long opVersion = opData.getLong(Key.VERSION);
if (snapshotV == opVersion) {
try {
snapshot.consume(createOperation(opData));
} catch (Exception e) {
callback.handle(new DefaultFutureResult<JsonObject>(new ReplyException(
ReplyFailure.RECIPIENT_FAILURE, e.getMessage())));
return;
}
snapshotV++;
}
if (opV == opVersion) {
transformedOps.add(opData);
opV++;
}
}
if (opV != snapshotV) {
callback.handle(new DefaultFutureResult<JsonObject>(new ReplyException(
ReplyFailure.RECIPIENT_FAILURE, "Invalid opData version")));
return;
}
CollaborativeOperation transformed = operation;
if (applyAt != null && ops.size() > 0
&& applyAt <= ops.<JsonObject>get(ops.size() - 1).getLong(Key.VERSION)) {
try {
CollaborativeOperation applied =
transformer.compose(createOperations(ops, (int) (applyAt - ops
.<JsonObject>get(0).getLong(Key.VERSION)), ops.size()));
transformed = operation.transform(applied, false);
} catch (Exception e) {
log.log(Level.WARNING, "Failed to transform operation", e);
callback.handle(new DefaultFutureResult<JsonObject>(new ReplyException(
ReplyFailure.RECIPIENT_FAILURE, e.getMessage())));
return;
}
}
// Ok, now we can try to apply the op.
try {
snapshot.consume(transformed);
} catch (Exception e) {
log.log(Level.WARNING, "Failed to consume operation", e);
callback.handle(new DefaultFutureResult<JsonObject>(new ReplyException(
ReplyFailure.RECIPIENT_FAILURE, e.getMessage())));
return;
}
doSubmit(transformedOps, docType, docId, transformed, opV, snapshot, callback);
}