@Override public CompletableFuture<Void> start() { registerListeners(); return memberGroupService.start().thenCompose(v -> { MemberGroup group = memberGroupService.getMemberGroup(clusterMembershipService.getLocalMember()); if (group != null) { return primaryElection.enter(new GroupMember(clusterMembershipService.getLocalMember().id(), group.id())); } return CompletableFuture.completedFuture(null); }).thenApply(v -> { started.set(true); return null; }); }
@Override public CompletableFuture<Void> stop() { unregisterListeners(); started.set(false); List<CompletableFuture<Void>> futures = services.values().stream() .map(future -> future.thenCompose(service -> service.close())) .collect(Collectors.toList()); return Futures.allOf(futures).exceptionally(throwable -> { log.error("Failed closing services", throwable); return null; }).thenCompose(v -> memberGroupService.stop()).exceptionally(throwable -> { log.error("Failed stopping member group service", throwable); return null; }).thenRunAsync(() -> { if (closeOnStop) { threadContextFactory.close(); } }); } }
@Override public CompletableFuture<Void> start() { registerListeners(); compactTimer = threadContext.schedule(Duration.ofSeconds(30), this::compact); return memberGroupService.start().thenComposeAsync(v -> { MemberGroup group = memberGroupService.getMemberGroup(clusterMembershipService.getLocalMember()); primaryElection.addListener(primaryElectionListener); if (group != null) { return primaryElection.enter(new GroupMember(clusterMembershipService.getLocalMember().id(), group.id())) .thenApply(term -> { changeRole(term); return null; }); } return CompletableFuture.completedFuture(null); }, threadContext).thenApply(v -> { started.set(true); return null; }); }
@Override public CompletableFuture<Void> stop() { unregisterListeners(); primaryElection.removeListener(primaryElectionListener); if (compactTimer != null) { compactTimer.cancel(); } journal.close(); started.set(false); return memberGroupService.stop().exceptionally(throwable -> { log.error("Failed stopping member group service", throwable); return null; }).thenRunAsync(() -> { if (closeOnStop) { threadContextFactory.close(); } }); } }
@Override public CompletableFuture<Void> start() { registerListeners(); compactTimer = threadContext.schedule(Duration.ofSeconds(30), this::compact); return memberGroupService.start().thenComposeAsync(v -> { MemberGroup group = memberGroupService.getMemberGroup(clusterMembershipService.getLocalMember()); primaryElection.addListener(primaryElectionListener); if (group != null) { return primaryElection.enter(new GroupMember(clusterMembershipService.getLocalMember().id(), group.id())) .thenApply(term -> { changeRole(term); return null; }); } return CompletableFuture.completedFuture(null); }, threadContext).thenApply(v -> { started.set(true); return null; }); }
@Override public CompletableFuture<Void> stop() { unregisterListeners(); primaryElection.removeListener(primaryElectionListener); if (compactTimer != null) { compactTimer.cancel(); } journal.close(); started.set(false); return memberGroupService.stop().exceptionally(throwable -> { log.error("Failed stopping member group service", throwable); return null; }).thenRunAsync(() -> { if (closeOnStop) { threadContextFactory.close(); } }); } }