/** * Returns the partition name. * * @return the partition name */ public String name() { return String.format("%s-partition-%d", partitionId.group(), partitionId.id()); }
/** * Returns the partition name. * * @return the partition name */ public String name() { return String.format("%s-partition-%d", partitionId.group(), partitionId.id()); }
/** * Returns the partition name. * * @return the partition name */ public String name() { return String.format("%s-partition-%d", partitionId.group(), partitionId.id()); }
@Override public int hashCode() { return Objects.hash(id(), group()); }
@Override public boolean isRelevant(PartitionGroupMembershipEvent event) { return event.membership().group().equals(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); }
public DistributedLogSession( PartitionId partitionId, SessionId sessionId, ClusterMembershipService clusterMembershipService, LogClientProtocol protocol, PrimaryElection primaryElection, ThreadContext threadContext) { this.partitionId = checkNotNull(partitionId, "partitionId cannot be null"); this.sessionId = checkNotNull(sessionId, "sessionId cannot be null"); this.protocol = checkNotNull(protocol, "protocol cannot be null"); this.primaryElection = checkNotNull(primaryElection, "primaryElection cannot be null"); this.threadContext = checkNotNull(threadContext, "threadContext cannot be null"); this.memberId = clusterMembershipService.getLocalMember().id(); this.subject = String.format("%s-%s-%s", partitionId.group(), partitionId.id(), sessionId); clusterMembershipService.addListener(membershipEventListener); primaryElection.addListener(primaryElectionListener); this.log = ContextualLoggerFactory.getLogger(getClass(), LoggerContext.builder(DistributedLogProducer.class) .addValue(partitionId.group() != null ? String.format("%s-%d", partitionId.group(), partitionId.id()) : partitionId.id()) .build()); }
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())); } }
/** * Returns the partition name. * * @return the partition name */ public String name() { return String.format("%s-partition-%d", partitionId.group(), partitionId.id()); }
public DistributedLogSession( PartitionId partitionId, SessionId sessionId, ClusterMembershipService clusterMembershipService, LogClientProtocol protocol, PrimaryElection primaryElection, ThreadContext threadContext) { this.partitionId = checkNotNull(partitionId, "partitionId cannot be null"); this.sessionId = checkNotNull(sessionId, "sessionId cannot be null"); this.protocol = checkNotNull(protocol, "protocol cannot be null"); this.primaryElection = checkNotNull(primaryElection, "primaryElection cannot be null"); this.threadContext = checkNotNull(threadContext, "threadContext cannot be null"); this.memberId = clusterMembershipService.getLocalMember().id(); this.subject = String.format("%s-%s-%s", partitionId.group(), partitionId.id(), sessionId); clusterMembershipService.addListener(membershipEventListener); primaryElection.addListener(primaryElectionListener); this.log = ContextualLoggerFactory.getLogger(getClass(), LoggerContext.builder(DistributedLogProducer.class) .addValue(partitionId.group() != null ? String.format("%s-%d", partitionId.group(), partitionId.id()) : partitionId.id()) .build()); }