use of io.atomix.primitive.partition.impl.DefaultPrimaryElectionService in project atomix by atomix.
the class Atomix method start.
/**
* Starts the Atomix instance.
* <p>
* The returned future will be completed once this instance completes startup. Note that in order to complete startup,
* all partitions must be able to form. For Raft partitions, that requires that a majority of the nodes in each
* partition be started concurrently.
*
* @return a future to be completed once the instance has completed startup
*/
@Override
public synchronized CompletableFuture<Atomix> start() {
if (closeFuture != null) {
return Futures.exceptionalFuture(new IllegalStateException("Atomix instance " + (closeFuture.isDone() ? "shutdown" : "shutting down")));
}
if (openFuture != null) {
return openFuture;
}
openFuture = messagingService.start().thenComposeAsync(v -> metadataService.start(), context).thenComposeAsync(v -> clusterService.start(), context).thenComposeAsync(v -> clusterMessagingService.start(), context).thenComposeAsync(v -> clusterEventingService.start(), context).thenComposeAsync(v -> systemPartitionGroup.open(new DefaultPartitionManagementService(metadataService, clusterService, clusterMessagingService, primitiveTypes, null, null)), context).thenComposeAsync(v -> {
ManagedPrimaryElectionService electionService = new DefaultPrimaryElectionService(systemPartitionGroup, RaftProtocol.builder().withMinTimeout(Duration.ofMillis(250)).withMaxTimeout(Duration.ofSeconds(5)).withReadConsistency(ReadConsistency.LINEARIZABLE).withCommunicationStrategy(CommunicationStrategy.LEADER).withRecoveryStrategy(Recovery.RECOVER).withMaxRetries(5).build());
ManagedSessionIdService sessionIdService = new IdGeneratorSessionIdService(systemPartitionGroup);
return electionService.start().thenComposeAsync(v2 -> sessionIdService.start(), context).thenApply(v2 -> new DefaultPartitionManagementService(metadataService, clusterService, clusterMessagingService, primitiveTypes, electionService, sessionIdService));
}, context).thenComposeAsync(partitionManagementService -> partitions.open((PartitionManagementService) partitionManagementService), context).thenComposeAsync(v -> primitives.start(), context).thenApplyAsync(v -> {
metadataService.addNode(clusterService.getLocalNode());
started.set(true);
LOGGER.info("Started");
return this;
}, context);
return openFuture;
}
Aggregations