@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); }); } }
@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) { .thenCompose(managementService -> { this.partitionManagementService = (PartitionManagementService) managementService; List<CompletableFuture> futures = groupMembershipService.getMemberships().stream() .map(membership -> { ManagedPartitionGroup group;