Program: 116379
Project: 116379
Buggy source:
private void addEventListeners(){
  topologyEventReceiver.addEventListener(new CompleteTopologyEventListener(){
    @Override protected void onEvent(    Event event){
      if (!topologyInitialized) {
        log.info("String_Node_Str" + event.getClass());
        ApplicationHolder.acquireReadLock();
        try {
          Applications applications=ApplicationHolder.getApplications();
          if (applications != null) {
            for (            Application application : applications.getApplications().values()) {
              if (allClustersInitialized(application)) {
                startApplicationMonitor(application.getUniqueIdentifier());
              }
 else {
                log.error("String_Node_Str" + "String_Node_Str");
              }
            }
            topologyInitialized=true;
          }
 else {
            log.info("String_Node_Str");
          }
        }
 catch (        Exception e) {
          log.error("String_Node_Str",e);
        }
 finally {
          ApplicationHolder.releaseReadLock();
        }
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ApplicationClustersCreatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        log.info("String_Node_Str" + event.getClass());
        ApplicationClustersCreatedEvent applicationClustersCreatedEvent=(ApplicationClustersCreatedEvent)event;
        String appId=applicationClustersCreatedEvent.getAppId();
        try {
          ApplicationHolder.acquireReadLock();
          startApplicationMonitor(appId);
        }
 catch (        Exception e) {
          String msg="String_Node_Str" + e.getLocalizedMessage();
          log.error(msg,e);
        }
 finally {
          ApplicationHolder.releaseReadLock();
        }
      }
 catch (      ClassCastException e) {
        String msg="String_Node_Str" + e.getLocalizedMessage();
        log.error(msg,e);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterActivatedEvent clusterActivatedEvent=(ClusterActivatedEvent)event;
      String appId=clusterActivatedEvent.getAppId();
      String clusterId=clusterActivatedEvent.getClusterId();
      AbstractClusterMonitor clusterMonitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterId);
      if (clusterMonitor != null) {
        clusterMonitor.setStatus(ClusterStatus.Active);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterResetEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterCreatedEvent clusterCreatedEvent=(ClusterCreatedEvent)event;
      String clusterId=clusterCreatedEvent.getCluster().getClusterId();
      AbstractClusterMonitor clusterMonitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterId);
      clusterMonitor.setStop(true);
      clusterMonitor.setStatus(ClusterStatus.Created);
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterCreatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterCreatedEvent clusterCreatedEvent=(ClusterCreatedEvent)event;
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterInActivateEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterInactivateEvent clusterInactivateEvent=(ClusterInactivateEvent)event;
      String appId=clusterInactivateEvent.getAppId();
      String clusterId=clusterInactivateEvent.getClusterId();
      AbstractClusterMonitor clusterMonitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterId);
      if (clusterMonitor != null) {
        clusterMonitor.setStatus(ClusterStatus.Inactive);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterTerminatingEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterTerminatingEvent clusterTerminatingEvent=(ClusterTerminatingEvent)event;
      String clusterId=clusterTerminatingEvent.getClusterId();
      AbstractClusterMonitor clusterMonitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterId);
      if (clusterMonitor != null) {
        if (clusterMonitor.getStatus() == ClusterStatus.Active) {
          clusterMonitor.setStatus(ClusterStatus.Terminating);
          InstanceNotificationPublisher.sendInstanceCleanupEventForCluster(clusterId);
        }
 else {
          clusterMonitor.setStatus(ClusterStatus.Terminating);
          clusterMonitor.terminateAllMembers();
        }
      }
 else {
        log.warn("String_Node_Str" + clusterId);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterTerminatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterTerminatedEvent clusterTerminatedEvent=(ClusterTerminatedEvent)event;
      String appId=clusterTerminatedEvent.getAppId();
      String clusterId=clusterTerminatedEvent.getClusterId();
      AbstractClusterMonitor clusterMonitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterId);
      if (clusterMonitor != null) {
        clusterMonitor.setStatus(ClusterStatus.Terminated);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ApplicationUndeployedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ApplicationUndeployedEvent applicationUndeployedEvent=(ApplicationUndeployedEvent)event;
      ApplicationMonitor appMonitor=AutoscalerContext.getInstance().getAppMonitor(applicationUndeployedEvent.getApplicationId());
      Set<ClusterDataHolder> clusterDataHolders=applicationUndeployedEvent.getClusterData();
      if (clusterDataHolders != null) {
        for (        ClusterDataHolder clusterDataHolder : clusterDataHolders) {
          ClusterMonitor clusterMonitor=((ClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterDataHolder.getClusterId()));
          if (clusterMonitor == null) {
            ClusterStatusEventPublisher.sendClusterTerminatedEvent(applicationUndeployedEvent.getApplicationId(),clusterDataHolder.getServiceType(),clusterDataHolder.getClusterId());
          }
 else {
            clusterMonitor.setDestroyed(true);
          }
        }
      }
      if (appMonitor != null) {
        appMonitor.setStatus(ApplicationStatus.Terminating);
      }
 else {
        ApplicationsEventPublisher.sendApplicationTerminatedEvent(applicationUndeployedEvent.getApplicationId(),applicationUndeployedEvent.getClusterData());
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberReadyToShutdownEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        MemberReadyToShutdownEvent memberReadyToShutdownEvent=(MemberReadyToShutdownEvent)event;
        AutoscalerContext asCtx=AutoscalerContext.getInstance();
        AbstractClusterMonitor monitor;
        String clusterId=memberReadyToShutdownEvent.getClusterId();
        String memberId=memberReadyToShutdownEvent.getMemberId();
        if (asCtx.monitorExist(clusterId)) {
          monitor=(AbstractClusterMonitor)asCtx.getMonitor(clusterId);
        }
 else         if (asCtx.lbMonitorExist(clusterId)) {
          monitor=asCtx.getLBMonitor(clusterId);
        }
 else {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
          }
          return;
        }
        NetworkPartitionContext nwPartitionCtxt;
        nwPartitionCtxt=monitor.getNetworkPartitionCtxt(memberReadyToShutdownEvent.getNetworkPartitionId());
        String partitionId=monitor.getPartitionOfMember(memberId);
        PartitionContext partitionCtxt=nwPartitionCtxt.getPartitionCtxt(partitionId);
        CloudControllerClient ccClient=CloudControllerClient.getInstance();
        ccClient.terminate(memberId);
        partitionCtxt.removeActiveMemberById(memberId);
        if (log.isInfoEnabled()) {
          log.info(String.format("String_Node_Str" + "String_Node_Str",memberId,partitionId,clusterId));
        }
      }
 catch (      TerminationException e) {
        log.error(e);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterRemovedEventListener(){
    @Override protected void onEvent(    Event event){
      ClusterRemovedEvent clusterRemovedEvent=null;
      try {
        clusterRemovedEvent=(ClusterRemovedEvent)event;
        TopologyManager.acquireReadLockForCluster(clusterRemovedEvent.getServiceName(),clusterRemovedEvent.getClusterId());
        String clusterId=clusterRemovedEvent.getClusterId();
        String deploymentPolicy=clusterRemovedEvent.getDeploymentPolicy();
        AbstractClusterMonitor monitor;
        if (clusterRemovedEvent.isLbCluster()) {
          DeploymentPolicy depPolicy=PolicyManager.getInstance().getDeploymentPolicy(deploymentPolicy);
          if (depPolicy != null) {
            List<NetworkPartitionLbHolder> lbHolders=PartitionManager.getInstance().getNetworkPartitionLbHolders(depPolicy);
            for (            NetworkPartitionLbHolder networkPartitionLbHolder : lbHolders) {
              boolean isRemoved=networkPartitionLbHolder.removeLbClusterId(clusterId);
              if (isRemoved) {
                log.info("String_Node_Str" + clusterId + "String_Node_Str"+ networkPartitionLbHolder.getNetworkPartitionId());
              }
              if (log.isDebugEnabled()) {
                log.debug(networkPartitionLbHolder);
              }
            }
          }
          monitor=AutoscalerContext.getInstance().removeLbMonitor(clusterId);
        }
 else {
          monitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().removeMonitor(clusterId);
        }
        if (monitor != null) {
          monitor.destroy();
          log.info(String.format("String_Node_Str",clusterId));
        }
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLockForCluster(clusterRemovedEvent.getServiceName(),clusterRemovedEvent.getClusterId());
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberStartedEventListener(){
    @Override protected void onEvent(    Event event){
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberTerminatedEventListener(){
    @Override protected void onEvent(    Event event){
      MemberTerminatedEvent memberTerminatedEvent=null;
      try {
        memberTerminatedEvent=(MemberTerminatedEvent)event;
        String networkPartitionId=memberTerminatedEvent.getNetworkPartitionId();
        String clusterId=memberTerminatedEvent.getClusterId();
        String partitionId=memberTerminatedEvent.getPartitionId();
        AbstractClusterMonitor monitor;
        TopologyManager.acquireReadLockForCluster(memberTerminatedEvent.getServiceName(),memberTerminatedEvent.getClusterId());
        if (AutoscalerContext.getInstance().monitorExist(clusterId)) {
          monitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterId);
        }
 else {
          monitor=AutoscalerContext.getInstance().getLBMonitor(clusterId);
        }
        NetworkPartitionContext networkPartitionContext=monitor.getNetworkPartitionCtxt(networkPartitionId);
        PartitionContext partitionContext=networkPartitionContext.getPartitionCtxt(partitionId);
        String memberId=memberTerminatedEvent.getMemberId();
        partitionContext.removeMemberStatsContext(memberId);
        if (partitionContext.removeTerminationPendingMember(memberId)) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",memberId));
          }
        }
 else         if (partitionContext.removePendingMember(memberId)) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",memberId));
          }
        }
 else         if (partitionContext.removeActiveMemberById(memberId)) {
          log.warn(String.format("String_Node_Str" + "String_Node_Str",memberId));
        }
 else {
          log.warn(String.format("String_Node_Str" + "String_Node_Str",memberId));
        }
        if (log.isInfoEnabled()) {
          log.info(String.format("String_Node_Str" + "String_Node_Str",memberId));
        }
        StatusChecker.getInstance().onMemberTermination(clusterId);
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLockForCluster(memberTerminatedEvent.getServiceName(),memberTerminatedEvent.getClusterId());
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      MemberActivatedEvent memberActivatedEvent=(MemberActivatedEvent)event;
      TopologyManager.acquireReadLockForCluster(memberActivatedEvent.getServiceName(),memberActivatedEvent.getClusterId());
      try {
        String networkPartitionId=memberActivatedEvent.getNetworkPartitionId();
        String clusterId=memberActivatedEvent.getClusterId();
        String partitionId=memberActivatedEvent.getPartitionId();
        String memberId=memberActivatedEvent.getMemberId();
        AbstractClusterMonitor monitor;
        if (AutoscalerContext.getInstance().monitorExist(clusterId)) {
          monitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterId);
        }
 else {
          monitor=AutoscalerContext.getInstance().getLBMonitor(clusterId);
        }
        NetworkPartitionContext networkPartitionContext=monitor.getNetworkPartitionCtxt(networkPartitionId);
        PartitionContext partitionContext=networkPartitionContext.getPartitionCtxt(partitionId);
        partitionContext.addMemberStatsContext(new MemberStatsContext(memberId));
        if (log.isInfoEnabled()) {
          log.info(String.format("String_Node_Str" + "String_Node_Str",memberId));
        }
        partitionContext.movePendingMemberToActiveMembers(memberId);
        StatusChecker.getInstance().onMemberStatusChange(memberActivatedEvent.getClusterId());
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLockForCluster(memberActivatedEvent.getServiceName(),memberActivatedEvent.getClusterId());
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberMaintenanceListener(){
    @Override protected void onEvent(    Event event){
      MemberMaintenanceModeEvent memberMaintenanceModeEvent=(MemberMaintenanceModeEvent)event;
      TopologyManager.acquireReadLockForCluster(memberMaintenanceModeEvent.getServiceName(),memberMaintenanceModeEvent.getClusterId());
      try {
        String memberId=memberMaintenanceModeEvent.getMemberId();
        String partitionId=memberMaintenanceModeEvent.getPartitionId();
        String networkPartitionId=memberMaintenanceModeEvent.getNetworkPartitionId();
        PartitionContext partitionContext;
        String clusterId=memberMaintenanceModeEvent.getClusterId();
        AbstractClusterMonitor monitor;
        if (AutoscalerContext.getInstance().monitorExist(clusterId)) {
          monitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterId);
          partitionContext=monitor.getNetworkPartitionCtxt(networkPartitionId).getPartitionCtxt(partitionId);
        }
 else {
          monitor=AutoscalerContext.getInstance().getLBMonitor(clusterId);
          partitionContext=monitor.getNetworkPartitionCtxt(networkPartitionId).getPartitionCtxt(partitionId);
        }
        partitionContext.addMemberStatsContext(new MemberStatsContext(memberId));
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",memberId));
        }
        partitionContext.moveActiveMemberToTerminationPendingMembers(memberId);
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLockForCluster(memberMaintenanceModeEvent.getServiceName(),memberMaintenanceModeEvent.getClusterId());
      }
    }
  }
);
}

Fixed version (ground truth):
private void addEventListeners(){
  topologyEventReceiver.addEventListener(new CompleteTopologyEventListener(){
    @Override protected void onEvent(    Event event){
      if (!topologyInitialized) {
        log.info("String_Node_Str" + event.getClass());
        ApplicationHolder.acquireReadLock();
        try {
          Applications applications=ApplicationHolder.getApplications();
          if (applications != null) {
            for (            Application application : applications.getApplications().values()) {
              if (allClustersInitialized(application)) {
                startApplicationMonitor(application.getUniqueIdentifier());
              }
 else {
                log.error("String_Node_Str" + "String_Node_Str");
              }
            }
            topologyInitialized=true;
          }
 else {
            log.info("String_Node_Str");
          }
        }
 catch (        Exception e) {
          log.error("String_Node_Str",e);
        }
 finally {
          ApplicationHolder.releaseReadLock();
        }
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ApplicationClustersCreatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        log.info("String_Node_Str" + event.getClass());
        ApplicationClustersCreatedEvent applicationClustersCreatedEvent=(ApplicationClustersCreatedEvent)event;
        String appId=applicationClustersCreatedEvent.getAppId();
        try {
          ApplicationHolder.acquireReadLock();
          startApplicationMonitor(appId);
        }
 catch (        Exception e) {
          String msg="String_Node_Str" + e.getLocalizedMessage();
          log.error(msg,e);
        }
 finally {
          ApplicationHolder.releaseReadLock();
        }
      }
 catch (      ClassCastException e) {
        String msg="String_Node_Str" + e.getLocalizedMessage();
        log.error(msg,e);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterActivatedEvent clusterActivatedEvent=(ClusterActivatedEvent)event;
      String appId=clusterActivatedEvent.getAppId();
      String clusterId=clusterActivatedEvent.getClusterId();
      AbstractClusterMonitor clusterMonitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterId);
      if (clusterMonitor != null) {
        clusterMonitor.setStatus(ClusterStatus.Active);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterResetEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterCreatedEvent clusterCreatedEvent=(ClusterCreatedEvent)event;
      String clusterId=clusterCreatedEvent.getCluster().getClusterId();
      AbstractClusterMonitor clusterMonitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterId);
      clusterMonitor.setStop(true);
      clusterMonitor.setStatus(ClusterStatus.Created);
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterCreatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterCreatedEvent clusterCreatedEvent=(ClusterCreatedEvent)event;
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterInActivateEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterInactivateEvent clusterInactivateEvent=(ClusterInactivateEvent)event;
      String appId=clusterInactivateEvent.getAppId();
      String clusterId=clusterInactivateEvent.getClusterId();
      AbstractClusterMonitor clusterMonitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterId);
      if (clusterMonitor != null) {
        clusterMonitor.setStatus(ClusterStatus.Inactive);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterTerminatingEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterTerminatingEvent clusterTerminatingEvent=(ClusterTerminatingEvent)event;
      String clusterId=clusterTerminatingEvent.getClusterId();
      AbstractClusterMonitor clusterMonitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterId);
      if (clusterMonitor != null) {
        if (clusterMonitor.getStatus() == ClusterStatus.Active) {
          clusterMonitor.setStatus(ClusterStatus.Terminating);
          InstanceNotificationPublisher.sendInstanceCleanupEventForCluster(clusterId);
        }
 else {
          clusterMonitor.setStatus(ClusterStatus.Terminating);
          clusterMonitor.terminateAllMembers();
        }
      }
 else {
        log.warn("String_Node_Str" + clusterId);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterTerminatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterTerminatedEvent clusterTerminatedEvent=(ClusterTerminatedEvent)event;
      String appId=clusterTerminatedEvent.getAppId();
      String clusterId=clusterTerminatedEvent.getClusterId();
      AbstractClusterMonitor clusterMonitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterId);
      if (clusterMonitor != null) {
        clusterMonitor.setStatus(ClusterStatus.Terminated);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberReadyToShutdownEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        MemberReadyToShutdownEvent memberReadyToShutdownEvent=(MemberReadyToShutdownEvent)event;
        AutoscalerContext asCtx=AutoscalerContext.getInstance();
        AbstractClusterMonitor monitor;
        String clusterId=memberReadyToShutdownEvent.getClusterId();
        String memberId=memberReadyToShutdownEvent.getMemberId();
        if (asCtx.monitorExist(clusterId)) {
          monitor=(AbstractClusterMonitor)asCtx.getMonitor(clusterId);
        }
 else         if (asCtx.lbMonitorExist(clusterId)) {
          monitor=asCtx.getLBMonitor(clusterId);
        }
 else {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
          }
          return;
        }
        NetworkPartitionContext nwPartitionCtxt;
        nwPartitionCtxt=monitor.getNetworkPartitionCtxt(memberReadyToShutdownEvent.getNetworkPartitionId());
        String partitionId=monitor.getPartitionOfMember(memberId);
        PartitionContext partitionCtxt=nwPartitionCtxt.getPartitionCtxt(partitionId);
        CloudControllerClient ccClient=CloudControllerClient.getInstance();
        ccClient.terminate(memberId);
        partitionCtxt.removeActiveMemberById(memberId);
        if (log.isInfoEnabled()) {
          log.info(String.format("String_Node_Str" + "String_Node_Str",memberId,partitionId,clusterId));
        }
      }
 catch (      TerminationException e) {
        log.error(e);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterRemovedEventListener(){
    @Override protected void onEvent(    Event event){
      ClusterRemovedEvent clusterRemovedEvent=null;
      try {
        clusterRemovedEvent=(ClusterRemovedEvent)event;
        TopologyManager.acquireReadLockForCluster(clusterRemovedEvent.getServiceName(),clusterRemovedEvent.getClusterId());
        String clusterId=clusterRemovedEvent.getClusterId();
        String deploymentPolicy=clusterRemovedEvent.getDeploymentPolicy();
        AbstractClusterMonitor monitor;
        if (clusterRemovedEvent.isLbCluster()) {
          DeploymentPolicy depPolicy=PolicyManager.getInstance().getDeploymentPolicy(deploymentPolicy);
          if (depPolicy != null) {
            List<NetworkPartitionLbHolder> lbHolders=PartitionManager.getInstance().getNetworkPartitionLbHolders(depPolicy);
            for (            NetworkPartitionLbHolder networkPartitionLbHolder : lbHolders) {
              boolean isRemoved=networkPartitionLbHolder.removeLbClusterId(clusterId);
              if (isRemoved) {
                log.info("String_Node_Str" + clusterId + "String_Node_Str"+ networkPartitionLbHolder.getNetworkPartitionId());
              }
              if (log.isDebugEnabled()) {
                log.debug(networkPartitionLbHolder);
              }
            }
          }
          monitor=AutoscalerContext.getInstance().removeLbMonitor(clusterId);
        }
 else {
          monitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().removeMonitor(clusterId);
        }
        if (monitor != null) {
          monitor.destroy();
          log.info(String.format("String_Node_Str",clusterId));
        }
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLockForCluster(clusterRemovedEvent.getServiceName(),clusterRemovedEvent.getClusterId());
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberStartedEventListener(){
    @Override protected void onEvent(    Event event){
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberTerminatedEventListener(){
    @Override protected void onEvent(    Event event){
      MemberTerminatedEvent memberTerminatedEvent=null;
      try {
        memberTerminatedEvent=(MemberTerminatedEvent)event;
        String networkPartitionId=memberTerminatedEvent.getNetworkPartitionId();
        String clusterId=memberTerminatedEvent.getClusterId();
        String partitionId=memberTerminatedEvent.getPartitionId();
        AbstractClusterMonitor monitor;
        TopologyManager.acquireReadLockForCluster(memberTerminatedEvent.getServiceName(),memberTerminatedEvent.getClusterId());
        if (AutoscalerContext.getInstance().monitorExist(clusterId)) {
          monitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterId);
        }
 else {
          monitor=AutoscalerContext.getInstance().getLBMonitor(clusterId);
        }
        NetworkPartitionContext networkPartitionContext=monitor.getNetworkPartitionCtxt(networkPartitionId);
        PartitionContext partitionContext=networkPartitionContext.getPartitionCtxt(partitionId);
        String memberId=memberTerminatedEvent.getMemberId();
        partitionContext.removeMemberStatsContext(memberId);
        if (partitionContext.removeTerminationPendingMember(memberId)) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",memberId));
          }
        }
 else         if (partitionContext.removePendingMember(memberId)) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",memberId));
          }
        }
 else         if (partitionContext.removeActiveMemberById(memberId)) {
          log.warn(String.format("String_Node_Str" + "String_Node_Str",memberId));
        }
 else {
          log.warn(String.format("String_Node_Str" + "String_Node_Str",memberId));
        }
        if (log.isInfoEnabled()) {
          log.info(String.format("String_Node_Str" + "String_Node_Str",memberId));
        }
        StatusChecker.getInstance().onMemberTermination(clusterId);
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLockForCluster(memberTerminatedEvent.getServiceName(),memberTerminatedEvent.getClusterId());
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      MemberActivatedEvent memberActivatedEvent=(MemberActivatedEvent)event;
      TopologyManager.acquireReadLockForCluster(memberActivatedEvent.getServiceName(),memberActivatedEvent.getClusterId());
      try {
        String networkPartitionId=memberActivatedEvent.getNetworkPartitionId();
        String clusterId=memberActivatedEvent.getClusterId();
        String partitionId=memberActivatedEvent.getPartitionId();
        String memberId=memberActivatedEvent.getMemberId();
        AbstractClusterMonitor monitor;
        if (AutoscalerContext.getInstance().monitorExist(clusterId)) {
          monitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterId);
        }
 else {
          monitor=AutoscalerContext.getInstance().getLBMonitor(clusterId);
        }
        NetworkPartitionContext networkPartitionContext=monitor.getNetworkPartitionCtxt(networkPartitionId);
        PartitionContext partitionContext=networkPartitionContext.getPartitionCtxt(partitionId);
        partitionContext.addMemberStatsContext(new MemberStatsContext(memberId));
        if (log.isInfoEnabled()) {
          log.info(String.format("String_Node_Str" + "String_Node_Str",memberId));
        }
        partitionContext.movePendingMemberToActiveMembers(memberId);
        StatusChecker.getInstance().onMemberStatusChange(memberActivatedEvent.getClusterId());
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLockForCluster(memberActivatedEvent.getServiceName(),memberActivatedEvent.getClusterId());
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberMaintenanceListener(){
    @Override protected void onEvent(    Event event){
      MemberMaintenanceModeEvent memberMaintenanceModeEvent=(MemberMaintenanceModeEvent)event;
      TopologyManager.acquireReadLockForCluster(memberMaintenanceModeEvent.getServiceName(),memberMaintenanceModeEvent.getClusterId());
      try {
        String memberId=memberMaintenanceModeEvent.getMemberId();
        String partitionId=memberMaintenanceModeEvent.getPartitionId();
        String networkPartitionId=memberMaintenanceModeEvent.getNetworkPartitionId();
        PartitionContext partitionContext;
        String clusterId=memberMaintenanceModeEvent.getClusterId();
        AbstractClusterMonitor monitor;
        if (AutoscalerContext.getInstance().monitorExist(clusterId)) {
          monitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterId);
          partitionContext=monitor.getNetworkPartitionCtxt(networkPartitionId).getPartitionCtxt(partitionId);
        }
 else {
          monitor=AutoscalerContext.getInstance().getLBMonitor(clusterId);
          partitionContext=monitor.getNetworkPartitionCtxt(networkPartitionId).getPartitionCtxt(partitionId);
        }
        partitionContext.addMemberStatsContext(new MemberStatsContext(memberId));
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",memberId));
        }
        partitionContext.moveActiveMemberToTerminationPendingMembers(memberId);
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLockForCluster(memberMaintenanceModeEvent.getServiceName(),memberMaintenanceModeEvent.getClusterId());
      }
    }
  }
);
}