mirror of https://github.com/M66B/FairEmail.git
Execute operations for same priority ordered
This commit is contained in:
parent
97f99a583f
commit
c7f7bfb3cd
|
@ -179,7 +179,9 @@ public class Helper {
|
|||
protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) {
|
||||
RunnableFuture<T> task = super.newTaskFor(runnable, value);
|
||||
if (runnable instanceof PriorityRunnable)
|
||||
return new PriorityFuture<T>(task, ((PriorityRunnable) runnable).getPriority());
|
||||
return new PriorityFuture<T>(task,
|
||||
((PriorityRunnable) runnable).getPriority(),
|
||||
((PriorityRunnable) runnable).getOrder());
|
||||
else
|
||||
return task;
|
||||
}
|
||||
|
@ -221,17 +223,22 @@ public class Helper {
|
|||
|
||||
private static class PriorityFuture<T> implements RunnableFuture<T> {
|
||||
private int priority;
|
||||
private long order;
|
||||
private RunnableFuture<T> wrapped;
|
||||
|
||||
PriorityFuture(RunnableFuture<T> wrapped, int priority) {
|
||||
this.priority = priority;
|
||||
PriorityFuture(RunnableFuture<T> wrapped, int priority, long order) {
|
||||
this.wrapped = wrapped;
|
||||
this.priority = priority;
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public int getPriority() {
|
||||
return priority;
|
||||
return this.priority;
|
||||
}
|
||||
|
||||
public long getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -270,8 +277,13 @@ public class Helper {
|
|||
if (r1 instanceof PriorityFuture<?> && r2 instanceof PriorityFuture<?>) {
|
||||
Integer p1 = ((PriorityFuture<?>) r1).getPriority();
|
||||
Integer p2 = ((PriorityFuture<?>) r2).getPriority();
|
||||
Log.i("Priority " + p1 + "/" + p2 + "=" + p1.compareTo(p2));
|
||||
return p1.compareTo(p2);
|
||||
int p = p1.compareTo(p2);
|
||||
if (p == 0) {
|
||||
Long o1 = ((PriorityFuture<?>) r1).getOrder();
|
||||
Long o2 = ((PriorityFuture<?>) r2).getOrder();
|
||||
return o1.compareTo(o2);
|
||||
} else
|
||||
return p;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
@ -279,13 +291,19 @@ public class Helper {
|
|||
|
||||
static class PriorityRunnable implements Runnable {
|
||||
private int priority;
|
||||
private long order;
|
||||
|
||||
int getPriority() {
|
||||
return priority;
|
||||
return this.priority;
|
||||
}
|
||||
|
||||
PriorityRunnable(int priority) {
|
||||
long getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
PriorityRunnable(int priority, long order) {
|
||||
this.priority = priority;
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1161,9 +1161,9 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
Integer p2 = k2.getPriority();
|
||||
int priority = p1.compareTo(p2);
|
||||
if (priority == 0) {
|
||||
Long t1 = k1.getTime();
|
||||
Long t2 = k2.getTime();
|
||||
return t1.compareTo(t2);
|
||||
Long o1 = k1.getOrder();
|
||||
Long o2 = k2.getOrder();
|
||||
return o1.compareTo(o2);
|
||||
} else
|
||||
return priority;
|
||||
}
|
||||
|
@ -1177,7 +1177,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
}
|
||||
|
||||
try {
|
||||
executor.submit(new Helper.PriorityRunnable(key.getPriority()) {
|
||||
executor.submit(new Helper.PriorityRunnable(key.getPriority(), key.getOrder()) {
|
||||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
|
|
|
@ -48,7 +48,7 @@ public class TupleOperationEx extends EntityOperation {
|
|||
PartitionKey getPartitionKey(boolean offline) {
|
||||
PartitionKey key = new PartitionKey();
|
||||
|
||||
key.time = this.created;
|
||||
key.order = this.id;
|
||||
|
||||
if (offline) {
|
||||
// open/close folder is expensive
|
||||
|
@ -75,13 +75,13 @@ public class TupleOperationEx extends EntityOperation {
|
|||
}
|
||||
|
||||
class PartitionKey {
|
||||
public long time;
|
||||
private long order;
|
||||
private int priority;
|
||||
private String id;
|
||||
private String operation;
|
||||
|
||||
long getTime() {
|
||||
return time;
|
||||
long getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
int getPriority() {
|
||||
|
|
Loading…
Reference in New Issue