use of io.atomix.core.election.LeaderElector in project atomix by atomix.
the class LeaderElectorProxyBuilder method buildAsync.
@Override
@SuppressWarnings("unchecked")
public CompletableFuture<LeaderElector<T>> buildAsync() {
PrimitiveProtocol protocol = protocol();
PartitionGroup<?> partitions = managementService.getPartitionService().getPartitionGroup(protocol);
Map<PartitionId, CompletableFuture<AsyncLeaderElector<T>>> electors = Maps.newConcurrentMap();
for (Partition partition : partitions.getPartitions()) {
electors.put(partition.id(), newLeaderElector(partition.getPrimitiveClient().newProxy(name(), primitiveType(), protocol)));
}
Partitioner<String> partitioner = topic -> partitions.getPartition(topic).id();
return Futures.allOf(new ArrayList<>(electors.values())).thenApply(e -> new PartitionedAsyncLeaderElector<T>(name(), Maps.transformValues(electors, v -> v.getNow(null)), partitioner).sync());
}
Aggregations