Search in sources :

Example 1 with RaftPartition

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());
}
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 2 with RaftPartition

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();
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) DefaultPartitionService(io.atomix.primitive.partition.impl.DefaultPartitionService) RaftPartition(io.atomix.protocols.raft.partition.RaftPartition) RaftPartitionGroup(io.atomix.protocols.raft.partition.RaftPartitionGroup) File(java.io.File) Test(org.junit.Test)

Aggregations

RaftPartition (io.atomix.protocols.raft.partition.RaftPartition)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 PrimitiveType (io.atomix.primitive.PrimitiveType)1 PartitionGroup (io.atomix.primitive.partition.PartitionGroup)1 PartitionService (io.atomix.primitive.partition.PartitionService)1 DefaultPartitionService (io.atomix.primitive.partition.impl.DefaultPartitionService)1 PrimitiveProtocol (io.atomix.primitive.protocol.PrimitiveProtocol)1 ProxyProtocol (io.atomix.primitive.protocol.ProxyProtocol)1 ProxyClient (io.atomix.primitive.proxy.ProxyClient)1 DefaultProxyClient (io.atomix.primitive.proxy.impl.DefaultProxyClient)1 ServiceConfig (io.atomix.primitive.service.ServiceConfig)1 SessionClient (io.atomix.primitive.session.SessionClient)1 RaftPartitionGroup (io.atomix.protocols.raft.partition.RaftPartitionGroup)1 ConfigurationException (io.atomix.utils.config.ConfigurationException)1 File (java.io.File)1 Collection (java.util.Collection)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Collectors (java.util.stream.Collectors)1 Test (org.junit.Test)1