@Override @SuppressWarnings("unchecked") public CompletableFuture<Void> stop() { groupMembershipService.removeListener(groupMembershipEventListener); Stream<CompletableFuture<Void>> systemStream = Stream.of(systemGroup != null ? systemGroup.close() : CompletableFuture.completedFuture(null)); Stream<CompletableFuture<Void>> groupStream = groups.values().stream().map(ManagedPartitionGroup::close); List<CompletableFuture<Void>> futures = Stream.concat(systemStream, groupStream).collect(Collectors.toList()); return CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])).exceptionally(throwable -> { LOGGER.error("Failed closing partition group(s)", throwable); return null; }).thenCompose(v -> electionService != null ? electionService.stop() : CompletableFuture.completedFuture(null)).exceptionally(throwable -> { LOGGER.error("Failed stopping election service", throwable); return null; }).thenCompose(v -> groupMembershipService.stop()).exceptionally(throwable -> { LOGGER.error("Failed stopping group membership service", throwable); return null; }).thenRun(() -> { LOGGER.info("Stopped"); started.set(false); }); } }
systemSessionIdService = new ReplicatedSessionIdService(systemGroup); electionService = new HashBasedPrimaryElectionService(clusterMembershipService, groupMembershipService, communicationService); return electionService.start() .thenCompose(s -> { PartitionManagementService managementService = new DefaultPartitionManagementService( .thenCompose(v -> systemElectionService.start() .thenCompose(v2 -> systemSessionIdService.start()) .thenApply(v2 -> new DefaultPartitionManagementService(