Schedule operations on priority, time

pull/172/head
M66B 6 years ago
parent c535df7e62
commit 9737ed1479

@ -1163,7 +1163,13 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
public int compare(TupleOperationEx.PartitionKey k1, TupleOperationEx.PartitionKey k2) {
Integer p1 = k1.getPriority();
Integer p2 = k2.getPriority();
return p1.compareTo(p2);
int priority = p1.compareTo(p2);
if (priority == 0) {
Long t1 = k1.getTime();
Long t2 = k2.getTime();
return t1.compareTo(t2);
} else
return priority;
}
});

@ -48,12 +48,16 @@ public class TupleOperationEx extends EntityOperation {
PartitionKey getPartitionKey(boolean offline) {
PartitionKey key = new PartitionKey();
key.time = this.created;
if (offline) {
// open/close folder is expensive
key.priority = this.priority + 10;
return key;
}
key.priority = this.priority;
if (FETCH.equals(name))
try {
JSONArray jargs = new JSONArray(args);
@ -65,17 +69,21 @@ public class TupleOperationEx extends EntityOperation {
else if (!MOVE.equals(name))
key.id = "id:" + id;
key.priority = this.priority;
key.operation = this.name;
return key;
}
class PartitionKey {
private String id;
public long time;
private int priority;
private String id;
private String operation;
long getTime() {
return time;
}
int getPriority() {
return this.priority;
}
@ -89,8 +97,8 @@ public class TupleOperationEx extends EntityOperation {
public boolean equals(@Nullable Object obj) {
if (obj instanceof PartitionKey) {
PartitionKey other = (PartitionKey) obj;
return (Objects.equals(this.id, other.id) &&
this.priority == other.priority &&
return (this.priority == other.priority &&
Objects.equals(this.id, other.id) &&
Objects.equals(this.operation, other.operation));
} else
return false;
@ -99,9 +107,9 @@ public class TupleOperationEx extends EntityOperation {
@NonNull
@Override
public String toString() {
return (id == null ? "" : id) + ":" +
priority + ":" +
(operation == null ? "" : operation);
return (priority + ":" +
(id == null ? "" : id) + ":" +
(operation == null ? "" : operation));
}
}
}

Loading…
Cancel
Save