private void sendMembershipEvents( Collection<MemberImpl> currentMembers, Collection<MemberImpl> newMembers) { Set<Member> eventMembers = new LinkedHashSet<Member>(currentMembers); if (!newMembers.isEmpty()) { if (newMembers.size() == 1) { MemberImpl newMember = newMembers.iterator().next(); // sync call node.getPartitionService().memberAdded(newMember); // async events eventMembers.add(newMember); sendMembershipEventNotifications(newMember, unmodifiableSet(eventMembers), true); } else { for (MemberImpl newMember : newMembers) { // sync call node.getPartitionService().memberAdded(newMember); // async events eventMembers.add(newMember); sendMembershipEventNotifications( newMember, unmodifiableSet(new LinkedHashSet<Member>(eventMembers)), true); } } } }
private void removeMember(MemberImpl deadMember) { logger.info("Removing " + deadMember); lock.lock(); try { Map<Address, MemberImpl> members = membersMapRef.get(); final Address deadAddress = deadMember.getAddress(); if (members.containsKey(deadAddress)) { // !!! ORDERED !!! Map<Address, MemberImpl> newMembers = new LinkedHashMap<Address, MemberImpl>(members); newMembers.remove(deadAddress); clusterHeartbeatManager.removeMember(deadMember); setMembersRef(newMembers); if (node.isMaster()) { if (logger.isFinestEnabled()) { logger.finest(deadMember + " is dead, sending remove to all other members..."); } invokeMemberRemoveOperation(deadAddress); } final ClusterState clusterState = clusterStateManager.getState(); if (clusterState == ClusterState.FROZEN || clusterState == ClusterState.PASSIVE) { if (logger.isFinestEnabled()) { logger.finest( deadMember + " is dead, added to members left while cluster is " + clusterState + " state"); } Map<Address, MemberImpl> membersRemovedInNotActiveState = new LinkedHashMap<Address, MemberImpl>(membersRemovedInNotActiveStateRef.get()); membersRemovedInNotActiveState.put(deadAddress, deadMember); membersRemovedInNotActiveStateRef.set( Collections.unmodifiableMap(membersRemovedInNotActiveState)); final InternalPartitionServiceImpl partitionService = node.partitionService; partitionService.cancelReplicaSyncRequestsTo(deadAddress); } else { onMemberRemove(deadMember, newMembers); } // async events sendMembershipEventNotifications( deadMember, unmodifiableSet(new LinkedHashSet<Member>(newMembers.values())), false); } } finally { lock.unlock(); } }