|
|
@ -908,7 +908,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
state.reset();
|
|
|
|
state.reset();
|
|
|
|
Log.i(account.name + " run thread=" + currentThread);
|
|
|
|
Log.i(account.name + " run thread=" + currentThread);
|
|
|
|
|
|
|
|
|
|
|
|
final List<TwoStateOwner> cowners = new ArrayList<>();
|
|
|
|
final ObjectHolder<TwoStateOwner> cowner = new ObjectHolder<>();
|
|
|
|
final ExecutorService executor =
|
|
|
|
final ExecutorService executor =
|
|
|
|
Helper.getBackgroundExecutor(1, "account_" + account.id);
|
|
|
|
Helper.getBackgroundExecutor(1, "account_" + account.id);
|
|
|
|
|
|
|
|
|
|
|
@ -1220,35 +1220,46 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
EntityOperation.sync(this, folder.id, false);
|
|
|
|
EntityOperation.sync(this, folder.id, false);
|
|
|
|
} else
|
|
|
|
} else
|
|
|
|
mapFolders.put(folder, null);
|
|
|
|
mapFolders.put(folder, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Log.d(folder.name + " observing");
|
|
|
|
Log.i(account.name + " observing operations");
|
|
|
|
getMainHandler().post(new Runnable() {
|
|
|
|
getMainHandler().post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
TwoStateOwner cowner = new TwoStateOwner(ServiceSynchronize.this, folder.name);
|
|
|
|
cowner.value = new TwoStateOwner(ServiceSynchronize.this, account.name);
|
|
|
|
cowners.add(cowner);
|
|
|
|
cowner.value.start();
|
|
|
|
cowner.start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.operation().liveOperations(folder.id).observe(cowner, new Observer<List<TupleOperationEx>>() {
|
|
|
|
db.operation().liveOperations(account.id).observe(cowner.value, new Observer<List<TupleOperationEx>>() {
|
|
|
|
private List<Long> handling = new ArrayList<>();
|
|
|
|
private List<Long> handling = new ArrayList<>();
|
|
|
|
private final Map<TupleOperationEx.PartitionKey, List<TupleOperationEx>> partitions = new HashMap<>();
|
|
|
|
private final Map<TupleOperationEx.PartitionKey, List<TupleOperationEx>> partitions = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
private final PowerManager.WakeLock wlFolder = pm.newWakeLock(
|
|
|
|
private final PowerManager.WakeLock wlOperations = pm.newWakeLock(
|
|
|
|
PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":folder." + folder.id);
|
|
|
|
PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":operations." + account.id);
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onChanged(final List<TupleOperationEx> _operations) {
|
|
|
|
public void onChanged(final List<TupleOperationEx> _operations) {
|
|
|
|
// Get new operations
|
|
|
|
// Get new operations
|
|
|
|
List<Long> ops = new ArrayList<>();
|
|
|
|
List<Long> ops = new ArrayList<>();
|
|
|
|
List<TupleOperationEx> added = new ArrayList<>();
|
|
|
|
Map<EntityFolder, List<TupleOperationEx>> added = new HashMap<>();
|
|
|
|
for (TupleOperationEx op : _operations) {
|
|
|
|
for (TupleOperationEx op : _operations) {
|
|
|
|
if (!handling.contains(op.id))
|
|
|
|
if (!handling.contains(op.id)) {
|
|
|
|
added.add(op);
|
|
|
|
boolean found = false;
|
|
|
|
|
|
|
|
for (EntityFolder folder : mapFolders.keySet())
|
|
|
|
|
|
|
|
if (Objects.equals(folder.id, op.folder)) {
|
|
|
|
|
|
|
|
found = true;
|
|
|
|
|
|
|
|
if (!added.containsKey(folder))
|
|
|
|
|
|
|
|
added.put(folder, new ArrayList<>());
|
|
|
|
|
|
|
|
added.get(folder).add(op);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
|
|
|
|
Log.e(account.name + " folder not found operation=" + op.name);
|
|
|
|
|
|
|
|
}
|
|
|
|
ops.add(op.id);
|
|
|
|
ops.add(op.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
handling = ops;
|
|
|
|
handling = ops;
|
|
|
|
|
|
|
|
|
|
|
|
if (added.size() > 0) {
|
|
|
|
for (EntityFolder folder : added.keySet()) {
|
|
|
|
Log.i(folder.name + " queuing operations=" + added.size() +
|
|
|
|
Log.i(folder.name + " queuing operations=" + added.size() +
|
|
|
|
" init=" + folder.initialize + " poll=" + folder.poll);
|
|
|
|
" init=" + folder.initialize + " poll=" + folder.poll);
|
|
|
|
|
|
|
|
|
|
|
@ -1256,7 +1267,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
boolean offline = (mapFolders.get(folder) == null);
|
|
|
|
boolean offline = (mapFolders.get(folder) == null);
|
|
|
|
List<TupleOperationEx.PartitionKey> keys = new ArrayList<>();
|
|
|
|
List<TupleOperationEx.PartitionKey> keys = new ArrayList<>();
|
|
|
|
synchronized (partitions) {
|
|
|
|
synchronized (partitions) {
|
|
|
|
for (TupleOperationEx op : added) {
|
|
|
|
for (TupleOperationEx op : added.get(folder)) {
|
|
|
|
TupleOperationEx.PartitionKey key = op.getPartitionKey(offline);
|
|
|
|
TupleOperationEx.PartitionKey key = op.getPartitionKey(offline);
|
|
|
|
|
|
|
|
|
|
|
|
if (!partitions.containsKey(key)) {
|
|
|
|
if (!partitions.containsKey(key)) {
|
|
|
@ -1297,7 +1308,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
super.run();
|
|
|
|
super.run();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
wlFolder.acquire();
|
|
|
|
wlOperations.acquire();
|
|
|
|
|
|
|
|
|
|
|
|
List<TupleOperationEx> partition;
|
|
|
|
List<TupleOperationEx> partition;
|
|
|
|
synchronized (partitions) {
|
|
|
|
synchronized (partitions) {
|
|
|
@ -1382,7 +1393,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
wlFolder.release();
|
|
|
|
wlOperations.release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -1392,7 +1403,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Keep alive
|
|
|
|
// Keep alive
|
|
|
|
boolean first = true;
|
|
|
|
boolean first = true;
|
|
|
@ -1603,8 +1613,11 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|
|
|
getMainHandler().post(new Runnable() {
|
|
|
|
getMainHandler().post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
for (TwoStateOwner owner : cowners)
|
|
|
|
try {
|
|
|
|
owner.destroy();
|
|
|
|
cowner.value.destroy();
|
|
|
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
|
|
|
Log.e(ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|