use of io.atomix.primitive.protocol.GossipProtocol 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();
});
}
}
Aggregations