Search in sources :

Example 1 with LeaderElector

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());
}
Also used : LeaderElectorBuilder(io.atomix.core.election.LeaderElectorBuilder) AsyncLeaderElector(io.atomix.core.election.AsyncLeaderElector) LeaderElector(io.atomix.core.election.LeaderElector) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) CompletableFuture(java.util.concurrent.CompletableFuture) Maps(com.google.common.collect.Maps) PartitionGroup(io.atomix.primitive.partition.PartitionGroup) PartitionId(io.atomix.primitive.partition.PartitionId) ArrayList(java.util.ArrayList) Partition(io.atomix.primitive.partition.Partition) PrimitiveProxy(io.atomix.primitive.proxy.PrimitiveProxy) PrimitiveManagementService(io.atomix.primitive.PrimitiveManagementService) PrimitiveProtocol(io.atomix.primitive.PrimitiveProtocol) Map(java.util.Map) Partitioner(io.atomix.primitive.partition.Partitioner) Futures(io.atomix.utils.concurrent.Futures) Partition(io.atomix.primitive.partition.Partition) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) PartitionId(io.atomix.primitive.partition.PartitionId) PrimitiveProtocol(io.atomix.primitive.PrimitiveProtocol)

Aggregations

Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Maps (com.google.common.collect.Maps)1 AsyncLeaderElector (io.atomix.core.election.AsyncLeaderElector)1 LeaderElector (io.atomix.core.election.LeaderElector)1 LeaderElectorBuilder (io.atomix.core.election.LeaderElectorBuilder)1 PrimitiveManagementService (io.atomix.primitive.PrimitiveManagementService)1 PrimitiveProtocol (io.atomix.primitive.PrimitiveProtocol)1 Partition (io.atomix.primitive.partition.Partition)1 PartitionGroup (io.atomix.primitive.partition.PartitionGroup)1 PartitionId (io.atomix.primitive.partition.PartitionId)1 Partitioner (io.atomix.primitive.partition.Partitioner)1 PrimitiveProxy (io.atomix.primitive.proxy.PrimitiveProxy)1 Futures (io.atomix.utils.concurrent.Futures)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1