Search in sources :

Example 1 with BlockingAwareSessionClient

use of io.atomix.primitive.session.impl.BlockingAwareSessionClient in project atomix by atomix.

the class DefaultRaftClient method sessionBuilder.

@Override
public RaftSessionClient.Builder sessionBuilder(String primitiveName, PrimitiveType primitiveType, ServiceConfig serviceConfig) {
    return new RaftSessionClient.Builder() {

        @Override
        public SessionClient build() {
            // Create a proxy builder that uses the session manager to open a session.
            Supplier<CompletableFuture<SessionClient>> proxyFactory = () -> CompletableFuture.completedFuture(new DefaultRaftSessionClient(primitiveName, primitiveType, serviceConfig, partitionId, DefaultRaftClient.this.protocol, selectorManager, sessionManager, readConsistency, communicationStrategy, threadContextFactory.createContext(), minTimeout, maxTimeout));
            SessionClient proxy;
            ThreadContext context = threadContextFactory.createContext();
            // If the recovery strategy is set to RECOVER, wrap the builder in a recovering proxy client.
            if (recoveryStrategy == Recovery.RECOVER) {
                proxy = new RecoveringSessionClient(clientId, partitionId, primitiveName, primitiveType, proxyFactory, context);
            } else {
                proxy = proxyFactory.get().join();
            }
            // If max retries is set, wrap the client in a retrying proxy client.
            if (maxRetries > 0) {
                proxy = new RetryingSessionClient(proxy, context, maxRetries, retryDelay);
            }
            return new BlockingAwareSessionClient(proxy, context);
        }
    };
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RecoveringSessionClient(io.atomix.primitive.session.impl.RecoveringSessionClient) BlockingAwareSessionClient(io.atomix.primitive.session.impl.BlockingAwareSessionClient) RaftSessionClient(io.atomix.protocols.raft.session.RaftSessionClient) BlockingAwareSessionClient(io.atomix.primitive.session.impl.BlockingAwareSessionClient) RetryingSessionClient(io.atomix.primitive.session.impl.RetryingSessionClient) DefaultRaftSessionClient(io.atomix.protocols.raft.session.impl.DefaultRaftSessionClient) RecoveringSessionClient(io.atomix.primitive.session.impl.RecoveringSessionClient) SessionClient(io.atomix.primitive.session.SessionClient) ThreadContext(io.atomix.utils.concurrent.ThreadContext) DefaultRaftSessionClient(io.atomix.protocols.raft.session.impl.DefaultRaftSessionClient) RetryingSessionClient(io.atomix.primitive.session.impl.RetryingSessionClient)

Example 2 with BlockingAwareSessionClient

use of io.atomix.primitive.session.impl.BlockingAwareSessionClient in project atomix by atomix.

the class PrimaryBackupClient method sessionBuilder.

/**
 * Creates a new primary backup proxy session builder.
 *
 * @param primitiveName the primitive name
 * @param primitiveType the primitive type
 * @param serviceConfig the service configuration
 * @return a new primary-backup proxy session builder
 */
public PrimaryBackupSessionClient.Builder sessionBuilder(String primitiveName, PrimitiveType primitiveType, ServiceConfig serviceConfig) {
    byte[] configBytes = Serializer.using(primitiveType.namespace()).encode(serviceConfig);
    return new PrimaryBackupSessionClient.Builder() {

        @Override
        public SessionClient build() {
            Supplier<CompletableFuture<SessionClient>> proxyBuilder = () -> sessionIdService.nextSessionId().thenApply(sessionId -> new PrimaryBackupSessionClient(clientName, partitionId, sessionId, primitiveType, new PrimitiveDescriptor(primitiveName, primitiveType.name(), configBytes, numBackups, replication), clusterMembershipService, PrimaryBackupClient.this.protocol, primaryElection, threadContextFactory.createContext()));
            SessionClient proxy;
            ThreadContext context = threadContextFactory.createContext();
            if (recovery == Recovery.RECOVER) {
                proxy = new RecoveringSessionClient(clientName, partitionId, primitiveName, primitiveType, proxyBuilder, context);
            } else {
                proxy = Futures.get(proxyBuilder.get());
            }
            // If max retries is set, wrap the client in a retrying proxy client.
            if (maxRetries > 0) {
                proxy = new RetryingSessionClient(proxy, context, maxRetries, retryDelay);
            }
            return new BlockingAwareSessionClient(proxy, context);
        }
    };
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RecoveringSessionClient(io.atomix.primitive.session.impl.RecoveringSessionClient) BlockingAwareSessionClient(io.atomix.primitive.session.impl.BlockingAwareSessionClient) BlockingAwareSessionClient(io.atomix.primitive.session.impl.BlockingAwareSessionClient) RetryingSessionClient(io.atomix.primitive.session.impl.RetryingSessionClient) PrimaryBackupSessionClient(io.atomix.protocols.backup.session.PrimaryBackupSessionClient) RecoveringSessionClient(io.atomix.primitive.session.impl.RecoveringSessionClient) SessionClient(io.atomix.primitive.session.SessionClient) ThreadContext(io.atomix.utils.concurrent.ThreadContext) PrimaryBackupSessionClient(io.atomix.protocols.backup.session.PrimaryBackupSessionClient) PrimitiveDescriptor(io.atomix.protocols.backup.protocol.PrimitiveDescriptor) RetryingSessionClient(io.atomix.primitive.session.impl.RetryingSessionClient)

Aggregations

SessionClient (io.atomix.primitive.session.SessionClient)2 BlockingAwareSessionClient (io.atomix.primitive.session.impl.BlockingAwareSessionClient)2 RecoveringSessionClient (io.atomix.primitive.session.impl.RecoveringSessionClient)2 RetryingSessionClient (io.atomix.primitive.session.impl.RetryingSessionClient)2 ThreadContext (io.atomix.utils.concurrent.ThreadContext)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 PrimitiveDescriptor (io.atomix.protocols.backup.protocol.PrimitiveDescriptor)1 PrimaryBackupSessionClient (io.atomix.protocols.backup.session.PrimaryBackupSessionClient)1 RaftSessionClient (io.atomix.protocols.raft.session.RaftSessionClient)1 DefaultRaftSessionClient (io.atomix.protocols.raft.session.impl.DefaultRaftSessionClient)1