Search in sources :

Example 1 with ProxyClient

use of io.atomix.primitive.proxy.ProxyClient in project atomix by atomix.

the class DefaultDistributedSetBuilder method buildAsync.

@Override
@SuppressWarnings("unchecked")
public CompletableFuture<DistributedSet<E>> buildAsync() {
    PrimitiveProtocol protocol = protocol();
    if (protocol instanceof GossipProtocol) {
        if (protocol instanceof SetProtocol) {
            return managementService.getPrimitiveCache().getPrimitive(name, () -> CompletableFuture.completedFuture(((SetProtocol) protocol).<E>newSetDelegate(name, serializer(), managementService)).thenApply(set -> new GossipDistributedSet<>(name, protocol, set))).thenApply(AsyncDistributedSet::sync);
        } else {
            return Futures.exceptionalFuture(new UnsupportedOperationException("Sets are not supported by the provided gossip protocol"));
        }
    } else {
        return newProxy(DistributedSetService.class, new ServiceConfig()).thenCompose(proxy -> new DistributedSetProxy((ProxyClient) proxy, managementService.getPrimitiveRegistry()).connect()).thenApply(rawSet -> {
            Serializer serializer = serializer();
            AsyncDistributedSet<E> set = new TranscodingAsyncDistributedSet<>(rawSet, element -> BaseEncoding.base16().encode(serializer.encode(element)), string -> serializer.decode(BaseEncoding.base16().decode(string)));
            if (config.getCacheConfig().isEnabled()) {
                set = new CachingAsyncDistributedSet<>(set, config.getCacheConfig());
            }
            if (config.isReadOnly()) {
                set = new UnmodifiableAsyncDistributedSet<>(set);
            }
            return set.sync();
        });
    }
}
Also used : ProxyClient(io.atomix.primitive.proxy.ProxyClient) BaseEncoding(com.google.common.io.BaseEncoding) CompletableFuture(java.util.concurrent.CompletableFuture) DistributedSetBuilder(io.atomix.core.set.DistributedSetBuilder) DistributedSet(io.atomix.core.set.DistributedSet) DistributedSetConfig(io.atomix.core.set.DistributedSetConfig) SetProtocol(io.atomix.primitive.protocol.set.SetProtocol) PrimitiveManagementService(io.atomix.primitive.PrimitiveManagementService) ServiceConfig(io.atomix.primitive.service.ServiceConfig) PrimitiveProtocol(io.atomix.primitive.protocol.PrimitiveProtocol) AsyncDistributedSet(io.atomix.core.set.AsyncDistributedSet) GossipProtocol(io.atomix.primitive.protocol.GossipProtocol) Serializer(io.atomix.utils.serializer.Serializer) Futures(io.atomix.utils.concurrent.Futures) AsyncDistributedSet(io.atomix.core.set.AsyncDistributedSet) ServiceConfig(io.atomix.primitive.service.ServiceConfig) GossipProtocol(io.atomix.primitive.protocol.GossipProtocol) ProxyClient(io.atomix.primitive.proxy.ProxyClient) SetProtocol(io.atomix.primitive.protocol.set.SetProtocol) PrimitiveProtocol(io.atomix.primitive.protocol.PrimitiveProtocol) Serializer(io.atomix.utils.serializer.Serializer)

Example 2 with ProxyClient

use of io.atomix.primitive.proxy.ProxyClient in project atomix by atomix.

the class CorePrimitiveRegistry method start.

@Override
@SuppressWarnings("unchecked")
public CompletableFuture<PrimitiveRegistry> start() {
    ProxyProtocol protocol = partitionService.getSystemPartitionGroup().newProtocol();
    ProxyClient proxy = protocol.newProxy("primitives", AtomicMapType.instance(), AtomicMapService.class, new ServiceConfig(), partitionService);
    return proxy.connect().thenApply(v -> {
        AtomicMapProxy mapProxy = new AtomicMapProxy(proxy, this);
        primitives = new TranscodingAsyncAtomicMap<>(mapProxy, key -> key, key -> key, value -> value != null ? SERIALIZER.encode(value) : null, value -> value != null ? SERIALIZER.decode(value) : null);
        started.set(true);
        return this;
    });
}
Also used : DistributedPrimitive(io.atomix.primitive.DistributedPrimitive) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PrimitiveTypeRegistry(io.atomix.primitive.PrimitiveTypeRegistry) CompletableFuture(java.util.concurrent.CompletableFuture) Namespaces(io.atomix.utils.serializer.Namespaces) ManagedPrimitiveRegistry(io.atomix.primitive.ManagedPrimitiveRegistry) PrimitiveInfo(io.atomix.primitive.PrimitiveInfo) TranscodingAsyncAtomicMap(io.atomix.core.map.impl.TranscodingAsyncAtomicMap) AtomicMapService(io.atomix.core.map.impl.AtomicMapService) AsyncAtomicMap(io.atomix.core.map.AsyncAtomicMap) AtomicMapProxy(io.atomix.core.map.impl.AtomicMapProxy) ProxyProtocol(io.atomix.primitive.protocol.ProxyProtocol) ProxyClient(io.atomix.primitive.proxy.ProxyClient) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Collectors(java.util.stream.Collectors) PrimitiveRegistry(io.atomix.primitive.PrimitiveRegistry) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) ServiceConfig(io.atomix.primitive.service.ServiceConfig) PrimitiveType(io.atomix.primitive.PrimitiveType) PartitionService(io.atomix.primitive.partition.PartitionService) AtomicMapType(io.atomix.core.map.AtomicMapType) PrimitiveException(io.atomix.primitive.PrimitiveException) Serializer(io.atomix.utils.serializer.Serializer) AtomicMapProxy(io.atomix.core.map.impl.AtomicMapProxy) ServiceConfig(io.atomix.primitive.service.ServiceConfig) ProxyClient(io.atomix.primitive.proxy.ProxyClient) ProxyProtocol(io.atomix.primitive.protocol.ProxyProtocol)

Example 3 with ProxyClient

use of io.atomix.primitive.proxy.ProxyClient 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 4 with ProxyClient

use of io.atomix.primitive.proxy.ProxyClient 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)

Aggregations

ProxyClient (io.atomix.primitive.proxy.ProxyClient)4 ServiceConfig (io.atomix.primitive.service.ServiceConfig)4 PrimitiveType (io.atomix.primitive.PrimitiveType)3 PartitionService (io.atomix.primitive.partition.PartitionService)3 PrimitiveProtocol (io.atomix.primitive.protocol.PrimitiveProtocol)3 ProxyProtocol (io.atomix.primitive.protocol.ProxyProtocol)3 Collection (java.util.Collection)3 Collectors (java.util.stream.Collectors)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 PartitionGroup (io.atomix.primitive.partition.PartitionGroup)2 DefaultProxyClient (io.atomix.primitive.proxy.impl.DefaultProxyClient)2 SessionClient (io.atomix.primitive.session.SessionClient)2 ConfigurationException (io.atomix.utils.config.ConfigurationException)2 Serializer (io.atomix.utils.serializer.Serializer)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 BaseEncoding (com.google.common.io.BaseEncoding)1 AsyncAtomicMap (io.atomix.core.map.AsyncAtomicMap)1 AtomicMapType (io.atomix.core.map.AtomicMapType)1 AtomicMapProxy (io.atomix.core.map.impl.AtomicMapProxy)1