Search in sources :

Example 1 with ComposableFuture

use of io.atomix.utils.concurrent.ComposableFuture 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;
}
Also used : ComposableFuture(io.atomix.utils.concurrent.ComposableFuture) PrimaryBackupSession(io.atomix.protocols.backup.impl.PrimaryBackupSession) CloseResponse(io.atomix.protocols.backup.protocol.CloseResponse)

Aggregations

PrimaryBackupSession (io.atomix.protocols.backup.impl.PrimaryBackupSession)1 CloseResponse (io.atomix.protocols.backup.protocol.CloseResponse)1 ComposableFuture (io.atomix.utils.concurrent.ComposableFuture)1