private void updateTerm(long term) { if (term > currentTerm.term()) { recomputeTerm(groupMembershipService.getMembership(partitionId.group())); } }
/** * Handles a cluster membership event. */ private void handleClusterMembershipEvent(ClusterMembershipEvent event) { if (event.type() == ClusterMembershipEvent.Type.MEMBER_ADDED || event.type() == ClusterMembershipEvent.Type.MEMBER_REMOVED) { recomputeTerm(groupMembershipService.getMembership(partitionId.group())); } }
public HashBasedPrimaryElection( PartitionId partitionId, ClusterMembershipService clusterMembershipService, PartitionGroupMembershipService groupMembershipService, ClusterCommunicationService communicationService, ScheduledExecutorService executor) { this.partitionId = partitionId; this.clusterMembershipService = clusterMembershipService; this.groupMembershipService = groupMembershipService; this.communicationService = communicationService; this.subject = String.format("primary-election-counter-%s-%d", partitionId.group(), partitionId.id()); recomputeTerm(groupMembershipService.getMembership(partitionId.group())); groupMembershipService.addListener(groupMembershipEventListener); clusterMembershipService.addListener(clusterMembershipEventListener); communicationService.subscribe(subject, SERIALIZER::decode, this::updateCounters, executor); broadcastFuture = executor.scheduleAtFixedRate(this::broadcastCounters, BROADCAST_INTERVAL, BROADCAST_INTERVAL, TimeUnit.MILLISECONDS); }