Search in sources :

Example 1 with RecoveringPrimitiveProxy

use of io.atomix.primitive.proxy.impl.RecoveringPrimitiveProxy in project atomix by atomix.

the class DefaultRaftClient method newProxy.

@Override
public PrimitiveProxy newProxy(String primitiveName, PrimitiveType primitiveType, RaftProtocol primitiveProtocol) {
    // Create a proxy builder that uses the session manager to open a session.
    Supplier<PrimitiveProxy> proxyFactory = () -> new DefaultRaftProxy(primitiveName, primitiveType, DefaultRaftClient.this.protocol, selectorManager, sessionManager, primitiveProtocol.readConsistency(), primitiveProtocol.communicationStrategy(), threadContextFactory.createContext(), primitiveProtocol.minTimeout(), primitiveProtocol.maxTimeout());
    PrimitiveProxy proxy;
    // If the recovery strategy is set to RECOVER, wrap the builder in a recovering proxy client.
    if (primitiveProtocol.recoveryStrategy() == Recovery.RECOVER) {
        proxy = new RecoveringPrimitiveProxy(clientId, primitiveName, primitiveType, proxyFactory, threadContextFactory.createContext());
    } else {
        proxy = proxyFactory.get();
    }
    // If max retries is set, wrap the client in a retrying proxy client.
    if (primitiveProtocol.maxRetries() > 0) {
        proxy = new RetryingPrimitiveProxy(proxy, threadContextFactory.createContext(), primitiveProtocol.maxRetries(), primitiveProtocol.retryDelay());
    }
    // Default the executor to use the configured thread pool executor and create a blocking aware proxy client.
    Executor executor = primitiveProtocol.executor() != null ? primitiveProtocol.executor() : threadContextFactory.createContext();
    return new BlockingAwarePrimitiveProxy(proxy, executor);
}
Also used : BlockingAwarePrimitiveProxy(io.atomix.primitive.proxy.impl.BlockingAwarePrimitiveProxy) RetryingPrimitiveProxy(io.atomix.primitive.proxy.impl.RetryingPrimitiveProxy) RecoveringPrimitiveProxy(io.atomix.primitive.proxy.impl.RecoveringPrimitiveProxy) PrimitiveProxy(io.atomix.primitive.proxy.PrimitiveProxy) Executor(java.util.concurrent.Executor) BlockingAwarePrimitiveProxy(io.atomix.primitive.proxy.impl.BlockingAwarePrimitiveProxy) RecoveringPrimitiveProxy(io.atomix.primitive.proxy.impl.RecoveringPrimitiveProxy) RetryingPrimitiveProxy(io.atomix.primitive.proxy.impl.RetryingPrimitiveProxy) DefaultRaftProxy(io.atomix.protocols.raft.proxy.impl.DefaultRaftProxy)

Example 2 with RecoveringPrimitiveProxy

use of io.atomix.primitive.proxy.impl.RecoveringPrimitiveProxy in project atomix by atomix.

the class PrimaryBackupClient method newProxy.

@Override
@SuppressWarnings("unchecked")
public PrimitiveProxy newProxy(String primitiveName, PrimitiveType primitiveType, MultiPrimaryProtocol primitiveProtocol) {
    Supplier<PrimitiveProxy> proxyBuilder = () -> new PrimaryBackupProxy(clientName, sessionIdService.nextSessionId().join(), primitiveType, new PrimitiveDescriptor(primitiveName, primitiveType.id(), primitiveProtocol.backups(), primitiveProtocol.replication()), clusterService, PrimaryBackupClient.this.protocol, primaryElection, threadContextFactory.createContext());
    PrimitiveProxy proxy;
    if (primitiveProtocol.recovery() == Recovery.RECOVER) {
        proxy = new RecoveringPrimitiveProxy(clientName, primitiveName, primitiveType, proxyBuilder, threadContextFactory.createContext());
    } else {
        proxy = proxyBuilder.get();
    }
    // If max retries is set, wrap the client in a retrying proxy client.
    if (primitiveProtocol.maxRetries() > 0) {
        proxy = new RetryingPrimitiveProxy(proxy, threadContextFactory.createContext(), primitiveProtocol.maxRetries(), primitiveProtocol.retryDelay());
    }
    // Default the executor to use the configured thread pool executor and create a blocking aware proxy client.
    Executor executor = primitiveProtocol.executor() != null ? primitiveProtocol.executor() : threadContextFactory.createContext();
    return new BlockingAwarePrimitiveProxy(proxy, executor);
}
Also used : BlockingAwarePrimitiveProxy(io.atomix.primitive.proxy.impl.BlockingAwarePrimitiveProxy) RetryingPrimitiveProxy(io.atomix.primitive.proxy.impl.RetryingPrimitiveProxy) RecoveringPrimitiveProxy(io.atomix.primitive.proxy.impl.RecoveringPrimitiveProxy) PrimitiveProxy(io.atomix.primitive.proxy.PrimitiveProxy) PrimaryBackupProxy(io.atomix.protocols.backup.proxy.PrimaryBackupProxy) Executor(java.util.concurrent.Executor) BlockingAwarePrimitiveProxy(io.atomix.primitive.proxy.impl.BlockingAwarePrimitiveProxy) PrimitiveDescriptor(io.atomix.protocols.backup.protocol.PrimitiveDescriptor) RecoveringPrimitiveProxy(io.atomix.primitive.proxy.impl.RecoveringPrimitiveProxy) RetryingPrimitiveProxy(io.atomix.primitive.proxy.impl.RetryingPrimitiveProxy)

Aggregations

PrimitiveProxy (io.atomix.primitive.proxy.PrimitiveProxy)2 BlockingAwarePrimitiveProxy (io.atomix.primitive.proxy.impl.BlockingAwarePrimitiveProxy)2 RecoveringPrimitiveProxy (io.atomix.primitive.proxy.impl.RecoveringPrimitiveProxy)2 RetryingPrimitiveProxy (io.atomix.primitive.proxy.impl.RetryingPrimitiveProxy)2 Executor (java.util.concurrent.Executor)2 PrimitiveDescriptor (io.atomix.protocols.backup.protocol.PrimitiveDescriptor)1 PrimaryBackupProxy (io.atomix.protocols.backup.proxy.PrimaryBackupProxy)1 DefaultRaftProxy (io.atomix.protocols.raft.proxy.impl.DefaultRaftProxy)1