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());
}
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);
}
}
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);
}
}
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);
}
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);
}
Aggregations