use of io.atomix.protocols.raft.protocol.CloseSessionRequest in project atomix by atomix.
the class RaftProxyManager method closeSession.
/**
* Closes a session.
*
* @param sessionId The session identifier.
* @return A completable future to be completed once the session is closed.
*/
public CompletableFuture<Void> closeSession(SessionId sessionId) {
RaftProxyState state = sessions.get(sessionId.id());
if (state == null) {
return Futures.exceptionalFuture(new RaftException.UnknownSession("Unknown session: " + sessionId));
}
log.info("Closing session {}", sessionId);
CloseSessionRequest request = CloseSessionRequest.builder().withSession(sessionId.id()).build();
CompletableFuture<Void> future = new CompletableFuture<>();
connection.closeSession(request).whenComplete((response, error) -> {
if (error == null) {
if (response.status() == RaftResponse.Status.OK) {
sessions.remove(sessionId.id());
future.complete(null);
} else {
future.completeExceptionally(response.error().createException());
}
} else {
future.completeExceptionally(error);
}
});
return future;
}
use of io.atomix.protocols.raft.protocol.CloseSessionRequest in project atomix by atomix.
the class RaftSessionManager method closeSession.
/**
* Closes a session.
*
* @param sessionId the session identifier.
* @param delete whether to delete the service
* @return A completable future to be completed once the session is closed.
*/
public CompletableFuture<Void> closeSession(SessionId sessionId, boolean delete) {
RaftSessionState state = sessions.get(sessionId.id());
if (state == null) {
return Futures.exceptionalFuture(new RaftException.UnknownSession("Unknown session: " + sessionId));
}
log.debug("Closing session {}", sessionId);
CloseSessionRequest request = CloseSessionRequest.builder().withSession(sessionId.id()).withDelete(delete).build();
CompletableFuture<Void> future = new CompletableFuture<>();
connection.closeSession(request).whenComplete((response, error) -> {
sessions.remove(sessionId.id());
if (error == null) {
if (response.status() == RaftResponse.Status.OK) {
future.complete(null);
} else {
future.completeExceptionally(response.error().createException());
}
} else {
future.completeExceptionally(error);
}
});
return future;
}
Aggregations