@Override public Collection<PrimitiveInfo> getPrimitives() { return managementService.getPrimitiveRegistry().getPrimitives(); }
@Override public Collection<PrimitiveInfo> getPrimitives(PrimitiveType primitiveType) { return managementService.getPrimitiveRegistry().getPrimitives(primitiveType); }
@Override public CompletableFuture<AtomicIdGenerator> buildAsync() { return newProxy(AtomicCounterService.class, new ServiceConfig()) .thenCompose(proxy -> new AtomicCounterProxy(proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(DelegatingAtomicIdGenerator::new) .thenApply(AsyncAtomicIdGenerator::sync); } }
@Override @SuppressWarnings("unchecked") public CompletableFuture<AtomicLock> buildAsync() { return newProxy(AtomicLockService.class, new ServiceConfig()) .thenCompose(proxy -> new AtomicLockProxy(proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(AsyncAtomicLock::sync); } }
@Override @SuppressWarnings("unchecked") public CompletableFuture<DistributedCyclicBarrier> buildAsync() { return newProxy(DistributedCyclicBarrierService.class, new ServiceConfig()) .thenCompose(proxy -> new DistributedCyclicBarrierProxy(proxy, managementService.getPrimitiveRegistry(), barrierAction).connect()) .thenApply(AsyncDistributedCyclicBarrier::sync); } }
@Override @SuppressWarnings("unchecked") public CompletableFuture<AtomicCounter> buildAsync() { return newProxy(AtomicCounterService.class, new ServiceConfig()) .thenCompose(proxy -> new AtomicCounterProxy(proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(AsyncAtomicCounter::sync); } }
@Override @SuppressWarnings("unchecked") public CompletableFuture<DistributedLock> buildAsync() { return newProxy(AtomicLockService.class, new ServiceConfig()) .thenCompose(proxy -> new AtomicLockProxy(proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(lock -> new DelegatingAsyncDistributedLock(lock).sync()); } }
@Override @SuppressWarnings("unchecked") public CompletableFuture<AtomicCounterMap<K>> buildAsync() { return newProxy(AtomicCounterMapService.class, new ServiceConfig()) .thenCompose(proxy -> new AtomicCounterMapProxy(proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(map -> { Serializer serializer = serializer(); return new TranscodingAsyncAtomicCounterMap<K, String>( map, key -> BaseEncoding.base16().encode(serializer.encode(key)), string -> serializer.decode(BaseEncoding.base16().decode(string))) .sync(); }); } }
@SuppressWarnings("unchecked") @Override public CompletableFuture<DistributedSemaphore> buildAsync() { return newProxy(AtomicSemaphoreService.class, new AtomicSemaphoreServiceConfig().setInitialCapacity(config.initialCapacity())) .thenCompose(proxy -> new AtomicSemaphoreProxy( proxy, managementService.getPrimitiveRegistry(), managementService.getExecutorService()) .connect()) .thenApply(DelegatingAsyncDistributedSemaphore::new) .thenApply(AsyncDistributedSemaphore::sync); } }
@SuppressWarnings("unchecked") @Override public CompletableFuture<AtomicSemaphore> buildAsync() { return newProxy(AtomicSemaphoreService.class, new AtomicSemaphoreServiceConfig().setInitialCapacity(config.initialCapacity())) .thenCompose(proxy -> new AtomicSemaphoreProxy( proxy, managementService.getPrimitiveRegistry(), managementService.getExecutorService()) .connect()) .thenApply(AsyncAtomicSemaphore::sync); } }
@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<AtomicNavigableMap<K, V>> buildAsync() { return newProxy(AtomicTreeMapService.class, new ServiceConfig()) .thenCompose(proxy -> new AtomicNavigableMapProxy(proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(map -> { Serializer serializer = serializer(); return new TranscodingAsyncAtomicNavigableMap<K, V, byte[]>( (AsyncAtomicNavigableMap) map, value -> serializer.encode(value), bytes -> serializer.decode(bytes)) .sync(); }); } }
@Override @SuppressWarnings("unchecked") public CompletableFuture<WorkQueue<E>> buildAsync() { return newProxy(WorkQueueService.class, new ServiceConfig()) .thenCompose(proxy -> new WorkQueueProxy(proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(queue -> { Serializer serializer = serializer(); return new TranscodingAsyncWorkQueue<E, byte[]>( queue, item -> serializer.encode(item), bytes -> serializer.decode(bytes)) .sync(); }); } }
@Override @SuppressWarnings("unchecked") public CompletableFuture<LeaderElection<T>> buildAsync() { return newProxy(LeaderElectionService.class, new ServiceConfig()) .thenCompose(proxy -> new LeaderElectionProxy(proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(election -> { Serializer serializer = serializer(); return new TranscodingAsyncLeaderElection<T, byte[]>( election, key -> serializer.encode(key), bytes -> serializer.decode(bytes)) .sync(); }); } }
@Override @SuppressWarnings("unchecked") public CompletableFuture<DistributedMultimap<K, V>> buildAsync() { return newProxy(AtomicMultimapService.class, new ServiceConfig()) .thenCompose(proxy -> new AtomicMultimapProxy(proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(rawMultimap -> { Serializer serializer = serializer(); AsyncAtomicMultimap<K, V> multimap = new TranscodingAsyncAtomicMultimap<>( rawMultimap, key -> BaseEncoding.base16().encode(serializer.encode(key)), string -> serializer.decode(BaseEncoding.base16().decode(string)), value -> serializer.encode(value), bytes -> serializer.decode(bytes)); if (config.getCacheConfig().isEnabled()) { multimap = new CachingAsyncAtomicMultimap<>(multimap, config.getCacheConfig()); } return multimap; }).thenApply(atomicMultimap -> new DelegatingAsyncDistributedMultimap<>(atomicMultimap).sync()); } }
@Override @SuppressWarnings("unchecked") public CompletableFuture<AtomicValue<V>> buildAsync() { 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)) .sync(); }); } }
@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(); }); } }
@Override @SuppressWarnings("unchecked") public CompletableFuture<AtomicSortedMap<K, V>> buildAsync() { return newProxy(AtomicTreeMapService.class, new ServiceConfig()) .thenCompose(proxy -> new AtomicNavigableMapProxy(proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(map -> { Serializer serializer = serializer(); return new TranscodingAsyncAtomicSortedMap<K, V, byte[]>( (AsyncAtomicSortedMap) map, value -> serializer.encode(value), bytes -> serializer.decode(bytes)) .sync(); }); } }
@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(); }); } }
@Override @SuppressWarnings("unchecked") public CompletableFuture<AtomicDocumentTree<V>> buildAsync() { return newProxy(DocumentTreeService.class, new ServiceConfig()) .thenCompose(proxy -> new AtomicDocumentTreeProxy(proxy, managementService.getPrimitiveRegistry()).connect()) .thenApply(treeProxy -> { Serializer serializer = serializer(); AsyncAtomicDocumentTree<V> tree = new TranscodingAsyncAtomicDocumentTree<>( treeProxy, key -> serializer.encode(key), bytes -> serializer.decode(bytes)); if (config.getCacheConfig().isEnabled()) { tree = new CachingAsyncAtomicDocumentTree<V>(tree, config.getCacheConfig()); } return tree.sync(); }); } }