Program: 116433
Project: 116433
Buggy source:
private void addEventListeners(){
  topologyEventReceiver.addEventListener(new CompleteTopologyEventListener(){
    @Override protected void onEvent(    Event event){
      if (!topologyInitialized) {
        log.info("String_Node_Str" + event.getClass());
        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(ClusterStatus.Active);
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterCreatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterCreatedEvent clusterCreatedEvent=(ClusterCreatedEvent)event;
      String clusterId=clusterCreatedEvent.getClusterId();
      AbstractClusterMonitor clusterMonitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterId);
      clusterMonitor.setStatus(ClusterStatus.Created);
    }
  }
);
  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);
      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 appId=clusterTerminatingEvent.getAppId();
      String clusterId=clusterTerminatingEvent.getClusterId();
      AbstractClusterMonitor clusterMonitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterId);
      clusterMonitor.setStatus(ClusterStatus.Terminating);
    }
  }
);
  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);
      clusterMonitor.setStatus(ClusterStatus.Terminated);
    }
  }
);
  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(GroupStatus.Active);
    }
  }
);
  topologyEventReceiver.addEventListener(new GroupInActivateEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      GroupInactivateEvent groupInactivateEvent=(GroupInactivateEvent)event;
      String appId=groupInactivateEvent.getAppId();
      String groupId=groupInactivateEvent.getGroupId();
      ApplicationMonitor appMonitor=AutoscalerContext.getInstance().getAppMonitor(appId);
      GroupMonitor monitor=(GroupMonitor)appMonitor.findGroupMonitorWithId(groupId);
      monitor.setStatus(GroupStatus.Inactive);
    }
  }
);
  topologyEventReceiver.addEventListener(new GroupTerminatingEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      GroupTerminatingEvent groupTerminatingEvent=(GroupTerminatingEvent)event;
      String appId=groupTerminatingEvent.getAppId();
      String groupId=groupTerminatingEvent.getGroupId();
      ApplicationMonitor appMonitor=AutoscalerContext.getInstance().getAppMonitor(appId);
      GroupMonitor monitor=(GroupMonitor)appMonitor.findGroupMonitorWithId(groupId);
      monitor.setStatus(GroupStatus.Terminating);
    }
  }
);
  topologyEventReceiver.addEventListener(new GroupTerminatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      GroupTerminatedEvent groupTerminatedEvent=(GroupTerminatedEvent)event;
      String appId=groupTerminatedEvent.getAppId();
      String groupId=groupTerminatedEvent.getGroupId();
      ApplicationMonitor appMonitor=AutoscalerContext.getInstance().getAppMonitor(appId);
      GroupMonitor monitor=(GroupMonitor)appMonitor.findGroupMonitorWithId(groupId);
      monitor.setStatus(GroupStatus.Terminated);
    }
  }
);
  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(ApplicationStatus.Active);
    }
  }
);
  topologyEventReceiver.addEventListener(new ApplicationUndeployedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ApplicationUndeployedEvent applicationUndeployedEvent=(ApplicationUndeployedEvent)event;
      TopologyManager.acquireReadLockForApplication(applicationUndeployedEvent.getApplicationId());
      Set<ClusterDataHolder> clusterDataHolders=applicationUndeployedEvent.getClusterData();
      if (clusterDataHolders != null) {
        for (        ClusterDataHolder clusterData : clusterDataHolders) {
          TopologyManager.acquireReadLockForCluster(clusterData.getServiceType(),clusterData.getClusterId());
        }
      }
      try {
        ApplicationMonitor appMonitor=AutoscalerContext.getInstance().getAppMonitor(applicationUndeployedEvent.getApplicationId());
        if (appMonitor != null) {
          appMonitor.setStatus(ApplicationStatus.Terminating);
          for (          ClusterDataHolder clusterData : clusterDataHolders) {
            ClusterMonitor clusterMonitor=((ClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterData.getClusterId()));
            if (clusterMonitor != null) {
              clusterMonitor.setDestroyed(true);
              clusterMonitor.terminateAllMembers();
              clusterMonitor.setStatus(ClusterStatus.Terminating);
            }
 else {
              log.warn("String_Node_Str" + clusterData.getClusterId());
            }
          }
        }
 else {
          log.warn("String_Node_Str" + applicationUndeployedEvent.getApplicationId());
        }
      }
  finally {
        if (clusterDataHolders != null) {
          for (          ClusterDataHolder clusterData : clusterDataHolders) {
            TopologyManager.releaseReadLockForCluster(clusterData.getServiceType(),clusterData.getClusterId());
          }
        }
        TopologyManager.releaseReadLockForApplication(applicationUndeployedEvent.getApplicationId());
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ApplicationTerminatingEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ApplicationTerminatingEvent appTerminatingEvent=(ApplicationTerminatingEvent)event;
      TopologyManager.acquireReadLockForApplication(appTerminatingEvent.getAppId());
      try {
        ApplicationMonitor appMonitor=AutoscalerContext.getInstance().getAppMonitor(appTerminatingEvent.getAppId());
        if (appMonitor != null) {
          appMonitor.setStatus(ApplicationStatus.Terminating);
        }
 else {
          log.warn("String_Node_Str" + appTerminatingEvent.getAppId());
        }
      }
  finally {
        TopologyManager.releaseReadLockForApplication(appTerminatingEvent.getAppId());
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ApplicationTerminatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ApplicationTerminatedEvent applicationRemovedEvent=(ApplicationTerminatedEvent)event;
      Set<ClusterDataHolder> clusterDataHolders=applicationRemovedEvent.getClusterData();
      try {
        ApplicationMonitor monitor=AutoscalerContext.getInstance().getAppMonitor(applicationRemovedEvent.getAppId());
        if (monitor != null) {
          for (          ClusterDataHolder clusterData : clusterDataHolders) {
            ((ClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterData.getClusterId())).setDestroyed(true);
            AutoscalerContext.getInstance().removeMonitor(clusterData.getClusterId());
          }
          AutoscalerContext.getInstance().removeAppMonitor(applicationRemovedEvent.getAppId());
        }
 else {
          log.warn("String_Node_Str" + applicationRemovedEvent.getAppId());
        }
      }
  finally {
      }
    }
  }
);
  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());
        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(ClusterStatus.Active);
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterCreatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterCreatedEvent clusterCreatedEvent=(ClusterCreatedEvent)event;
      String clusterId=clusterCreatedEvent.getClusterId();
      AbstractClusterMonitor clusterMonitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterId);
      clusterMonitor.setStatus(ClusterStatus.Created);
    }
  }
);
  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);
      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 appId=clusterTerminatingEvent.getAppId();
      String clusterId=clusterTerminatingEvent.getClusterId();
      AbstractClusterMonitor clusterMonitor=(AbstractClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterId);
      if (clusterMonitor != null) {
        clusterMonitor.setDestroyed(true);
        clusterMonitor.terminateAllMembers();
        clusterMonitor.setStatus(ClusterStatus.Terminating);
      }
 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);
      clusterMonitor.setStatus(ClusterStatus.Terminated);
    }
  }
);
  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);
      if (monitor != null) {
        monitor.setStatus(GroupStatus.Active);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new GroupInActivateEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      GroupInactivateEvent groupInactivateEvent=(GroupInactivateEvent)event;
      String appId=groupInactivateEvent.getAppId();
      String groupId=groupInactivateEvent.getGroupId();
      ApplicationMonitor appMonitor=AutoscalerContext.getInstance().getAppMonitor(appId);
      GroupMonitor monitor=(GroupMonitor)appMonitor.findGroupMonitorWithId(groupId);
      monitor.setStatus(GroupStatus.Inactive);
    }
  }
);
  topologyEventReceiver.addEventListener(new GroupTerminatingEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      GroupTerminatingEvent groupTerminatingEvent=(GroupTerminatingEvent)event;
      String appId=groupTerminatingEvent.getAppId();
      String groupId=groupTerminatingEvent.getGroupId();
      ApplicationMonitor appMonitor=AutoscalerContext.getInstance().getAppMonitor(appId);
      GroupMonitor monitor=(GroupMonitor)appMonitor.findGroupMonitorWithId(groupId);
      monitor.setStatus(GroupStatus.Terminating);
    }
  }
);
  topologyEventReceiver.addEventListener(new GroupTerminatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      GroupTerminatedEvent groupTerminatedEvent=(GroupTerminatedEvent)event;
      String appId=groupTerminatedEvent.getAppId();
      String groupId=groupTerminatedEvent.getGroupId();
      ApplicationMonitor appMonitor=AutoscalerContext.getInstance().getAppMonitor(appId);
      GroupMonitor monitor=(GroupMonitor)appMonitor.findGroupMonitorWithId(groupId);
      monitor.setStatus(GroupStatus.Terminated);
    }
  }
);
  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(ApplicationStatus.Active);
    }
  }
);
  topologyEventReceiver.addEventListener(new ApplicationUndeployedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ApplicationUndeployedEvent applicationUndeployedEvent=(ApplicationUndeployedEvent)event;
      TopologyManager.acquireReadLockForApplication(applicationUndeployedEvent.getApplicationId());
      Set<ClusterDataHolder> clusterDataHolders=applicationUndeployedEvent.getClusterData();
      if (clusterDataHolders != null) {
        for (        ClusterDataHolder clusterData : clusterDataHolders) {
          TopologyManager.acquireReadLockForCluster(clusterData.getServiceType(),clusterData.getClusterId());
        }
      }
      try {
        ApplicationMonitor appMonitor=AutoscalerContext.getInstance().getAppMonitor(applicationUndeployedEvent.getApplicationId());
        if (appMonitor != null) {
          appMonitor.setStatus(ApplicationStatus.Terminating);
          for (          ClusterDataHolder clusterData : clusterDataHolders) {
            ClusterMonitor clusterMonitor=((ClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterData.getClusterId()));
            if (clusterMonitor != null) {
              clusterMonitor.setDestroyed(true);
              clusterMonitor.terminateAllMembers();
              clusterMonitor.setStatus(ClusterStatus.Terminating);
            }
 else {
              log.warn("String_Node_Str" + clusterData.getClusterId());
            }
          }
        }
 else {
          log.warn("String_Node_Str" + applicationUndeployedEvent.getApplicationId());
        }
      }
  finally {
        if (clusterDataHolders != null) {
          for (          ClusterDataHolder clusterData : clusterDataHolders) {
            TopologyManager.releaseReadLockForCluster(clusterData.getServiceType(),clusterData.getClusterId());
          }
        }
        TopologyManager.releaseReadLockForApplication(applicationUndeployedEvent.getApplicationId());
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ApplicationTerminatingEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ApplicationTerminatingEvent appTerminatingEvent=(ApplicationTerminatingEvent)event;
      TopologyManager.acquireReadLockForApplication(appTerminatingEvent.getAppId());
      try {
        ApplicationMonitor appMonitor=AutoscalerContext.getInstance().getAppMonitor(appTerminatingEvent.getAppId());
        if (appMonitor != null) {
          appMonitor.setStatus(ApplicationStatus.Terminating);
        }
 else {
          log.warn("String_Node_Str" + appTerminatingEvent.getAppId());
        }
      }
  finally {
        TopologyManager.releaseReadLockForApplication(appTerminatingEvent.getAppId());
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ApplicationTerminatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ApplicationTerminatedEvent applicationRemovedEvent=(ApplicationTerminatedEvent)event;
      Set<ClusterDataHolder> clusterDataHolders=applicationRemovedEvent.getClusterData();
      try {
        ApplicationMonitor monitor=AutoscalerContext.getInstance().getAppMonitor(applicationRemovedEvent.getAppId());
        if (monitor != null) {
          for (          ClusterDataHolder clusterData : clusterDataHolders) {
            ((ClusterMonitor)AutoscalerContext.getInstance().getMonitor(clusterData.getClusterId())).setDestroyed(true);
            AutoscalerContext.getInstance().removeMonitor(clusterData.getClusterId());
          }
          AutoscalerContext.getInstance().removeAppMonitor(applicationRemovedEvent.getAppId());
        }
 else {
          log.warn("String_Node_Str" + applicationRemovedEvent.getAppId());
        }
      }
  finally {
      }
    }
  }
);
  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());
      }
    }
  }
);
}