Search in sources :

Example 1 with IdGeneratorSessionIdService

use of io.atomix.core.generator.impl.IdGeneratorSessionIdService 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;
}
Also used : ManagedClusterMetadataService(io.atomix.cluster.ManagedClusterMetadataService) Node(io.atomix.cluster.Node) Arrays(java.util.Arrays) ManagedPrimaryElectionService(io.atomix.primitive.partition.ManagedPrimaryElectionService) ClusterEventingService(io.atomix.cluster.messaging.ClusterEventingService) DistributedPrimitive(io.atomix.primitive.DistributedPrimitive) RaftProtocol(io.atomix.protocols.raft.RaftProtocol) LoggerFactory(org.slf4j.LoggerFactory) PrimitiveTypeRegistry(io.atomix.primitive.PrimitiveTypeRegistry) DistributedPrimitiveBuilder(io.atomix.primitive.DistributedPrimitiveBuilder) NettyMessagingService(io.atomix.messaging.impl.NettyMessagingService) TransactionBuilder(io.atomix.core.transaction.TransactionBuilder) Managed(io.atomix.utils.Managed) InetAddress(java.net.InetAddress) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) CorePrimitivesService(io.atomix.core.impl.CorePrimitivesService) Duration(java.time.Duration) ManagedPartitionGroup(io.atomix.primitive.partition.ManagedPartitionGroup) DefaultPrimaryElectionService(io.atomix.primitive.partition.impl.DefaultPrimaryElectionService) ManagedSessionIdService(io.atomix.primitive.session.ManagedSessionIdService) Collection(java.util.Collection) Set(java.util.Set) Endpoint(io.atomix.messaging.Endpoint) ManagedClusterEventingService(io.atomix.cluster.messaging.ManagedClusterEventingService) ReadConsistency(io.atomix.protocols.raft.ReadConsistency) RaftPartitionGroup(io.atomix.protocols.raft.partition.RaftPartitionGroup) SingleThreadContext(io.atomix.utils.concurrent.SingleThreadContext) ThreadContext(io.atomix.utils.concurrent.ThreadContext) ClusterMessagingService(io.atomix.cluster.messaging.ClusterMessagingService) CommunicationStrategy(io.atomix.protocols.raft.proxy.CommunicationStrategy) DefaultClusterMessagingService(io.atomix.cluster.messaging.impl.DefaultClusterMessagingService) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) DefaultPartitionService(io.atomix.primitive.partition.impl.DefaultPartitionService) IdGeneratorSessionIdService(io.atomix.core.generator.impl.IdGeneratorSessionIdService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ManagedPartitionService(io.atomix.primitive.partition.ManagedPartitionService) CompletableFuture(java.util.concurrent.CompletableFuture) ManagedClusterService(io.atomix.cluster.ManagedClusterService) DefaultClusterEventingService(io.atomix.cluster.messaging.impl.DefaultClusterEventingService) ArrayList(java.util.ArrayList) DefaultClusterService(io.atomix.cluster.impl.DefaultClusterService) Futures(io.atomix.utils.concurrent.Futures) PrimaryBackupPartitionGroup(io.atomix.protocols.backup.partition.PrimaryBackupPartitionGroup) ManagedMessagingService(io.atomix.messaging.ManagedMessagingService) ClusterMetadata(io.atomix.cluster.ClusterMetadata) Logger(org.slf4j.Logger) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) ClusterMetadataService(io.atomix.cluster.ClusterMetadataService) Recovery(io.atomix.primitive.Recovery) UnknownHostException(java.net.UnknownHostException) File(java.io.File) DefaultClusterMetadataService(io.atomix.cluster.impl.DefaultClusterMetadataService) ManagedClusterMessagingService(io.atomix.cluster.messaging.ManagedClusterMessagingService) MessagingService(io.atomix.messaging.MessagingService) PartitionManagementService(io.atomix.primitive.partition.PartitionManagementService) PrimitiveType(io.atomix.primitive.PrimitiveType) PartitionService(io.atomix.primitive.partition.PartitionService) DefaultPartitionManagementService(io.atomix.primitive.partition.impl.DefaultPartitionManagementService) ClusterService(io.atomix.cluster.ClusterService) Collections(java.util.Collections) ManagedPrimaryElectionService(io.atomix.primitive.partition.ManagedPrimaryElectionService) DefaultPrimaryElectionService(io.atomix.primitive.partition.impl.DefaultPrimaryElectionService) DefaultPartitionManagementService(io.atomix.primitive.partition.impl.DefaultPartitionManagementService) IdGeneratorSessionIdService(io.atomix.core.generator.impl.IdGeneratorSessionIdService) ManagedSessionIdService(io.atomix.primitive.session.ManagedSessionIdService)

Aggregations

MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ClusterMetadata (io.atomix.cluster.ClusterMetadata)1 ClusterMetadataService (io.atomix.cluster.ClusterMetadataService)1 ClusterService (io.atomix.cluster.ClusterService)1 ManagedClusterMetadataService (io.atomix.cluster.ManagedClusterMetadataService)1 ManagedClusterService (io.atomix.cluster.ManagedClusterService)1 Node (io.atomix.cluster.Node)1 DefaultClusterMetadataService (io.atomix.cluster.impl.DefaultClusterMetadataService)1 DefaultClusterService (io.atomix.cluster.impl.DefaultClusterService)1 ClusterEventingService (io.atomix.cluster.messaging.ClusterEventingService)1 ClusterMessagingService (io.atomix.cluster.messaging.ClusterMessagingService)1 ManagedClusterEventingService (io.atomix.cluster.messaging.ManagedClusterEventingService)1 ManagedClusterMessagingService (io.atomix.cluster.messaging.ManagedClusterMessagingService)1 DefaultClusterEventingService (io.atomix.cluster.messaging.impl.DefaultClusterEventingService)1 DefaultClusterMessagingService (io.atomix.cluster.messaging.impl.DefaultClusterMessagingService)1 IdGeneratorSessionIdService (io.atomix.core.generator.impl.IdGeneratorSessionIdService)1 CorePrimitivesService (io.atomix.core.impl.CorePrimitivesService)1 TransactionBuilder (io.atomix.core.transaction.TransactionBuilder)1