Search in sources :

Example 1 with PrimaryBackupSession

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;
}
Also used : PrimaryBackupSession(io.atomix.protocols.backup.impl.PrimaryBackupSession)

Example 2 with PrimaryBackupSession

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

Example 3 with PrimaryBackupSession

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);
    }
}
Also used : PrimaryBackupSession(io.atomix.protocols.backup.impl.PrimaryBackupSession)

Example 4 with PrimaryBackupSession

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);
    }
}
Also used : PrimaryBackupSession(io.atomix.protocols.backup.impl.PrimaryBackupSession)

Example 5 with PrimaryBackupSession

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);
        }
    });
}
Also used : PrimaryBackupSession(io.atomix.protocols.backup.impl.PrimaryBackupSession) ExecuteOperation(io.atomix.protocols.backup.protocol.ExecuteOperation)

Aggregations

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