Program: 116469
Project: 116469
Buggy source:
private void addEventListeners(){
  topologyEventReceiver.addEventListener(new CompleteTopologyEventListener(){
    @Override protected void onEvent(    Event event){
      if (!topologyInitialized) {
        TopologyManager.acquireReadLock();
        try {
          for (          Application application : TopologyManager.getTopology().getApplications()) {
            startApplicationMonitor(application.getUniqueIdentifier());
          }
          topologyInitialized=true;
        }
 catch (        Exception e) {
          log.error("String_Node_Str",e);
        }
 finally {
          TopologyManager.releaseReadLock();
        }
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ApplicationCreatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        log.info("String_Node_Str" + event.getClass());
        ApplicationCreatedEvent applicationCreatedEvent=(ApplicationCreatedEvent)event;
        try {
          TopologyManager.acquireReadLockForApplication(applicationCreatedEvent.getApplication().getUniqueIdentifier());
          startApplicationMonitor(applicationCreatedEvent.getApplication().getUniqueIdentifier());
        }
 catch (        Exception e) {
          String msg="String_Node_Str" + e.getLocalizedMessage();
          log.error(msg,e);
        }
 finally {
          TopologyManager.releaseReadLockForApplication(applicationCreatedEvent.getApplication().getUniqueIdentifier());
        }
      }
 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);
      clusterMonitor.setStatus(Status.Activated);
    }
  }
);
  topologyEventReceiver.addEventListener(new GroupActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      GroupActivatedEvent groupActivatedEvent=(GroupActivatedEvent)event;
      String appId=groupActivatedEvent.getAppId();
      String groupId=groupActivatedEvent.getGroupId();
      ApplicationMonitor appMonitor=AutoscalerContext.getInstance().getAppMonitor(appId);
      GroupMonitor monitor=(GroupMonitor)appMonitor.findGroupMonitorWithId(groupId);
      monitor.setStatus(Status.Activated);
    }
  }
);
  topologyEventReceiver.addEventListener(new ApplicationActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ApplicationActivatedEvent applicationActivatedEvent=(ApplicationActivatedEvent)event;
      String appId=applicationActivatedEvent.getAppId();
      ApplicationMonitor appMonitor=AutoscalerContext.getInstance().getAppMonitor(appId);
      appMonitor.setStatus(Status.Activated);
    }
  }
);
  topologyEventReceiver.addEventListener(new ApplicationRemovedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ApplicationRemovedEvent applicationRemovedEvent=(ApplicationRemovedEvent)event;
      TopologyManager.acquireReadLockForApplication(applicationRemovedEvent.getApplicationId());
      try {
      }
  finally {
        TopologyManager.releaseReadLockForApplication(applicationRemovedEvent.getApplicationId());
      }
    }
  }
);
  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 ClusterMaintenanceModeEventListener(){
    @Override protected void onEvent(    Event event){
      ClusterMaintenanceModeEvent clusterMaitenanceEvent=null;
      try {
        log.info("String_Node_Str" + event);
        clusterMaitenanceEvent=(ClusterMaintenanceModeEvent)event;
        TopologyManager.acquireReadLockForCluster(clusterMaitenanceEvent.getServiceName(),clusterMaitenanceEvent.getClusterId());
        Service service=TopologyManager.getTopology().getService(clusterMaitenanceEvent.getServiceName());
        Cluster cluster=service.getCluster(clusterMaitenanceEvent.getClusterId());
        AbstractClusterMonitor monitor;
        if (AutoscalerContext.getInstance().monitorExist((cluster.getClusterId()))) {
          monitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterMaitenanceEvent.getClusterId());
          monitor.setStatus(Status.In_Active);
        }
 else         if (AutoscalerContext.getInstance().lbMonitorExist((cluster.getClusterId()))) {
          AutoscalerContext.getInstance().getLBMonitor(clusterMaitenanceEvent.getClusterId()).setStatus(clusterMaitenanceEvent.getStatus());
        }
 else {
          log.error("String_Node_Str" + cluster.toString());
        }
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLockForCluster(clusterMaitenanceEvent.getServiceName(),clusterMaitenanceEvent.getClusterId());
      }
    }
  }
);
  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) {
        TopologyManager.acquireReadLock();
        try {
          for (          Application application : TopologyManager.getTopology().getApplications()) {
            startApplicationMonitor(application.getUniqueIdentifier());
          }
          topologyInitialized=true;
        }
 catch (        Exception e) {
          log.error("String_Node_Str",e);
        }
 finally {
          TopologyManager.releaseReadLock();
        }
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ApplicationCreatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        log.info("String_Node_Str" + event.getClass());
        ApplicationCreatedEvent applicationCreatedEvent=(ApplicationCreatedEvent)event;
        try {
          TopologyManager.acquireReadLockForApplication(applicationCreatedEvent.getApplication().getUniqueIdentifier());
          startApplicationMonitor(applicationCreatedEvent.getApplication().getUniqueIdentifier());
        }
 catch (        Exception e) {
          String msg="String_Node_Str" + e.getLocalizedMessage();
          log.error(msg,e);
        }
 finally {
          TopologyManager.releaseReadLockForApplication(applicationCreatedEvent.getApplication().getUniqueIdentifier());
        }
      }
 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);
      clusterMonitor.setStatus(Status.Activated);
    }
  }
);
  topologyEventReceiver.addEventListener(new GroupActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      GroupActivatedEvent groupActivatedEvent=(GroupActivatedEvent)event;
      String appId=groupActivatedEvent.getAppId();
      String groupId=groupActivatedEvent.getGroupId();
      ApplicationMonitor appMonitor=AutoscalerContext.getInstance().getAppMonitor(appId);
      GroupMonitor monitor=(GroupMonitor)appMonitor.findGroupMonitorWithId(groupId);
      monitor.setStatus(Status.Activated);
    }
  }
);
  topologyEventReceiver.addEventListener(new ApplicationActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ApplicationActivatedEvent applicationActivatedEvent=(ApplicationActivatedEvent)event;
      String appId=applicationActivatedEvent.getAppId();
      ApplicationMonitor appMonitor=AutoscalerContext.getInstance().getAppMonitor(appId);
      appMonitor.setStatus(Status.Activated);
    }
  }
);
  topologyEventReceiver.addEventListener(new ApplicationRemovedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ApplicationRemovedEvent applicationRemovedEvent=(ApplicationRemovedEvent)event;
      TopologyManager.acquireReadLockForApplication(applicationRemovedEvent.getApplicationId());
      try {
      }
  finally {
        TopologyManager.releaseReadLockForApplication(applicationRemovedEvent.getApplicationId());
      }
    }
  }
);
  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 ClusterMaintenanceModeEventListener(){
    @Override protected void onEvent(    Event event){
      ClusterMaintenanceModeEvent clusterMaitenanceEvent=null;
      try {
        log.info("String_Node_Str" + event);
        clusterMaitenanceEvent=(ClusterMaintenanceModeEvent)event;
        TopologyManager.acquireReadLockForCluster(clusterMaitenanceEvent.getServiceName(),clusterMaitenanceEvent.getClusterId());
        Service service=TopologyManager.getTopology().getService(clusterMaitenanceEvent.getServiceName());
        Cluster cluster=service.getCluster(clusterMaitenanceEvent.getClusterId());
        AbstractClusterMonitor monitor;
        if (AutoscalerContext.getInstance().monitorExist((cluster.getClusterId()))) {
          monitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterMaitenanceEvent.getClusterId());
          monitor.setStatus(Status.In_Maintenance);
        }
 else         if (AutoscalerContext.getInstance().lbMonitorExist((cluster.getClusterId()))) {
          AutoscalerContext.getInstance().getLBMonitor(clusterMaitenanceEvent.getClusterId()).setStatus(clusterMaitenanceEvent.getStatus());
        }
 else {
          log.error("String_Node_Str" + cluster.toString());
        }
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLockForCluster(clusterMaitenanceEvent.getServiceName(),clusterMaitenanceEvent.getClusterId());
      }
    }
  }
);
  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());
      }
    }
  }
);
}