use of io.atomix.protocols.backup.impl.PrimaryBackupSession in project atomix by atomix.
the class PrimaryBackupServiceContext method createSession.
/**
* Creates a service session.
*
* @param sessionId the session to create
* @param nodeId the owning node ID
* @return the service session
*/
public PrimaryBackupSession createSession(long sessionId, NodeId nodeId) {
PrimaryBackupSession session = new PrimaryBackupSession(SessionId.from(sessionId), nodeId, this);
sessions.openSession(session);
return session;
}
use of io.atomix.protocols.backup.impl.PrimaryBackupSession in project atomix by atomix.
the class PrimaryBackupServiceContext method close.
/**
* Handles a close request.
*
* @param request the close request
* @return future to be completed with a close response
*/
public CompletableFuture<CloseResponse> close(CloseRequest request) {
ComposableFuture<CloseResponse> future = new ComposableFuture<>();
threadContext.execute(() -> {
PrimaryBackupSession session = sessions.getSession(request.session());
if (session != null) {
role.close(session).whenComplete((result, error) -> {
if (error == null) {
future.complete(CloseResponse.ok());
} else {
future.complete(CloseResponse.error());
}
});
} else {
future.complete(CloseResponse.error());
}
});
return future;
}
use of io.atomix.protocols.backup.impl.PrimaryBackupSession in project atomix by atomix.
the class BackupRole method applyExpire.
/**
* Applies an expire operation.
*/
private void applyExpire(ExpireOperation operation) {
context.setTimestamp(operation.timestamp());
PrimaryBackupSession session = context.getSession(operation.session());
if (session != null) {
context.sessions().expireSession(session);
}
}
use of io.atomix.protocols.backup.impl.PrimaryBackupSession in project atomix by atomix.
the class BackupRole method applyClose.
/**
* Applies a close operation.
*/
private void applyClose(CloseOperation operation) {
context.setTimestamp(operation.timestamp());
PrimaryBackupSession session = context.getSession(operation.session());
if (session != null) {
context.sessions().closeSession(session);
}
}
use of io.atomix.protocols.backup.impl.PrimaryBackupSession 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