use of io.atomix.primitive.service.ServiceConfig in project atomix by atomix.
the class DefaultDistributedQueueBuilder method buildAsync.
@Override
@SuppressWarnings("unchecked")
public CompletableFuture<DistributedQueue<E>> buildAsync() {
return newProxy(DistributedQueueService.class, new ServiceConfig()).thenCompose(proxy -> new DistributedQueueProxy(proxy, managementService.getPrimitiveRegistry()).connect()).thenApply(rawQueue -> {
Serializer serializer = serializer();
AsyncDistributedQueue<E> queue = new TranscodingAsyncDistributedQueue<>(rawQueue, element -> BaseEncoding.base16().encode(serializer.encode(element)), string -> serializer.decode(BaseEncoding.base16().decode(string)));
if (config.getCacheConfig().isEnabled()) {
queue = new CachingAsyncDistributedQueue<>(queue, config.getCacheConfig());
}
if (config.isReadOnly()) {
queue = new UnmodifiableAsyncDistributedQueue<>(queue);
}
return queue.sync();
});
}
use of io.atomix.primitive.service.ServiceConfig 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.service.ServiceConfig in project atomix by atomix.
the class DefaultLeaderElectorBuilder method buildAsync.
@Override
@SuppressWarnings("unchecked")
public CompletableFuture<LeaderElector<T>> buildAsync() {
return newProxy(LeaderElectorService.class, new ServiceConfig()).thenCompose(proxy -> new LeaderElectorProxy(proxy, managementService.getPrimitiveRegistry()).connect()).thenApply(proxy -> {
Serializer serializer = serializer();
AsyncLeaderElector<T> elector = new TranscodingAsyncLeaderElector<>(proxy, key -> serializer.encode(key), bytes -> serializer.decode(bytes));
if (config.getCacheConfig().isEnabled()) {
elector = new CachingAsyncLeaderElector<T>(elector, config.getCacheConfig());
}
return elector.sync();
});
}
use of io.atomix.primitive.service.ServiceConfig in project atomix by atomix.
the class DefaultDistributedMultisetBuilder method buildAsync.
@Override
@SuppressWarnings("unchecked")
public CompletableFuture<DistributedMultiset<E>> buildAsync() {
return newProxy(DistributedMultisetService.class, new ServiceConfig()).thenCompose(proxy -> new DistributedMultisetProxy(proxy, managementService.getPrimitiveRegistry()).connect()).thenApply(rawList -> {
Serializer serializer = serializer();
AsyncDistributedMultiset<E> list = new TranscodingAsyncDistributedMultiset<>(rawList, element -> BaseEncoding.base16().encode(serializer.encode(element)), string -> serializer.decode(BaseEncoding.base16().decode(string)));
if (config.getCacheConfig().isEnabled()) {
list = new CachingAsyncDistributedMultiset<>(list, config.getCacheConfig());
}
if (config.isReadOnly()) {
list = new UnmodifiableAsyncDistributedMultiset<>(list);
}
return list.sync();
});
}
use of io.atomix.primitive.service.ServiceConfig 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