@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 public CompletableFuture<SessionIdService> start() { return systemPartitionGroup.getPartitions().iterator().next().getClient() .sessionBuilder(PRIMITIVE_NAME, SessionIdGeneratorType.instance(), new ServiceConfig()) .build() .connect() .thenApply(proxy -> { this.proxy = proxy; started.set(true); return this; }); }
private SessionClient createProxy(RaftClient client) { return client.sessionBuilder(ClusterPrimitiveType.PRIMITIVE_NAME, ClusterPrimitiveType.INSTANCE, new ServiceConfig()) .withReadConsistency(ReadConsistency.SEQUENTIAL) .withCommunicationStrategy(CommunicationStrategy.LEADER) .build() .connect() .join(); }
@Override @SuppressWarnings("unchecked") public CompletableFuture<PrimaryElectionService> start() { return partitions.getPartitions().iterator().next().getClient() .sessionBuilder(PRIMITIVE_NAME, PrimaryElectorType.instance(), new ServiceConfig()) .build() .connect() .thenAccept(proxy -> { this.proxy = proxy; proxy.addEventListener(CHANGE, eventListener); started.set(true); }) .thenApply(v -> this); }
@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(); }); } }
/** * Creates a test session. */ private SessionClient createProxy(RaftClient client, ReadConsistency consistency) { return client.sessionBuilder("raft-fuzz-test", TestPrimitiveType.INSTANCE, new ServiceConfig()) .withReadConsistency(consistency) .withCommunicationStrategy(COMMUNICATION_STRATEGY) .build() .connect() .join(); }
@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()); } }
/** * Creates a test session. */ private SessionClient createProxy(RaftClient client) { return client.sessionBuilder("raft-performance-test", TestPrimitiveType.INSTANCE, new ServiceConfig()) .withReadConsistency(READ_CONSISTENCY) .withCommunicationStrategy(COMMUNICATION_STRATEGY) .build(); }
@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<AtomicMultimap<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.sync(); }); } }