예제 #1
0
 private void updateMembersRef() {
   final Map<Address, MemberImpl> map = new LinkedHashMap<Address, MemberImpl>(members.size());
   for (MemberImpl member : members) {
     map.put(member.getAddress(), member);
   }
   clusterService.setMembersRef(Collections.unmodifiableMap(map));
 }
예제 #2
0
 private List<MembershipEvent> detectMembershipEvents(Map<String, MemberImpl> prevMembers) {
   final List<MembershipEvent> events = new LinkedList<MembershipEvent>();
   final Set<Member> eventMembers =
       Collections.unmodifiableSet(new LinkedHashSet<Member>(members));
   for (MemberImpl member : members) {
     final MemberImpl former = prevMembers.remove(member.getUuid());
     if (former == null) {
       events.add(
           new MembershipEvent(
               client.getCluster(), member, MembershipEvent.MEMBER_ADDED, eventMembers));
     }
   }
   for (MemberImpl member : prevMembers.values()) {
     events.add(
         new MembershipEvent(
             client.getCluster(), member, MembershipEvent.MEMBER_REMOVED, eventMembers));
     if (clusterService.getMember(member.getAddress()) == null) {
       final Connection connection = connectionManager.getConnection(member.getAddress());
       if (connection != null) {
         connectionManager.destroyConnection(connection);
       }
     }
   }
   return events;
 }
예제 #3
0
  void initialMembers(Collection<MemberImpl> memberList) {

    Map<String, MemberImpl> prevMembers = Collections.emptyMap();
    if (!members.isEmpty()) {
      prevMembers = new HashMap<String, MemberImpl>(members.size());
      for (MemberImpl member : members) {
        prevMembers.put(member.getUuid(), member);
      }
      members.clear();
    }
    members.addAll(memberList);

    final List<MembershipEvent> events = detectMembershipEvents(prevMembers);
    if (events.size() != 0) {
      applyMemberListChanges();
    }
    fireMembershipEvent(events);
  }
예제 #4
0
 private void memberAttributeChanged(MemberAttributeChange memberAttributeChange) {
   Map<Address, MemberImpl> memberMap = clusterService.getMembersRef();
   if (memberMap == null) {
     return;
   }
   if (memberAttributeChange == null) {
     return;
   }
   for (MemberImpl target : memberMap.values()) {
     if (target.getUuid().equals(memberAttributeChange.getUuid())) {
       final MemberAttributeOperationType operationType = memberAttributeChange.getOperationType();
       final String key = memberAttributeChange.getKey();
       final Object value = memberAttributeChange.getValue();
       target.updateAttribute(operationType, key, value);
       MemberAttributeEvent memberAttributeEvent =
           new MemberAttributeEvent(client.getCluster(), target, operationType, key, value);
       clusterService.fireMemberAttributeEvent(memberAttributeEvent);
       break;
     }
   }
 }
예제 #5
0
 private void memberRemoved(MemberImpl member) {
   members.remove(member);
   final Connection connection = connectionManager.getConnection(member.getAddress());
   if (connection != null) {
     connectionManager.destroyConnection(connection);
   }
   applyMemberListChanges();
   MembershipEvent event =
       new MembershipEvent(
           client.getCluster(),
           member,
           ClientInitialMembershipEvent.MEMBER_REMOVED,
           Collections.unmodifiableSet(new LinkedHashSet<Member>(members)));
   clusterService.fireMembershipEvent(event);
 }