io.atomix.protocols.raft.protocol.CloseSessionRequest Java Examples
The following examples show how to use
io.atomix.protocols.raft.protocol.CloseSessionRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PassiveRole.java From atomix with Apache License 2.0 | 6 votes |
@Override public CompletableFuture<CloseSessionResponse> onCloseSession(CloseSessionRequest request) { raft.checkThread(); logRequest(request); if (raft.getLeader() == null) { return CompletableFuture.completedFuture(logResponse(CloseSessionResponse.builder() .withStatus(RaftResponse.Status.ERROR) .withError(RaftError.Type.NO_LEADER) .build())); } else { return forward(request, raft.getProtocol()::closeSession) .exceptionally(error -> CloseSessionResponse.builder() .withStatus(RaftResponse.Status.ERROR) .withError(RaftError.Type.NO_LEADER) .build()) .thenApply(this::logResponse); } }
Example #2
Source File: InactiveRole.java From atomix with Apache License 2.0 | 5 votes |
@Override public CompletableFuture<CloseSessionResponse> onCloseSession(CloseSessionRequest request) { logRequest(request); return Futures.completedFuture(logResponse(CloseSessionResponse.builder() .withStatus(Status.ERROR) .withError(RaftError.Type.UNAVAILABLE) .build())); }
Example #3
Source File: RaftSessionConnection.java From atomix with Apache License 2.0 | 5 votes |
/** * Sends a close session request to the given node. * * @param request the request to send * @return a future to be completed with the response */ public CompletableFuture<CloseSessionResponse> closeSession(CloseSessionRequest request) { CompletableFuture<CloseSessionResponse> future = new CompletableFuture<>(); if (context.isCurrentContext()) { sendRequest(request, protocol::closeSession, future); } else { context.execute(() -> sendRequest(request, protocol::closeSession, future)); } return future; }
Example #4
Source File: RaftSessionManager.java From atomix with Apache License 2.0 | 5 votes |
/** * 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; }
Example #5
Source File: LocalRaftServerProtocol.java From atomix with Apache License 2.0 | 4 votes |
@Override public void registerCloseSessionHandler(Function<CloseSessionRequest, CompletableFuture<CloseSessionResponse>> handler) { this.closeSessionHandler = handler; }
Example #6
Source File: RaftClientMessagingProtocol.java From submarine with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<CloseSessionResponse> closeSession(MemberId memberId, CloseSessionRequest request) { return sendAndReceive(memberId, "close-session", request); }
Example #7
Source File: LocalRaftServerProtocol.java From atomix with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<CloseSessionResponse> closeSession(MemberId memberId, CloseSessionRequest request) { return getServer(memberId).thenCompose(listener -> listener.closeSession(encode(request))).thenApply(this::decode); }
Example #8
Source File: RaftServerMessagingProtocol.java From atomix with Apache License 2.0 | 4 votes |
@Override public void registerCloseSessionHandler(Function<CloseSessionRequest, CompletableFuture<CloseSessionResponse>> handler) { registerHandler("close-session", handler); }
Example #9
Source File: RaftServerMessagingProtocol.java From atomix with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<CloseSessionResponse> closeSession(MemberId memberId, CloseSessionRequest request) { return sendAndReceive(memberId, "close-session", request); }
Example #10
Source File: LocalRaftClientProtocol.java From atomix with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<CloseSessionResponse> closeSession(MemberId memberId, CloseSessionRequest request) { return getServer(memberId).thenCompose(protocol -> protocol.closeSession(encode(request))).thenApply(this::decode); }
Example #11
Source File: RaftClientMessagingProtocol.java From atomix with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<CloseSessionResponse> closeSession(MemberId memberId, CloseSessionRequest request) { return sendAndReceive(memberId, "close-session", request); }
Example #12
Source File: LeaderRole.java From atomix with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<CloseSessionResponse> onCloseSession(CloseSessionRequest request) { final long term = raft.getTerm(); final long timestamp = System.currentTimeMillis(); raft.checkThread(); logRequest(request); CompletableFuture<CloseSessionResponse> future = new CompletableFuture<>(); appendAndCompact(new CloseSessionEntry(term, timestamp, request.session(), false, request.delete())) .whenCompleteAsync((entry, error) -> { if (error != null) { future.complete(logResponse(CloseSessionResponse.builder() .withStatus(RaftResponse.Status.ERROR) .withError(RaftError.Type.PROTOCOL_ERROR) .build())); return; } appender.appendEntries(entry.index()).whenComplete((commitIndex, commitError) -> { raft.checkThread(); if (isRunning()) { if (commitError == null) { raft.getServiceManager().<Long>apply(entry.index()).whenComplete((closeResult, closeError) -> { if (closeError == null) { future.complete(logResponse(CloseSessionResponse.builder() .withStatus(RaftResponse.Status.OK) .build())); } else if (closeError instanceof CompletionException && closeError.getCause() instanceof RaftException) { future.complete(logResponse(CloseSessionResponse.builder() .withStatus(RaftResponse.Status.ERROR) .withError(((RaftException) closeError.getCause()).getType(), closeError.getMessage()) .build())); } else if (closeError instanceof RaftException) { future.complete(logResponse(CloseSessionResponse.builder() .withStatus(RaftResponse.Status.ERROR) .withError(((RaftException) closeError).getType(), closeError.getMessage()) .build())); } else { future.complete(logResponse(CloseSessionResponse.builder() .withStatus(RaftResponse.Status.ERROR) .withError(RaftError.Type.PROTOCOL_ERROR, closeError.getMessage()) .build())); } }); } else { future.complete(logResponse(CloseSessionResponse.builder() .withStatus(RaftResponse.Status.ERROR) .withError(RaftError.Type.PROTOCOL_ERROR) .build())); } } else { future.complete(logResponse(CloseSessionResponse.builder() .withStatus(RaftResponse.Status.ERROR) .withError(RaftError.Type.ILLEGAL_MEMBER_STATE) .build())); } }); }, raft.getThreadContext()); return future; }
Example #13
Source File: RaftClientCommunicator.java From atomix with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<CloseSessionResponse> closeSession(MemberId memberId, CloseSessionRequest request) { return sendAndReceive(context.closeSessionSubject, request, memberId); }
Example #14
Source File: RaftServerCommunicator.java From atomix with Apache License 2.0 | 4 votes |
@Override public void registerCloseSessionHandler(Function<CloseSessionRequest, CompletableFuture<CloseSessionResponse>> handler) { clusterCommunicator.subscribe(context.closeSessionSubject, serializer::decode, handler, serializer::encode); }
Example #15
Source File: RaftServerCommunicator.java From atomix with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<CloseSessionResponse> closeSession(MemberId memberId, CloseSessionRequest request) { return sendAndReceive(context.closeSessionSubject, request, memberId); }
Example #16
Source File: LocalRaftServerProtocol.java From zeppelin with Apache License 2.0 | 4 votes |
@Override public void registerCloseSessionHandler(Function<CloseSessionRequest, CompletableFuture<CloseSessionResponse>> handler) { this.closeSessionHandler = handler; }
Example #17
Source File: LocalRaftServerProtocol.java From zeppelin with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<CloseSessionResponse> closeSession(MemberId memberId, CloseSessionRequest request) { return getServer(memberId).thenCompose(listener -> listener.closeSession(encode(request))).thenApply(this::decode); }
Example #18
Source File: RaftServerMessagingProtocol.java From zeppelin with Apache License 2.0 | 4 votes |
@Override public void registerCloseSessionHandler(Function<CloseSessionRequest, CompletableFuture<CloseSessionResponse>> handler) { registerHandler("close-session", handler); }
Example #19
Source File: RaftServerMessagingProtocol.java From zeppelin with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<CloseSessionResponse> closeSession(MemberId memberId, CloseSessionRequest request) { return sendAndReceive(memberId, "close-session", request); }
Example #20
Source File: LocalRaftClientProtocol.java From zeppelin with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<CloseSessionResponse> closeSession(MemberId memberId, CloseSessionRequest request) { return getServer(memberId).thenCompose(protocol -> protocol.closeSession(encode(request))).thenApply(this::decode); }
Example #21
Source File: RaftClientMessagingProtocol.java From zeppelin with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<CloseSessionResponse> closeSession(MemberId memberId, CloseSessionRequest request) { return sendAndReceive(memberId, "close-session", request); }
Example #22
Source File: LocalRaftServerProtocol.java From submarine with Apache License 2.0 | 4 votes |
@Override public void registerCloseSessionHandler(Function<CloseSessionRequest, CompletableFuture<CloseSessionResponse>> handler) { this.closeSessionHandler = handler; }
Example #23
Source File: LocalRaftServerProtocol.java From submarine with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<CloseSessionResponse> closeSession(MemberId memberId, CloseSessionRequest request) { return getServer(memberId).thenCompose(listener -> listener.closeSession(encode(request))).thenApply(this::decode); }
Example #24
Source File: RaftServerMessagingProtocol.java From submarine with Apache License 2.0 | 4 votes |
@Override public void registerCloseSessionHandler(Function<CloseSessionRequest, CompletableFuture<CloseSessionResponse>> handler) { registerHandler("close-session", handler); }
Example #25
Source File: RaftServerMessagingProtocol.java From submarine with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<CloseSessionResponse> closeSession(MemberId memberId, CloseSessionRequest request) { return sendAndReceive(memberId, "close-session", request); }
Example #26
Source File: LocalRaftClientProtocol.java From submarine with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<CloseSessionResponse> closeSession(MemberId memberId, CloseSessionRequest request) { return getServer(memberId).thenCompose(protocol -> protocol.closeSession(encode(request))).thenApply(this::decode); }
Example #27
Source File: RaftRole.java From atomix with Apache License 2.0 | 2 votes |
/** * Handles a close session request. * * @param request The request to handle. * @return A completable future to be completed with the request response. */ CompletableFuture<CloseSessionResponse> onCloseSession(CloseSessionRequest request);