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;
});
});
}
Aggregations