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()); }
/** * Returns the primitive protocol. * * @return the primitive protocol */ protected PrimitiveProtocol protocol() { PrimitiveProtocol protocol = this.protocol; if (protocol == null) { PrimitiveProtocolConfig<?> protocolConfig = config.getProtocolConfig(); if (protocolConfig == null) { Collection<PartitionGroup> partitionGroups = managementService.getPartitionService().getPartitionGroups(); if (partitionGroups.size() == 1) { protocol = partitionGroups.iterator().next().newProtocol(); } else { String groups = Joiner.on(", ").join(partitionGroups.stream() .map(group -> group.name()) .collect(Collectors.toList())); throw new ConfigurationException(String.format("Primitive protocol is ambiguous: %d partition groups found (%s)", partitionGroups.size(), groups)); } } else { protocol = protocolConfig.getType().newProtocol(protocolConfig); } } return protocol; }
@Override public CompletableFuture<DistributedLog<E>> buildAsync() { LogProtocol protocol = (LogProtocol) protocol(); return protocol.newClient(managementService.getPartitionService()) .connect() .thenApply(client -> new DefaultAsyncDistributedLog<E>(name, client, serializer()).sync()); } }
@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; }); }
partitionGroup = managementService.getPartitionService().getPartitionGroup(protocolType); } else { partitionGroup = managementService.getPartitionService().getPartitionGroup(participantInfo.group());
@Override public CompletableFuture<DistributedLog<E>> buildAsync() { LogProtocol protocol = (LogProtocol) protocol(); return protocol.newClient(managementService.getPartitionService()) .connect() .thenApply(client -> new DefaultAsyncDistributedLog<E>(name, client, serializer()).sync()); } }
@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; }); }
partitionGroup = managementService.getPartitionService().getPartitionGroup(protocolType); } else { partitionGroup = managementService.getPartitionService().getPartitionGroup(participantInfo.group());