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