use of io.atomix.protocols.raft.partition.RaftPartition 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.protocols.raft.partition.RaftPartition in project atomix by atomix.
the class AtomixTest method testRoleChangedListener.
@Test
public void testRoleChangedListener() throws Exception {
// given
final CompletableFuture<Void> roleChanged = new CompletableFuture<>();
final CompletableFuture<Atomix> nodeOneFuture = startAtomix(1, Arrays.asList(1), builder -> {
final RaftPartitionGroup partitionGroup = RaftPartitionGroup.builder("system").withNumPartitions(1).withMembers(String.valueOf(1)).withDataDirectory(new File(new File(DATA_DIR, "log"), "1")).build();
final Atomix atomix = builder.withManagementGroup(partitionGroup).build();
final DefaultPartitionService partitionService = (DefaultPartitionService) atomix.getPartitionService();
final RaftPartitionGroup raftPartitionGroup = (RaftPartitionGroup) partitionService.getSystemPartitionGroup();
// when
raftPartitionGroup.getPartitions().forEach(partition -> {
final RaftPartition raftPartition = (RaftPartition) partition;
raftPartition.addRoleChangeListener((role) -> roleChanged.complete(null));
});
return atomix;
});
// then
nodeOneFuture.get();
roleChanged.get();
}
Aggregations