Search in sources :

Example 1 with ReplicatedSessionIdService

use of io.atomix.primitive.session.impl.ReplicatedSessionIdService in project atomix by atomix.

the class DefaultPartitionService method start.

@Override
@SuppressWarnings("unchecked")
public CompletableFuture<PartitionService> start() {
    groupMembershipService.addListener(groupMembershipEventListener);
    return groupMembershipService.start().thenCompose(v -> {
        PartitionGroupMembership systemGroupMembership = groupMembershipService.getSystemMembership();
        if (systemGroupMembership != null) {
            if (systemGroup == null) {
                systemGroup = ((PartitionGroup.Type) systemGroupMembership.config().getType()).newPartitionGroup(systemGroupMembership.config());
            }
            systemElectionService = new DefaultPrimaryElectionService(systemGroup);
            systemSessionIdService = new ReplicatedSessionIdService(systemGroup);
            electionService = new HashBasedPrimaryElectionService(clusterMembershipService, groupMembershipService, communicationService);
            return electionService.start().thenCompose(s -> {
                PartitionManagementService managementService = new DefaultPartitionManagementService(clusterMembershipService, communicationService, primitiveTypeRegistry, electionService, new DefaultSessionIdService());
                if (systemGroupMembership.members().contains(clusterMembershipService.getLocalMember().id())) {
                    return systemGroup.join(managementService);
                } else {
                    return systemGroup.connect(managementService);
                }
            });
        } else {
            return Futures.exceptionalFuture(new ConfigurationException("No system partition group found"));
        }
    }).thenCompose(v -> systemElectionService.start().thenCompose(v2 -> systemSessionIdService.start()).thenApply(v2 -> new DefaultPartitionManagementService(clusterMembershipService, communicationService, primitiveTypeRegistry, systemElectionService, systemSessionIdService))).thenCompose(managementService -> {
        this.partitionManagementService = (PartitionManagementService) managementService;
        List<CompletableFuture> futures = groupMembershipService.getMemberships().stream().map(membership -> {
            ManagedPartitionGroup group;
            synchronized (groups) {
                group = groups.get(membership.group());
                if (group == null) {
                    group = ((PartitionGroup.Type) membership.config().getType()).newPartitionGroup(membership.config());
                    groups.put(group.name(), group);
                }
            }
            if (membership.members().contains(clusterMembershipService.getLocalMember().id())) {
                return group.join(partitionManagementService);
            } else {
                return group.connect(partitionManagementService);
            }
        }).collect(Collectors.toList());
        return CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])).thenApply(v -> {
            LOGGER.info("Started");
            started.set(true);
            return this;
        });
    });
}
Also used : ManagedPartitionGroup(io.atomix.primitive.partition.ManagedPartitionGroup) PartitionGroup(io.atomix.primitive.partition.PartitionGroup) ManagedPrimaryElectionService(io.atomix.primitive.partition.ManagedPrimaryElectionService) PartitionGroupMembershipEventListener(io.atomix.primitive.partition.PartitionGroupMembershipEventListener) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PrimitiveTypeRegistry(io.atomix.primitive.PrimitiveTypeRegistry) ManagedPartitionService(io.atomix.primitive.partition.ManagedPartitionService) DefaultSessionIdService(io.atomix.primitive.session.impl.DefaultSessionIdService) CompletableFuture(java.util.concurrent.CompletableFuture) ConfigurationException(io.atomix.utils.config.ConfigurationException) ClusterMembershipService(io.atomix.cluster.ClusterMembershipService) PartitionGroupTypeRegistry(io.atomix.primitive.partition.PartitionGroupTypeRegistry) Map(java.util.Map) ClusterCommunicationService(io.atomix.cluster.messaging.ClusterCommunicationService) ManagedPartitionGroup(io.atomix.primitive.partition.ManagedPartitionGroup) Futures(io.atomix.utils.concurrent.Futures) Logger(org.slf4j.Logger) ReplicatedSessionIdService(io.atomix.primitive.session.impl.ReplicatedSessionIdService) ManagedSessionIdService(io.atomix.primitive.session.ManagedSessionIdService) Collection(java.util.Collection) ManagedPartitionGroupMembershipService(io.atomix.primitive.partition.ManagedPartitionGroupMembershipService) Maps(com.google.common.collect.Maps) PartitionGroup(io.atomix.primitive.partition.PartitionGroup) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) PartitionManagementService(io.atomix.primitive.partition.PartitionManagementService) PartitionService(io.atomix.primitive.partition.PartitionService) PartitionGroupMembershipEvent(io.atomix.primitive.partition.PartitionGroupMembershipEvent) PartitionGroupMembership(io.atomix.primitive.partition.PartitionGroupMembership) ReplicatedSessionIdService(io.atomix.primitive.session.impl.ReplicatedSessionIdService) CompletableFuture(java.util.concurrent.CompletableFuture) PartitionGroupMembership(io.atomix.primitive.partition.PartitionGroupMembership) ManagedPartitionGroup(io.atomix.primitive.partition.ManagedPartitionGroup) PartitionManagementService(io.atomix.primitive.partition.PartitionManagementService) ConfigurationException(io.atomix.utils.config.ConfigurationException) DefaultSessionIdService(io.atomix.primitive.session.impl.DefaultSessionIdService)

Aggregations

Maps (com.google.common.collect.Maps)1 ClusterMembershipService (io.atomix.cluster.ClusterMembershipService)1 ClusterCommunicationService (io.atomix.cluster.messaging.ClusterCommunicationService)1 PrimitiveTypeRegistry (io.atomix.primitive.PrimitiveTypeRegistry)1 ManagedPartitionGroup (io.atomix.primitive.partition.ManagedPartitionGroup)1 ManagedPartitionGroupMembershipService (io.atomix.primitive.partition.ManagedPartitionGroupMembershipService)1 ManagedPartitionService (io.atomix.primitive.partition.ManagedPartitionService)1 ManagedPrimaryElectionService (io.atomix.primitive.partition.ManagedPrimaryElectionService)1 PartitionGroup (io.atomix.primitive.partition.PartitionGroup)1 PartitionGroupMembership (io.atomix.primitive.partition.PartitionGroupMembership)1 PartitionGroupMembershipEvent (io.atomix.primitive.partition.PartitionGroupMembershipEvent)1 PartitionGroupMembershipEventListener (io.atomix.primitive.partition.PartitionGroupMembershipEventListener)1 PartitionGroupTypeRegistry (io.atomix.primitive.partition.PartitionGroupTypeRegistry)1 PartitionManagementService (io.atomix.primitive.partition.PartitionManagementService)1 PartitionService (io.atomix.primitive.partition.PartitionService)1 ManagedSessionIdService (io.atomix.primitive.session.ManagedSessionIdService)1 DefaultSessionIdService (io.atomix.primitive.session.impl.DefaultSessionIdService)1 ReplicatedSessionIdService (io.atomix.primitive.session.impl.ReplicatedSessionIdService)1 Futures (io.atomix.utils.concurrent.Futures)1 ConfigurationException (io.atomix.utils.config.ConfigurationException)1