private void listenMembershipEvents() throws IOException {
   final SerializationService serializationService = getSerializationService();
   while (!Thread.currentThread().isInterrupted()) {
     final Data eventData = conn.read();
     final ClientMembershipEvent event =
         (ClientMembershipEvent) serializationService.toObject(eventData);
     final MemberImpl member = (MemberImpl) event.getMember();
     if (event.getEventType() == MembershipEvent.MEMBER_ADDED) {
       members.add(member);
     } else {
       members.remove(member);
       getConnectionManager().removeConnectionPool(member.getAddress());
     }
     updateMembersRef();
     logger.info(membersString());
     fireMembershipEvent(
         new MembershipEvent(
             client.getCluster(),
             member,
             event.getEventType(),
             Collections.unmodifiableSet(new LinkedHashSet<Member>(members))));
   }
 }
  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))));
      }
    }
  }