public CrdtCounterDelegate(String name, CrdtProtocolConfig config, PrimitiveManagementService managementService) { this.localMemberId = managementService.getMembershipService().getLocalMember().id(); this.clusterCommunicator = managementService.getCommunicationService(); this.executorService = managementService.getExecutorService(); this.subject = String.format("atomix-crdt-counter-%s", name); clusterCommunicator.subscribe(subject, SERIALIZER::decode, this::updateCounters, executorService); broadcastFuture = executorService.scheduleAtFixedRate( this::broadcastCounters, config.getGossipInterval().toMillis(), config.getGossipInterval().toMillis(), TimeUnit.MILLISECONDS); }
@Override @SuppressWarnings("unchecked") public CompletableFuture<TransactionService> start() { PrimitiveProtocol protocol = managementService.getPartitionService().getSystemPartitionGroup().newProtocol(); return AtomicMapType.<TransactionId, TransactionInfo>instance() .newBuilder("atomix-transactions", new AtomicMapConfig(), managementService) .withSerializer(SERIALIZER) .withProtocol((ProxyProtocol) protocol) .withCacheEnabled() .buildAsync() .thenApply(transactions -> { this.transactions = transactions.async(); managementService.getMembershipService().addListener(clusterEventListener); LOGGER.info("Started"); started.set(true); return this; }); }
@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")); } } }
public CrdtSetDelegate(String name, Serializer serializer, CrdtProtocolConfig config, PrimitiveManagementService managementService) { this.clusterCommunicator = managementService.getCommunicationService(); this.executorService = managementService.getExecutorService(); this.elementSerializer = serializer; this.timestampProvider = config.getTimestampProvider(); this.subject = String.format("atomix-crdt-set-%s", name); clusterCommunicator.subscribe(subject, SERIALIZER::decode, this::updateElements, executorService); broadcastFuture = executorService.scheduleAtFixedRate( this::broadcastElements, config.getGossipInterval().toMillis(), config.getGossipInterval().toMillis(), TimeUnit.MILLISECONDS); }
public CrdtValueDelegate(String name, Serializer serializer, CrdtProtocolConfig config, PrimitiveManagementService managementService) { this.clusterEventService = managementService.getEventService(); this.executorService = managementService.getExecutorService(); this.valueSerializer = serializer; this.timestampProvider = config.getTimestampProvider(); this.subject = String.format("atomix-crdt-value-%s", name); subscribeFuture = clusterEventService.subscribe(subject, SERIALIZER::decode, this::updateValue, executorService); broadcastFuture = executorService.scheduleAtFixedRate( this::broadcastValue, config.getGossipInterval().toMillis(), config.getGossipInterval().toMillis(), TimeUnit.MILLISECONDS); }
@Override public Collection<PrimitiveInfo> getPrimitives() { return managementService.getPrimitiveRegistry().getPrimitives(); }
@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); } }
Function<Transactional<?>, CompletableFuture<Void>> completionFunction) { PrimitiveType primitiveType = managementService.getPrimitiveTypeRegistry().getPrimitiveType(participantInfo.type()); if (primitiveType == null) { return Futures.exceptionalFuture(new TransactionException("Failed to locate primitive type " + participantInfo.type() + " for participant " + participantInfo.name())); PrimitiveProtocol.Type protocolType = managementService.getProtocolTypeRegistry().getProtocolType(participantInfo.protocol()); if (protocolType == null) { return Futures.exceptionalFuture(new TransactionException("Failed to locate protocol type for participant " + participantInfo.name())); partitionGroup = managementService.getPartitionService().getPartitionGroup(protocolType); } else { partitionGroup = managementService.getPartitionService().getPartitionGroup(participantInfo.group());
public AntiEntropyMapDelegate(String name, Serializer entrySerializer, AntiEntropyProtocolConfig config, PrimitiveManagementService managementService) { this.localMemberId = managementService.getMembershipService().getLocalMember().id(); this.mapName = name; this.entrySerializer = entrySerializer; destroyedMessage = mapName + ERROR_DESTROYED; this.clusterCommunicator = managementService.getCommunicationService(); this.membershipService = managementService.getMembershipService(); : managementService.getMembershipService() .getMembers() .stream()
@Override public CompletableFuture<Void> stop() { if (started.compareAndSet(true, false)) { managementService.getMembershipService().removeListener(clusterEventListener); return transactions.close().exceptionally(e -> null); } return CompletableFuture.completedFuture(null); }
protected <S> CompletableFuture<ProxyClient<S>> newProxy(Class<S> serviceType, ServiceConfig config) { PrimitiveProtocol protocol = protocol(); if (protocol instanceof ProxyProtocol) { try { return CompletableFuture.completedFuture(((ProxyProtocol) protocol) .newProxy(name, type, serviceType, config, managementService.getPartitionService())); } catch (Exception e) { return Futures.exceptionalFuture(e); } } return Futures.exceptionalFuture(new UnsupportedOperationException()); }
SerializerBuilder serializerBuilder = managementService.getSerializationService().newBuilder(name); serializerBuilder.withNamespace(new Namespace(namespaceConfig));
/** * 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 Collection<PrimitiveInfo> getPrimitives(PrimitiveType primitiveType) { return managementService.getPrimitiveRegistry().getPrimitives(primitiveType); }
@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); } }
Function<Transactional<?>, CompletableFuture<Void>> completionFunction) { PrimitiveType primitiveType = managementService.getPrimitiveTypeRegistry().getPrimitiveType(participantInfo.type()); if (primitiveType == null) { return Futures.exceptionalFuture(new TransactionException("Failed to locate primitive type " + participantInfo.type() + " for participant " + participantInfo.name())); PrimitiveProtocol.Type protocolType = managementService.getProtocolTypeRegistry().getProtocolType(participantInfo.protocol()); if (protocolType == null) { return Futures.exceptionalFuture(new TransactionException("Failed to locate protocol type for participant " + participantInfo.name())); partitionGroup = managementService.getPartitionService().getPartitionGroup(protocolType); } else { partitionGroup = managementService.getPartitionService().getPartitionGroup(participantInfo.group());
public CrdtSetDelegate(String name, Serializer serializer, CrdtProtocolConfig config, PrimitiveManagementService managementService) { this.clusterCommunicator = managementService.getCommunicationService(); this.executorService = managementService.getExecutorService(); this.elementSerializer = serializer; this.timestampProvider = config.getTimestampProvider(); this.subject = String.format("atomix-crdt-set-%s", name); clusterCommunicator.subscribe(subject, SERIALIZER::decode, this::updateElements, executorService); broadcastFuture = executorService.scheduleAtFixedRate( this::broadcastElements, config.getGossipInterval().toMillis(), config.getGossipInterval().toMillis(), TimeUnit.MILLISECONDS); }
public CrdtValueDelegate(String name, Serializer serializer, CrdtProtocolConfig config, PrimitiveManagementService managementService) { this.clusterEventService = managementService.getEventService(); this.executorService = managementService.getExecutorService(); this.valueSerializer = serializer; this.timestampProvider = config.getTimestampProvider(); this.subject = String.format("atomix-crdt-value-%s", name); subscribeFuture = clusterEventService.subscribe(subject, SERIALIZER::decode, this::updateValue, executorService); broadcastFuture = executorService.scheduleAtFixedRate( this::broadcastValue, config.getGossipInterval().toMillis(), config.getGossipInterval().toMillis(), TimeUnit.MILLISECONDS); }
public AntiEntropyMapDelegate(String name, Serializer entrySerializer, AntiEntropyProtocolConfig config, PrimitiveManagementService managementService) { this.localMemberId = managementService.getMembershipService().getLocalMember().id(); this.mapName = name; this.entrySerializer = entrySerializer; destroyedMessage = mapName + ERROR_DESTROYED; this.clusterCommunicator = managementService.getCommunicationService(); this.membershipService = managementService.getMembershipService(); managementService.getMembershipService() .getMembers() .stream()
public CoreTransactionService(PrimitiveManagementService managementService) { this.managementService = checkNotNull(managementService); this.localMemberId = managementService.getMembershipService().getLocalMember().id(); }