use of io.atomix.protocols.backup.protocol.ExecuteOperation in project atomix by atomix.
the class PrimaryRole method executeQuery.
private CompletableFuture<ExecuteResponse> executeQuery(ExecuteRequest request) {
// If the session doesn't exist, create and replicate a new session before applying the query.
Session session = context.getSession(request.session());
if (session == null) {
Session newSession = context.createSession(request.session(), request.node());
long index = context.nextIndex();
long timestamp = System.currentTimeMillis();
return replicator.replicate(new ExecuteOperation(index, timestamp, newSession.sessionId().id(), newSession.nodeId(), null)).thenApply(v -> {
context.setIndex(index);
context.setTimestamp(timestamp);
return applyQuery(request, newSession);
});
} else {
return CompletableFuture.completedFuture(applyQuery(request, session));
}
}
use of io.atomix.protocols.backup.protocol.ExecuteOperation in project atomix by atomix.
the class PrimaryRole method executeCommand.
private CompletableFuture<ExecuteResponse> executeCommand(ExecuteRequest request) {
PrimaryBackupSession session = context.getOrCreateSession(request.session(), request.node());
long index = context.nextIndex();
long timestamp = System.currentTimeMillis();
return replicator.replicate(new ExecuteOperation(index, timestamp, session.sessionId().id(), session.nodeId(), request.operation())).thenApply(v -> {
try {
byte[] result = context.service().apply(new DefaultCommit<>(context.setIndex(index), request.operation().id(), request.operation().value(), context.setSession(session), context.setTimestamp(timestamp)));
return ExecuteResponse.ok(result);
} catch (Exception e) {
return ExecuteResponse.error();
} finally {
context.setSession(null);
}
});
}
Aggregations