Search in sources :

Example 1 with DefaultProxyClient

use of io.atomix.primitive.proxy.impl.DefaultProxyClient 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 DefaultProxyClient

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

the class MultiPrimaryProtocol 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 -> ((PrimaryBackupPartition) partition).getClient().sessionBuilder(primitiveName, primitiveType, serviceConfig).withConsistency(config.getConsistency()).withReplication(config.getReplication()).withRecovery(config.getRecovery()).withNumBackups(config.getBackups()).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) PrimaryBackupPartition(io.atomix.protocols.backup.partition.PrimaryBackupPartition) Collection(java.util.Collection) 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) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) DefaultProxyClient(io.atomix.primitive.proxy.impl.DefaultProxyClient) ConfigurationException(io.atomix.utils.config.ConfigurationException) SessionClient(io.atomix.primitive.session.SessionClient) PrimaryBackupPartition(io.atomix.protocols.backup.partition.PrimaryBackupPartition)

Example 3 with DefaultProxyClient

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

the class RaftTest method createPrimitive.

/**
 * Creates a new primitive instance.
 */
private TestPrimitive createPrimitive(RaftClient client, ReadConsistency consistency) throws Exception {
    SessionClient partition = createSession(client, consistency);
    ProxyClient<TestPrimitiveService> proxy = new DefaultProxyClient<>("test", TestPrimitiveType.INSTANCE, MultiRaftProtocol.builder().build(), TestPrimitiveService.class, Collections.singletonList(partition), (key, partitions) -> partitions.get(0));
    PrimitiveRegistry registry = mock(PrimitiveRegistry.class);
    when(registry.createPrimitive(any(String.class), any(PrimitiveType.class))).thenReturn(CompletableFuture.completedFuture(new PrimitiveInfo("raft-test", TestPrimitiveType.INSTANCE)));
    when(registry.deletePrimitive(any(String.class))).thenReturn(CompletableFuture.completedFuture(null));
    return new TestPrimitiveImpl(proxy, registry);
}
Also used : DefaultProxyClient(io.atomix.primitive.proxy.impl.DefaultProxyClient) PrimitiveInfo(io.atomix.primitive.PrimitiveInfo) SessionClient(io.atomix.primitive.session.SessionClient) PrimitiveRegistry(io.atomix.primitive.PrimitiveRegistry) PrimitiveType(io.atomix.primitive.PrimitiveType)

Aggregations

PrimitiveType (io.atomix.primitive.PrimitiveType)3 DefaultProxyClient (io.atomix.primitive.proxy.impl.DefaultProxyClient)3 SessionClient (io.atomix.primitive.session.SessionClient)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 ConfigurationException (io.atomix.utils.config.ConfigurationException)2 Collection (java.util.Collection)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 PrimitiveInfo (io.atomix.primitive.PrimitiveInfo)1 PrimitiveRegistry (io.atomix.primitive.PrimitiveRegistry)1 PrimaryBackupPartition (io.atomix.protocols.backup.partition.PrimaryBackupPartition)1 RaftPartition (io.atomix.protocols.raft.partition.RaftPartition)1