Search in sources :

Example 6 with SessionClient

use of io.atomix.primitive.session.SessionClient in project atomix by atomix.

the class MultiRaftProtocol method newProxy.

@Override
public <S> ProxyClient<S> newProxy(String primitiveName, PrimitiveType primitiveType, Class<S> serviceType, ServiceConfig serviceConfig, PartitionService partitionService) {
    PartitionGroup partitionGroup = partitionService.getPartitionGroup(this);
    if (partitionGroup == null) {
        throw new ConfigurationException("No Raft partition group matching the configured protocol exists");
    }
    Collection<SessionClient> partitions = partitionGroup.getPartitions().stream().map(partition -> ((RaftPartition) partition).getClient().sessionBuilder(primitiveName, primitiveType, serviceConfig).withMinTimeout(config.getMinTimeout()).withMaxTimeout(config.getMaxTimeout()).withReadConsistency(config.getReadConsistency()).withCommunicationStrategy(config.getCommunicationStrategy()).withRecoveryStrategy(config.getRecoveryStrategy()).withMaxRetries(config.getMaxRetries()).withRetryDelay(config.getRetryDelay()).build()).collect(Collectors.toList());
    return new DefaultProxyClient<>(primitiveName, primitiveType, this, serviceType, partitions, config.getPartitioner());
}
Also used : PartitionGroup(io.atomix.primitive.partition.PartitionGroup) ProxyProtocol(io.atomix.primitive.protocol.ProxyProtocol) ProxyClient(io.atomix.primitive.proxy.ProxyClient) Collection(java.util.Collection) RaftPartition(io.atomix.protocols.raft.partition.RaftPartition) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) PartitionGroup(io.atomix.primitive.partition.PartitionGroup) Collectors(java.util.stream.Collectors) ConfigurationException(io.atomix.utils.config.ConfigurationException) ServiceConfig(io.atomix.primitive.service.ServiceConfig) PrimitiveType(io.atomix.primitive.PrimitiveType) PartitionService(io.atomix.primitive.partition.PartitionService) PrimitiveProtocol(io.atomix.primitive.protocol.PrimitiveProtocol) DefaultProxyClient(io.atomix.primitive.proxy.impl.DefaultProxyClient) SessionClient(io.atomix.primitive.session.SessionClient) DefaultProxyClient(io.atomix.primitive.proxy.impl.DefaultProxyClient) ConfigurationException(io.atomix.utils.config.ConfigurationException) SessionClient(io.atomix.primitive.session.SessionClient)

Example 7 with SessionClient

use of io.atomix.primitive.session.SessionClient in project atomix by atomix.

the class RecoveringSessionClient method removeEventListener.

@Override
public synchronized void removeEventListener(EventType eventType, Consumer<PrimitiveEvent> consumer) {
    eventListeners.remove(eventType.canonicalize(), consumer);
    SessionClient proxy = this.session;
    if (proxy != null) {
        proxy.removeEventListener(eventType, consumer);
    }
}
Also used : SessionClient(io.atomix.primitive.session.SessionClient)

Example 8 with SessionClient

use of io.atomix.primitive.session.SessionClient in project atomix by atomix.

the class RecoveringSessionClient method addEventListener.

@Override
public synchronized void addEventListener(EventType eventType, Consumer<PrimitiveEvent> consumer) {
    eventListeners.put(eventType.canonicalize(), consumer);
    SessionClient proxy = this.session;
    if (proxy != null) {
        proxy.addEventListener(eventType, consumer);
    }
}
Also used : SessionClient(io.atomix.primitive.session.SessionClient)

Example 9 with SessionClient

use of io.atomix.primitive.session.SessionClient in project atomix by atomix.

the class DefaultPrimaryElectionService method stop.

@Override
public CompletableFuture<Void> stop() {
    SessionClient proxy = this.proxy;
    if (proxy != null) {
        return proxy.close().whenComplete((result, error) -> {
            started.set(false);
        });
    }
    started.set(false);
    return CompletableFuture.completedFuture(null);
}
Also used : SessionClient(io.atomix.primitive.session.SessionClient)

Example 10 with SessionClient

use of io.atomix.primitive.session.SessionClient in project atomix by atomix.

the class RaftTest method testClientKeepAlive.

/**
 * Tests keeping a client session alive.
 */
@Test
public void testClientKeepAlive() throws Throwable {
    createServers(3);
    RaftClient client = createClient();
    SessionClient session = createSession(client);
    Thread.sleep(Duration.ofSeconds(10).toMillis());
    threadAssertTrue(session.getState() == PrimitiveState.CONNECTED);
}
Also used : SessionClient(io.atomix.primitive.session.SessionClient) Test(org.junit.Test)

Aggregations

SessionClient (io.atomix.primitive.session.SessionClient)19 PrimitiveType (io.atomix.primitive.PrimitiveType)3 DefaultProxyClient (io.atomix.primitive.proxy.impl.DefaultProxyClient)3 ThreadContext (io.atomix.utils.concurrent.ThreadContext)3 PartitionGroup (io.atomix.primitive.partition.PartitionGroup)2 PartitionService (io.atomix.primitive.partition.PartitionService)2 PrimitiveProtocol (io.atomix.primitive.protocol.PrimitiveProtocol)2 ProxyProtocol (io.atomix.primitive.protocol.ProxyProtocol)2 ProxyClient (io.atomix.primitive.proxy.ProxyClient)2 ServiceConfig (io.atomix.primitive.service.ServiceConfig)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 ConfigurationException (io.atomix.utils.config.ConfigurationException)2 Collection (java.util.Collection)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Collectors (java.util.stream.Collectors)2 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1