private void memberAdded(MemberImpl member) { members.add(member); applyMemberListChanges(); MembershipEvent event = new MembershipEvent( client.getCluster(), member, ClientInitialMembershipEvent.MEMBER_ADDED, Collections.unmodifiableSet(new LinkedHashSet<Member>(members))); clusterService.fireMembershipEvent(event); }
private void listenMembershipEvents() throws IOException { final SerializationService serializationService = clusterService.getSerializationService(); while (!Thread.currentThread().isInterrupted()) { final Data clientResponseData = conn.read(); final ClientResponse clientResponse = serializationService.toObject(clientResponseData); final Object eventObject = serializationService.toObject(clientResponse.getResponse()); final ClientMembershipEvent event = (ClientMembershipEvent) eventObject; final MemberImpl member = (MemberImpl) event.getMember(); boolean membersUpdated = false; if (event.getEventType() == MembershipEvent.MEMBER_ADDED) { members.add(member); membersUpdated = true; } else if (event.getEventType() == ClientMembershipEvent.MEMBER_REMOVED) { members.remove(member); membersUpdated = true; // getConnectionManager().removeConnectionPool(member.getAddress()); // //TODO } else if (event.getEventType() == ClientMembershipEvent.MEMBER_ATTRIBUTE_CHANGED) { MemberAttributeChange memberAttributeChange = event.getMemberAttributeChange(); Map<Address, MemberImpl> memberMap = clusterService.getMembersRef(); if (memberMap != null) { 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; } } } } if (membersUpdated) { ((ClientPartitionServiceImpl) client.getClientPartitionService()).refreshPartitions(); updateMembersRef(); LOGGER.info(clusterService.membersString()); clusterService.fireMembershipEvent( new MembershipEvent( client.getCluster(), member, event.getEventType(), Collections.unmodifiableSet(new LinkedHashSet<Member>(members)))); } } }
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); }
private void loadInitialMemberList() throws Exception { final SerializationService serializationService = clusterService.getSerializationService(); final AddMembershipListenerRequest request = new AddMembershipListenerRequest(); final SerializableCollection coll = (SerializableCollection) connectionManager.sendAndReceive(request, conn); 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(); } for (Data data : coll) { members.add((MemberImpl) serializationService.toObject(data)); } updateMembersRef(); LOGGER.info(clusterService.membersString()); 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)); } for (MembershipEvent event : events) { clusterService.fireMembershipEvent(event); } latch.countDown(); }
private void fireMembershipEvent(List<MembershipEvent> events) { for (MembershipEvent event : events) { clusterService.fireMembershipEvent(event); } }