Search in sources :

Example 1 with CloseSessionRequest

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;
}
Also used : RaftException(io.atomix.protocols.raft.RaftException) CompletableFuture(java.util.concurrent.CompletableFuture) CloseSessionRequest(io.atomix.protocols.raft.protocol.CloseSessionRequest)

Example 2 with CloseSessionRequest

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;
}
Also used : RaftException(io.atomix.protocols.raft.RaftException) CompletableFuture(java.util.concurrent.CompletableFuture) CloseSessionRequest(io.atomix.protocols.raft.protocol.CloseSessionRequest)

Aggregations

RaftException (io.atomix.protocols.raft.RaftException)2 CloseSessionRequest (io.atomix.protocols.raft.protocol.CloseSessionRequest)2 CompletableFuture (java.util.concurrent.CompletableFuture)2