@Override public boolean equals(Object object) { if (object instanceof PartitionMetadata) { PartitionMetadata partition = (PartitionMetadata) object; return partition.id.equals(id) && partition.members.equals(members); } return false; }
@Override public boolean equals(Object object) { if (object instanceof PartitionEvent) { PartitionEvent that = (PartitionEvent) object; return this.partitionId().equals(that.partitionId()) && this.members.equals(that.members) && Objects.equals(this.primary, that.primary) && this.backups.equals(that.backups); } return false; }
int countPrimaries(Registration registration) { if (registration == null) { return 0; } return (int) elections.entrySet().stream() .filter(entry -> !entry.getKey().equals(partitionId)) .filter(entry -> entry.getValue().primary != null) .filter(entry -> { // Get the topic leader's identifier and a list of session identifiers. // Then return true if the leader's identifier matches any of the session's candidates. GroupMember leaderId = entry.getValue().primary(); List<GroupMember> sessionCandidates = entry.getValue().registrations.stream() .filter(r -> r.sessionId == registration.sessionId) .map(r -> r.member()) .collect(Collectors.toList()); return sessionCandidates.stream() .anyMatch(candidate -> Objects.equals(candidate, leaderId)); }) .count(); }
public DefaultPrimaryElection(PartitionId partitionId, SessionClient proxy, PrimaryElectionService service) { this.partitionId = checkNotNull(partitionId); this.proxy = proxy; this.service = service; this.eventListener = event -> { if (event.partitionId().equals(partitionId)) { listeners.forEach(l -> l.event(event)); } }; service.addListener(eventListener); }