@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; }); }
@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()); }
@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 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 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 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()); }