@Override public LogClient newClient(PartitionService partitionService) { Collection<LogSession> partitions = partitionService.getPartitionGroup(this) .getPartitions() .stream() .map(partition -> ((LogPartition) partition).getClient().logSessionBuilder().build()) .collect(Collectors.toList()); return new DistributedLogClient(this, partitions, config.getPartitioner()); }
/** * Returns the first partition group that matches the given primitive protocol. * * @param protocol the primitive protocol * @return the first partition group that matches the given primitive protocol */ @SuppressWarnings("unchecked") default PartitionGroup getPartitionGroup(ProxyProtocol protocol) { if (protocol.group() != null) { PartitionGroup group = getPartitionGroup(protocol.group()); if (group != null) { return group; } PartitionGroup systemGroup = getSystemPartitionGroup(); if (systemGroup != null && systemGroup.name().equals(protocol.group())) { return systemGroup; } return null; } for (PartitionGroup partitionGroup : getPartitionGroups()) { if (partitionGroup.protocol().name().equals(protocol.type().name())) { return partitionGroup; } } return null; }
@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; }); }
/** * Returns the first partition group that matches the given primitive type. * * @param type the primitive type * @return the first partition group that matches the given primitive type */ @SuppressWarnings("unchecked") default PartitionGroup getPartitionGroup(PrimitiveProtocol.Type type) { return getPartitionGroups().stream() .filter(group -> group.protocol().name().equals(type.name())) .findFirst() .orElse(null); }
@Override @SuppressWarnings("unchecked") public CompletableFuture<PrimitiveRegistry> start() { ProxyProtocol protocol = partitionService.getSystemPartitionGroup().newProtocol(); ProxyClient proxy = protocol.newProxy( "primitives", AtomicMapType.instance(), AtomicMapService.class, new ServiceConfig(), partitionService); return proxy.connect() .thenApply(v -> { AtomicMapProxy mapProxy = new AtomicMapProxy(proxy, this); primitives = new TranscodingAsyncAtomicMap<>( mapProxy, key -> key, key -> key, value -> value != null ? SERIALIZER.encode(value) : null, value -> value != null ? SERIALIZER.decode(value) : null); started.set(true); return this; }); }
/** * 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 <S> ProxyClient<S> newProxy(String primitiveName, PrimitiveType primitiveType, Class<S> serviceType, ServiceConfig serviceConfig, PartitionService partitionService) { PartitionGroup partitionGroup = partitionService.getPartitionGroup(this); if (partitionGroup == null) { throw new ConfigurationException("No Raft partition group matching the configured protocol exists"); } Collection<SessionClient> partitions = partitionGroup.getPartitions().stream() .map(partition -> ((PrimaryBackupPartition) partition).getClient() .sessionBuilder(primitiveName, primitiveType, serviceConfig) .withConsistency(config.getConsistency()) .withReplication(config.getReplication()) .withRecovery(config.getRecovery()) .withNumBackups(config.getBackups()) .withMaxRetries(config.getMaxRetries()) .withRetryDelay(config.getRetryDelay()) .build()) .collect(Collectors.toList()); return new DefaultProxyClient<>(primitiveName, primitiveType, this, serviceType, partitions, config.getPartitioner()); }
@Override @SuppressWarnings("unchecked") public CompletableFuture<PrimitiveRegistry> start() { ProxyProtocol protocol = partitionService.getSystemPartitionGroup().newProtocol(); ProxyClient proxy = protocol.newProxy( "primitives", AtomicMapType.instance(), AtomicMapService.class, new ServiceConfig(), partitionService); return proxy.connect() .thenApply(v -> { AtomicMapProxy mapProxy = new AtomicMapProxy(proxy, this); primitives = new TranscodingAsyncAtomicMap<>( mapProxy, key -> key, key -> key, value -> value != null ? SERIALIZER.encode(value) : null, value -> value != null ? SERIALIZER.decode(value) : null); started.set(true); return this; }); }
@Override public <S> ProxyClient<S> newProxy(String primitiveName, PrimitiveType primitiveType, Class<S> serviceType, ServiceConfig serviceConfig, PartitionService partitionService) { PartitionGroup partitionGroup = partitionService.getPartitionGroup(this); if (partitionGroup == null) { throw new ConfigurationException("No Raft partition group matching the configured protocol exists"); } Collection<SessionClient> partitions = partitionGroup.getPartitions().stream() .map(partition -> ((RaftPartition) partition).getClient() .sessionBuilder(primitiveName, primitiveType, serviceConfig) .withMinTimeout(config.getMinTimeout()) .withMaxTimeout(config.getMaxTimeout()) .withReadConsistency(config.getReadConsistency()) .withCommunicationStrategy(config.getCommunicationStrategy()) .withRecoveryStrategy(config.getRecoveryStrategy()) .withMaxRetries(config.getMaxRetries()) .withRetryDelay(config.getRetryDelay()) .build()) .collect(Collectors.toList()); return new DefaultProxyClient<>(primitiveName, primitiveType, this, serviceType, partitions, config.getPartitioner()); } }
@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 LogClient newClient(PartitionService partitionService) { Collection<LogSession> partitions = partitionService.getPartitionGroup(this) .getPartitions() .stream() .map(partition -> ((LogPartition) partition).getClient().logSessionBuilder().build()) .collect(Collectors.toList()); return new DistributedLogClient(this, partitions, config.getPartitioner()); }
partitionGroup = managementService.getPartitionService().getPartitionGroup(protocolType); } else { partitionGroup = managementService.getPartitionService().getPartitionGroup(participantInfo.group());