/** * Gets or builds a singleton instance of the primitive asynchronously. * <p> * The returned primitive will be shared by all {@code get()} calls for the named primitive. If no instance has yet * been constructed, the instance will be built from this builder's configuration. * * @return a singleton instance of the primitive */ public CompletableFuture<P> getAsync() { return managementService.getPrimitiveCache().getPrimitive(name, this::buildAsync); } }
@Override public CompletableFuture<DistributedCounter> buildAsync() { PrimitiveProtocol protocol = protocol(); if (protocol instanceof GossipProtocol) { if (protocol instanceof CounterProtocol) { return managementService.getPrimitiveCache().getPrimitive(name, () -> CompletableFuture.completedFuture( new GossipDistributedCounter(name, (GossipProtocol) protocol, ((CounterProtocol) protocol) .newCounterDelegate(name, managementService)))) .thenApply(AsyncDistributedCounter::sync); } else { return Futures.exceptionalFuture(new UnsupportedOperationException("Counter is not supported by the provided gossip protocol")); } } else if (protocol instanceof ProxyProtocol) { return newProxy(AtomicCounterService.class, new ServiceConfig()) .thenCompose(proxy -> new AtomicCounterProxy(proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(DelegatingDistributedCounter::new) .thenApply(AsyncDistributedCounter::sync); } else { return Futures.exceptionalFuture(new ConfigurationException("Invalid protocol type")); } } }
@Override @SuppressWarnings("unchecked") public CompletableFuture<DistributedValue<V>> buildAsync() { PrimitiveProtocol protocol = protocol(); if (protocol instanceof GossipProtocol) { if (protocol instanceof ValueProtocol) { CompletableFuture<AsyncDistributedValue<V>> future = managementService.getPrimitiveCache().getPrimitive(name, () -> CompletableFuture.completedFuture(((ValueProtocol) protocol).<V>newValueDelegate(name, serializer(), managementService)) .thenApply(map -> new GossipDistributedValue<>(name, protocol, map))); return future.thenApply(AsyncDistributedValue::sync); } else { return Futures.exceptionalFuture(new UnsupportedOperationException("Values are not supported by the provided gossip protocol")); } } else { return newProxy(AtomicValueService.class, new ServiceConfig()) .thenCompose(proxy -> new AtomicValueProxy(proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(elector -> { Serializer serializer = serializer(); return new TranscodingAsyncAtomicValue<V, byte[]>( elector, key -> serializer.encode(key), bytes -> serializer.decode(bytes)); }) .thenApply(value -> new DelegatingAsyncDistributedValue<>(value).sync()); } } }
@Override @SuppressWarnings("unchecked") public CompletableFuture<DistributedNavigableMap<K, V>> buildAsync() { PrimitiveProtocol protocol = protocol(); if (protocol instanceof GossipProtocol) { if (protocol instanceof NavigableMapProtocol) { return managementService.getPrimitiveCache().getPrimitive(name, () -> CompletableFuture.completedFuture(((NavigableMapProtocol) protocol).<K, V>newNavigableMapDelegate(name, serializer(), managementService)) .thenApply(set -> new GossipDistributedNavigableMap<>(name, protocol, set))) .thenApply(AsyncDistributedNavigableMap::sync); } else { return Futures.exceptionalFuture(new UnsupportedOperationException("Sets are not supported by the provided gossip protocol")); } } else { return newProxy(AtomicTreeMapService.class, new ServiceConfig()) .thenCompose(proxy -> new AtomicNavigableMapProxy<K>((ProxyClient) proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(map -> { Serializer serializer = serializer(); return new TranscodingAsyncAtomicNavigableMap<K, V, byte[]>( map, value -> serializer.encode(value), bytes -> serializer.decode(bytes)); }).thenApply(atomicMap -> new DelegatingAsyncDistributedNavigableMap<>(atomicMap).sync()); } } }
@Override @SuppressWarnings("unchecked") public CompletableFuture<DistributedSortedMap<K, V>> buildAsync() { PrimitiveProtocol protocol = protocol(); if (protocol instanceof GossipProtocol) { if (protocol instanceof SortedMapProtocol) { return managementService.getPrimitiveCache().getPrimitive(name, () -> CompletableFuture.completedFuture(((SortedMapProtocol) protocol).<K, V>newSortedMapDelegate(name, serializer(), managementService)) .thenApply(set -> new GossipDistributedSortedMap<>(name, protocol, set))) .thenApply(AsyncDistributedSortedMap::sync); } else { return Futures.exceptionalFuture(new UnsupportedOperationException("Sets are not supported by the provided gossip protocol")); } } else { return newProxy(AtomicTreeMapService.class, new ServiceConfig()) .thenCompose(proxy -> new AtomicNavigableMapProxy<K>((ProxyClient) proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(map -> { Serializer serializer = serializer(); return new TranscodingAsyncAtomicNavigableMap<K, V, byte[]>( map, value -> serializer.encode(value), bytes -> serializer.decode(bytes)); }).thenApply(atomicMap -> new DelegatingAsyncDistributedSortedMap<>(atomicMap).sync()); } } }
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)))
@Override @SuppressWarnings("unchecked") public CompletableFuture<DistributedNavigableSet<E>> buildAsync() { PrimitiveProtocol protocol = protocol(); if (protocol instanceof GossipProtocol) { if (protocol instanceof NavigableSetProtocol) { return managementService.getPrimitiveCache().getPrimitive(name, () -> CompletableFuture.completedFuture(((NavigableSetProtocol) protocol).<E>newNavigableSetDelegate(name, serializer(), managementService)) .thenApply(set -> new GossipDistributedNavigableSet<>(name, protocol, set))) .thenApply(AsyncDistributedNavigableSet::sync); } else { return Futures.exceptionalFuture(new UnsupportedOperationException("Sets are not supported by the provided gossip protocol")); } } else { return newProxy(DistributedTreeSetService.class, new ServiceConfig()) .thenCompose(proxy -> new DistributedNavigableSetProxy<E>((ProxyClient) proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(set -> { if (config.getCacheConfig().isEnabled()) { set = new CachingAsyncDistributedNavigableSet<>(set, config.getCacheConfig()); } if (config.isReadOnly()) { set = new UnmodifiableAsyncDistributedNavigableSet<>(set); } return set.sync(); }); } } }
@Override @SuppressWarnings("unchecked") public CompletableFuture<DistributedSortedSet<E>> buildAsync() { PrimitiveProtocol protocol = protocol(); if (protocol instanceof GossipProtocol) { if (protocol instanceof SortedSetProtocol) { return managementService.getPrimitiveCache().getPrimitive(name, () -> CompletableFuture.completedFuture(((SortedSetProtocol) protocol).<E>newSortedSetDelegate(name, serializer(), managementService)) .thenApply(set -> new GossipDistributedSortedSet<>(name, protocol, set))) .thenApply(AsyncDistributedSortedSet::sync); } else { return Futures.exceptionalFuture(new UnsupportedOperationException("Sets are not supported by the provided gossip protocol")); } } else { return newProxy(DistributedTreeSetService.class, new ServiceConfig()) .thenCompose(proxy -> new DistributedNavigableSetProxy<E>((ProxyClient) proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(set -> { if (config.getCacheConfig().isEnabled()) { set = new CachingAsyncDistributedNavigableSet<>(set, config.getCacheConfig()); } if (config.isReadOnly()) { set = new UnmodifiableAsyncDistributedNavigableSet<>(set); } return set.sync(); }); } } }
if (protocol instanceof GossipProtocol) { if (protocol instanceof MapProtocol) { return managementService.getPrimitiveCache().getPrimitive(name, () -> CompletableFuture.completedFuture(((MapProtocol) protocol).<K, V>newMapDelegate(name, serializer(), managementService)) .thenApply(map -> new GossipDistributedMap<>(name, protocol, map)))
@Override public CompletableFuture<DistributedCounter> buildAsync() { PrimitiveProtocol protocol = protocol(); if (protocol instanceof GossipProtocol) { if (protocol instanceof CounterProtocol) { return managementService.getPrimitiveCache().getPrimitive(name, () -> CompletableFuture.completedFuture( new GossipDistributedCounter(name, (GossipProtocol) protocol, ((CounterProtocol) protocol) .newCounterDelegate(name, managementService)))) .thenApply(AsyncDistributedCounter::sync); } else { return Futures.exceptionalFuture(new UnsupportedOperationException("Counter is not supported by the provided gossip protocol")); } } else if (protocol instanceof ProxyProtocol) { return newProxy(AtomicCounterService.class, new ServiceConfig()) .thenCompose(proxy -> new AtomicCounterProxy(proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(DelegatingDistributedCounter::new) .thenApply(AsyncDistributedCounter::sync); } else { return Futures.exceptionalFuture(new ConfigurationException("Invalid protocol type")); } } }
@Override @SuppressWarnings("unchecked") public CompletableFuture<DistributedSortedMap<K, V>> buildAsync() { PrimitiveProtocol protocol = protocol(); if (protocol instanceof GossipProtocol) { if (protocol instanceof SortedMapProtocol) { return managementService.getPrimitiveCache().getPrimitive(name, () -> CompletableFuture.completedFuture(((SortedMapProtocol) protocol).<K, V>newSortedMapDelegate(name, serializer(), managementService)) .thenApply(set -> new GossipDistributedSortedMap<>(name, protocol, set))) .thenApply(AsyncDistributedSortedMap::sync); } else { return Futures.exceptionalFuture(new UnsupportedOperationException("Sets are not supported by the provided gossip protocol")); } } else { return newProxy(AtomicTreeMapService.class, new ServiceConfig()) .thenCompose(proxy -> new AtomicNavigableMapProxy<K>((ProxyClient) proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(map -> { Serializer serializer = serializer(); return new TranscodingAsyncAtomicNavigableMap<K, V, byte[]>( map, value -> serializer.encode(value), bytes -> serializer.decode(bytes)); }).thenApply(atomicMap -> new DelegatingAsyncDistributedSortedMap<>(atomicMap).sync()); } } }
@Override @SuppressWarnings("unchecked") public CompletableFuture<DistributedNavigableMap<K, V>> buildAsync() { PrimitiveProtocol protocol = protocol(); if (protocol instanceof GossipProtocol) { if (protocol instanceof NavigableMapProtocol) { return managementService.getPrimitiveCache().getPrimitive(name, () -> CompletableFuture.completedFuture(((NavigableMapProtocol) protocol).<K, V>newNavigableMapDelegate(name, serializer(), managementService)) .thenApply(set -> new GossipDistributedNavigableMap<>(name, protocol, set))) .thenApply(AsyncDistributedNavigableMap::sync); } else { return Futures.exceptionalFuture(new UnsupportedOperationException("Sets are not supported by the provided gossip protocol")); } } else { return newProxy(AtomicTreeMapService.class, new ServiceConfig()) .thenCompose(proxy -> new AtomicNavigableMapProxy<K>((ProxyClient) proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(map -> { Serializer serializer = serializer(); return new TranscodingAsyncAtomicNavigableMap<K, V, byte[]>( map, value -> serializer.encode(value), bytes -> serializer.decode(bytes)); }).thenApply(atomicMap -> new DelegatingAsyncDistributedNavigableMap<>(atomicMap).sync()); } } }
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)))
@Override @SuppressWarnings("unchecked") public CompletableFuture<DistributedValue<V>> buildAsync() { PrimitiveProtocol protocol = protocol(); if (protocol instanceof GossipProtocol) { if (protocol instanceof ValueProtocol) { CompletableFuture<AsyncDistributedValue<V>> future = managementService.getPrimitiveCache().getPrimitive(name, () -> CompletableFuture.completedFuture(((ValueProtocol) protocol).<V>newValueDelegate(name, serializer(), managementService)) .thenApply(map -> new GossipDistributedValue<>(name, protocol, map))); return future.thenApply(AsyncDistributedValue::sync); } else { return Futures.exceptionalFuture(new UnsupportedOperationException("Values are not supported by the provided gossip protocol")); } } else { return newProxy(AtomicValueService.class, new ServiceConfig()) .thenCompose(proxy -> new AtomicValueProxy(proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(elector -> { Serializer serializer = serializer(); return new TranscodingAsyncAtomicValue<V, byte[]>( elector, key -> serializer.encode(key), bytes -> serializer.decode(bytes)); }) .thenApply(value -> new DelegatingAsyncDistributedValue<>(value).sync()); } } }
@Override @SuppressWarnings("unchecked") public CompletableFuture<DistributedNavigableSet<E>> buildAsync() { PrimitiveProtocol protocol = protocol(); if (protocol instanceof GossipProtocol) { if (protocol instanceof NavigableSetProtocol) { return managementService.getPrimitiveCache().getPrimitive(name, () -> CompletableFuture.completedFuture(((NavigableSetProtocol) protocol).<E>newNavigableSetDelegate(name, serializer(), managementService)) .thenApply(set -> new GossipDistributedNavigableSet<>(name, protocol, set))) .thenApply(AsyncDistributedNavigableSet::sync); } else { return Futures.exceptionalFuture(new UnsupportedOperationException("Sets are not supported by the provided gossip protocol")); } } else { return newProxy(DistributedTreeSetService.class, new ServiceConfig()) .thenCompose(proxy -> new DistributedNavigableSetProxy<E>((ProxyClient) proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(set -> { if (config.getCacheConfig().isEnabled()) { set = new CachingAsyncDistributedNavigableSet<>(set, config.getCacheConfig()); } if (config.isReadOnly()) { set = new UnmodifiableAsyncDistributedNavigableSet<>(set); } return set.sync(); }); } } }
if (protocol instanceof GossipProtocol) { if (protocol instanceof MapProtocol) { return managementService.getPrimitiveCache().getPrimitive(name, () -> CompletableFuture.completedFuture(((MapProtocol) protocol).<K, V>newMapDelegate(name, serializer(), managementService)) .thenApply(map -> new GossipDistributedMap<>(name, protocol, map)))
@Override @SuppressWarnings("unchecked") public CompletableFuture<DistributedSortedSet<E>> buildAsync() { PrimitiveProtocol protocol = protocol(); if (protocol instanceof GossipProtocol) { if (protocol instanceof SortedSetProtocol) { return managementService.getPrimitiveCache().getPrimitive(name, () -> CompletableFuture.completedFuture(((SortedSetProtocol) protocol).<E>newSortedSetDelegate(name, serializer(), managementService)) .thenApply(set -> new GossipDistributedSortedSet<>(name, protocol, set))) .thenApply(AsyncDistributedSortedSet::sync); } else { return Futures.exceptionalFuture(new UnsupportedOperationException("Sets are not supported by the provided gossip protocol")); } } else { return newProxy(DistributedTreeSetService.class, new ServiceConfig()) .thenCompose(proxy -> new DistributedNavigableSetProxy<E>((ProxyClient) proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(set -> { if (config.getCacheConfig().isEnabled()) { set = new CachingAsyncDistributedNavigableSet<>(set, config.getCacheConfig()); } if (config.isReadOnly()) { set = new UnmodifiableAsyncDistributedNavigableSet<>(set); } return set.sync(); }); } } }