@Override
 public void memberRemoved(MembershipEvent membershipEvent) {
   synchronized (listenerRegLock) {
     Member member = membershipEvent.getMember();
     members.remove(member);
     for (Map<Address, ClientEventRegistration> registrationMap : registrations.values()) {
       ClientEventRegistration registration = registrationMap.remove(member.getAddress());
       removeEventHandler(registration.getCallId());
     }
   }
 }
  /**
   * This is triggered when a new member joined to the cluster.
   *
   * @param membershipEvent contains the information about the added node.
   */
  @Override
  public void memberAdded(MembershipEvent membershipEvent) {
    Member member = membershipEvent.getMember();
    log.info(
        "Handling cluster gossip: New member joined to the cluster. Member Socket Address:"
            + member.getSocketAddress()
            + " UUID:"
            + member.getUuid());

    ClusterResourceHolder.getInstance().getClusterManager().memberAdded();
  }
 @Override
 public void memberRemoved(MembershipEvent event) {
   if (this.getHazelcast().getLifecycleService().isRunning()) {
     String id = this.getIdFromMember(event.getMember());
     this.membersMap.remove(id);
     try {
       if (this.isLeader()) {
         log.info(
             "Task ["
                 + this.getTaskType()
                 + "] member departed ["
                 + event.getMember().toString()
                 + "], rescheduling missing tasks...");
         this.scheduleAllMissingTasks();
       }
     } catch (TaskException e) {
       log.error(
           "Error in scheduling missing tasks [" + this.getTaskType() + "]: " + e.getMessage(), e);
     }
   }
 }
 /**
  * This is triggered when a node left the cluster.
  *
  * @param membershipEvent contains the information about the removed node.
  */
 @Override
 public void memberRemoved(MembershipEvent membershipEvent) {
   Member member = membershipEvent.getMember();
   log.info(
       "Handling cluster gossip: A member left the cluster. Member Socket Address:"
           + member.getSocketAddress()
           + " UUID:"
           + member.getUuid());
   ClusterManager clusterManager = ClusterResourceHolder.getInstance().getClusterManager();
   try {
     clusterManager.memberRemoved(member);
   } catch (Exception e) {
     log.error("Error while handling node removal, NodeID:" + clusterManager.getNodeId(member), e);
   }
 }