Program: 116169
Project: 116169
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 (AutoscalerUtil.allClustersInitialized(application)) {
                DeploymentPolicy policy=PolicyManager.getInstance().getDeploymentPolicyByApplication(application.getUniqueIdentifier());
                if (policy != null) {
                  AutoscalerUtil.getInstance().startApplicationMonitor(application.getUniqueIdentifier());
                }
 else {
                  log.info("String_Node_Str" + "String_Node_Str" + 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();
          DeploymentPolicy policy=PolicyManager.getInstance().getDeploymentPolicyByApplication(appId);
          if (policy != null && !AutoscalerContext.getInstance().containsPendingMonitor(appId)) {
            AutoscalerUtil.getInstance().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 ClusterInstanceActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterInstanceActivatedEvent clusterActivatedEvent=(ClusterInstanceActivatedEvent)event;
      String clusterId=clusterActivatedEvent.getClusterId();
      String instanceId=clusterActivatedEvent.getInstanceId();
      AutoscalerContext asCtx=AutoscalerContext.getInstance();
      AbstractClusterMonitor monitor;
      monitor=asCtx.getClusterMonitor(clusterId);
      if (null == monitor) {
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
        }
        return;
      }
      monitor.notifyParentMonitor(ClusterStatus.Active,instanceId);
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterResetEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterResetEvent clusterResetEvent=(ClusterResetEvent)event;
      String clusterId=clusterResetEvent.getClusterId();
      String instanceId=clusterResetEvent.getInstanceId();
      AutoscalerContext asCtx=AutoscalerContext.getInstance();
      AbstractClusterMonitor monitor;
      monitor=asCtx.getClusterMonitor(clusterId);
      if (null == monitor) {
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
        }
        return;
      }
      monitor.destroy();
      monitor.notifyParentMonitor(ClusterStatus.Created,instanceId);
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterCreatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterInstanceInActivateEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterInstanceInactivateEvent clusterInactivateEvent=(ClusterInstanceInactivateEvent)event;
      String clusterId=clusterInactivateEvent.getClusterId();
      String instanceId=clusterInactivateEvent.getInstanceId();
      AutoscalerContext asCtx=AutoscalerContext.getInstance();
      AbstractClusterMonitor monitor;
      monitor=asCtx.getClusterMonitor(clusterId);
      if (null == monitor) {
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
        }
        return;
      }
      monitor.notifyParentMonitor(ClusterStatus.Inactive,instanceId);
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterInstanceTerminatingEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterInstanceTerminatingEvent clusterTerminatingEvent=(ClusterInstanceTerminatingEvent)event;
      String clusterId=clusterTerminatingEvent.getClusterId();
      String instanceId=clusterTerminatingEvent.getInstanceId();
      AutoscalerContext asCtx=AutoscalerContext.getInstance();
      AbstractClusterMonitor monitor;
      monitor=asCtx.getClusterMonitor(clusterId);
      if (null == monitor) {
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
        }
        ClusterStatusEventPublisher.sendClusterTerminatedEvent(clusterTerminatingEvent.getAppId(),clusterTerminatingEvent.getServiceName(),clusterId,instanceId);
        return;
      }
      ClusterInstance clusterInstance=(ClusterInstance)monitor.getInstance(instanceId);
      if (clusterInstance.getCurrentState() == ClusterStatus.Active) {
        monitor.notifyParentMonitor(ClusterStatus.Terminating,instanceId);
        InstanceNotificationPublisher.sendInstanceCleanupEventForCluster(clusterId,instanceId);
      }
 else {
        monitor.notifyParentMonitor(ClusterStatus.Terminating,instanceId);
        monitor.terminateAllMembers(instanceId,clusterInstance.getNetworkPartitionId());
      }
      ServiceReferenceHolder.getInstance().getClusterStatusProcessorChain().process("String_Node_Str",clusterId,instanceId);
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterInstanceTerminatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterInstanceTerminatedEvent clusterTerminatedEvent=(ClusterInstanceTerminatedEvent)event;
      String clusterId=clusterTerminatedEvent.getClusterId();
      String instanceId=clusterTerminatedEvent.getInstanceId();
      AutoscalerContext asCtx=AutoscalerContext.getInstance();
      AbstractClusterMonitor monitor;
      ApplicationMonitor appMonitor=null;
      monitor=asCtx.getClusterMonitor(clusterId);
      if (null == monitor) {
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
        }
        appMonitor=AutoscalerContext.getInstance().getAppMonitor(clusterTerminatedEvent.getAppId());
        if (appMonitor != null) {
          appMonitor.onChildStatusEvent(new ClusterStatusEvent(ClusterStatus.Terminated,clusterId,instanceId));
        }
        return;
      }
      monitor.notifyParentMonitor(ClusterStatus.Terminated,instanceId);
      monitor.removeInstance(instanceId);
      if (!monitor.hasInstance() && appMonitor.isTerminating()) {
        monitor.destroy();
        AutoscalerContext.getInstance().removeClusterMonitor(clusterId);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberReadyToShutdownEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        MemberReadyToShutdownEvent memberReadyToShutdownEvent=(MemberReadyToShutdownEvent)event;
        String clusterId=memberReadyToShutdownEvent.getClusterId();
        AutoscalerContext asCtx=AutoscalerContext.getInstance();
        AbstractClusterMonitor monitor;
        monitor=asCtx.getClusterMonitor(clusterId);
        if (null == monitor) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
          }
          return;
        }
        monitor.handleMemberReadyToShutdownEvent(memberReadyToShutdownEvent);
      }
 catch (      Exception e) {
        String msg="String_Node_Str" + e.getLocalizedMessage();
        log.error(msg,e);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberStartedEventListener(){
    @Override protected void onEvent(    Event event){
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberTerminatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        MemberTerminatedEvent memberTerminatedEvent=(MemberTerminatedEvent)event;
        String clusterId=memberTerminatedEvent.getClusterId();
        AbstractClusterMonitor monitor;
        AutoscalerContext asCtx=AutoscalerContext.getInstance();
        monitor=asCtx.getClusterMonitor(clusterId);
        if (null == monitor) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
          }
          return;
        }
        monitor.handleMemberTerminatedEvent(memberTerminatedEvent);
      }
 catch (      Exception e) {
        String msg="String_Node_Str" + e.getLocalizedMessage();
        log.error(msg,e);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        MemberActivatedEvent memberActivatedEvent=(MemberActivatedEvent)event;
        String clusterId=memberActivatedEvent.getClusterId();
        AbstractClusterMonitor monitor;
        AutoscalerContext asCtx=AutoscalerContext.getInstance();
        monitor=asCtx.getClusterMonitor(clusterId);
        if (null == monitor) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
          }
          return;
        }
        monitor.handleMemberActivatedEvent(memberActivatedEvent);
      }
 catch (      Exception e) {
        String msg="String_Node_Str" + e.getLocalizedMessage();
        log.error(msg,e);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberMaintenanceListener(){
    @Override protected void onEvent(    Event event){
      try {
        MemberMaintenanceModeEvent maintenanceModeEvent=(MemberMaintenanceModeEvent)event;
        String clusterId=maintenanceModeEvent.getClusterId();
        AbstractClusterMonitor monitor;
        AutoscalerContext asCtx=AutoscalerContext.getInstance();
        monitor=asCtx.getClusterMonitor(clusterId);
        if (null == monitor) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
          }
          return;
        }
        monitor.handleMemberMaintenanceModeEvent(maintenanceModeEvent);
      }
 catch (      Exception e) {
        String msg="String_Node_Str" + e.getLocalizedMessage();
        log.error(msg,e);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterInstanceCreatedEventListener(){
    @Override protected void onEvent(    Event event){
      ClusterInstanceCreatedEvent clusterInstanceCreatedEvent=(ClusterInstanceCreatedEvent)event;
      AbstractClusterMonitor clusterMonitor=AutoscalerContext.getInstance().getClusterMonitor(clusterInstanceCreatedEvent.getClusterId());
      String instanceId=((ClusterInstanceCreatedEvent)event).getInstanceId();
      if (clusterMonitor != null) {
        TopologyManager.acquireReadLockForCluster(clusterInstanceCreatedEvent.getServiceName(),clusterInstanceCreatedEvent.getClusterId());
        try {
          Service service=TopologyManager.getTopology().getService(clusterInstanceCreatedEvent.getServiceName());
          if (service != null) {
            Cluster cluster=service.getCluster(clusterInstanceCreatedEvent.getClusterId());
            if (cluster != null) {
              try {
                if (cluster.isKubernetesCluster()) {
                  clusterMonitor.setClusterContext(ClusterContextFactory.getKubernetesClusterContext(instanceId,cluster));
                }
 else {
                  VMClusterContext clusterContext=(VMClusterContext)clusterMonitor.getClusterContext();
                  if (clusterContext == null) {
                    clusterContext=ClusterContextFactory.getVMClusterContext(instanceId,cluster);
                    clusterMonitor.setClusterContext(clusterContext);
                  }
                  clusterContext.addInstanceContext(instanceId,cluster);
                  if (clusterMonitor.getInstance(instanceId) == null) {
                    ClusterInstance clusterInstance=cluster.getInstanceContexts(instanceId);
                    ClusterInstance instance=new ClusterInstance(clusterInstance.getAlias(),cluster.getClusterId(),clusterInstance.getInstanceId());
                    instance.setParentId(clusterInstance.getParentId());
                    instance.setNetworkPartitionId(clusterInstance.getNetworkPartitionId());
                    instance.setPartitionId(clusterInstance.getPartitionId());
                    instance.setStatus(clusterInstance.getStatus());
                    clusterMonitor.addInstance(instance);
                  }
                }
                if (clusterMonitor.hasMonitoringStarted().compareAndSet(false,true)) {
                  clusterMonitor.startScheduler();
                  log.info("String_Node_Str" + clusterInstanceCreatedEvent.getClusterId() + "String_Node_Str");
                }
              }
 catch (              PolicyValidationException e) {
                log.error(e.getMessage(),e);
              }
catch (              PartitionValidationException e) {
                log.error(e.getMessage(),e);
              }
            }
          }
 else {
            log.error("String_Node_Str" + clusterInstanceCreatedEvent.getServiceName() + "String_Node_Str"+ clusterInstanceCreatedEvent.getClusterId());
          }
        }
  finally {
          TopologyManager.releaseReadLockForCluster(clusterInstanceCreatedEvent.getServiceName(),clusterInstanceCreatedEvent.getClusterId());
        }
      }
 else {
        log.error("String_Node_Str" + clusterInstanceCreatedEvent.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 (AutoscalerUtil.allClustersInitialized(application)) {
                DeploymentPolicy policy=PolicyManager.getInstance().getDeploymentPolicyByApplication(application.getUniqueIdentifier());
                if (policy != null) {
                  AutoscalerUtil.getInstance().startApplicationMonitor(application.getUniqueIdentifier());
                }
 else {
                  log.info("String_Node_Str" + "String_Node_Str" + 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();
          DeploymentPolicy policy=PolicyManager.getInstance().getDeploymentPolicyByApplication(appId);
          if (policy != null && !AutoscalerContext.getInstance().containsPendingMonitor(appId)) {
            AutoscalerUtil.getInstance().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 ClusterInstanceActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterInstanceActivatedEvent clusterActivatedEvent=(ClusterInstanceActivatedEvent)event;
      String clusterId=clusterActivatedEvent.getClusterId();
      String instanceId=clusterActivatedEvent.getInstanceId();
      AutoscalerContext asCtx=AutoscalerContext.getInstance();
      AbstractClusterMonitor monitor;
      monitor=asCtx.getClusterMonitor(clusterId);
      if (null == monitor) {
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
        }
        return;
      }
      monitor.notifyParentMonitor(ClusterStatus.Active,instanceId);
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterResetEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterResetEvent clusterResetEvent=(ClusterResetEvent)event;
      String clusterId=clusterResetEvent.getClusterId();
      String instanceId=clusterResetEvent.getInstanceId();
      AutoscalerContext asCtx=AutoscalerContext.getInstance();
      AbstractClusterMonitor monitor;
      monitor=asCtx.getClusterMonitor(clusterId);
      if (null == monitor) {
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
        }
        return;
      }
      monitor.destroy();
      monitor.notifyParentMonitor(ClusterStatus.Created,instanceId);
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterCreatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterInstanceInActivateEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterInstanceInactivateEvent clusterInactivateEvent=(ClusterInstanceInactivateEvent)event;
      String clusterId=clusterInactivateEvent.getClusterId();
      String instanceId=clusterInactivateEvent.getInstanceId();
      AutoscalerContext asCtx=AutoscalerContext.getInstance();
      AbstractClusterMonitor monitor;
      monitor=asCtx.getClusterMonitor(clusterId);
      if (null == monitor) {
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
        }
        return;
      }
      monitor.notifyParentMonitor(ClusterStatus.Inactive,instanceId);
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterInstanceTerminatingEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterInstanceTerminatingEvent clusterTerminatingEvent=(ClusterInstanceTerminatingEvent)event;
      String clusterId=clusterTerminatingEvent.getClusterId();
      String instanceId=clusterTerminatingEvent.getInstanceId();
      AutoscalerContext asCtx=AutoscalerContext.getInstance();
      AbstractClusterMonitor monitor;
      monitor=asCtx.getClusterMonitor(clusterId);
      if (null == monitor) {
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
        }
        ClusterStatusEventPublisher.sendClusterTerminatedEvent(clusterTerminatingEvent.getAppId(),clusterTerminatingEvent.getServiceName(),clusterId,instanceId);
        return;
      }
      ClusterInstance clusterInstance=(ClusterInstance)monitor.getInstance(instanceId);
      if (clusterInstance.getCurrentState() == ClusterStatus.Active) {
        monitor.notifyParentMonitor(ClusterStatus.Terminating,instanceId);
        InstanceNotificationPublisher.sendInstanceCleanupEventForCluster(clusterId,instanceId);
      }
 else {
        monitor.notifyParentMonitor(ClusterStatus.Terminating,instanceId);
        monitor.terminateAllMembers(instanceId,clusterInstance.getNetworkPartitionId());
      }
      ServiceReferenceHolder.getInstance().getClusterStatusProcessorChain().process("String_Node_Str",clusterId,instanceId);
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterInstanceTerminatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterInstanceTerminatedEvent clusterTerminatedEvent=(ClusterInstanceTerminatedEvent)event;
      String clusterId=clusterTerminatedEvent.getClusterId();
      String instanceId=clusterTerminatedEvent.getInstanceId();
      AutoscalerContext asCtx=AutoscalerContext.getInstance();
      AbstractClusterMonitor monitor;
      ApplicationMonitor appMonitor=null;
      monitor=asCtx.getClusterMonitor(clusterId);
      if (null == monitor) {
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
        }
        appMonitor=AutoscalerContext.getInstance().getAppMonitor(clusterTerminatedEvent.getAppId());
        if (appMonitor != null) {
          appMonitor.onChildStatusEvent(new ClusterStatusEvent(ClusterStatus.Terminated,clusterId,instanceId));
        }
        return;
      }
      monitor.notifyParentMonitor(ClusterStatus.Terminated,instanceId);
      monitor.removeInstance(instanceId);
      if (!monitor.hasInstance() && appMonitor.isTerminating()) {
        monitor.destroy();
        AutoscalerContext.getInstance().removeClusterMonitor(clusterId);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberReadyToShutdownEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        MemberReadyToShutdownEvent memberReadyToShutdownEvent=(MemberReadyToShutdownEvent)event;
        String clusterId=memberReadyToShutdownEvent.getClusterId();
        AutoscalerContext asCtx=AutoscalerContext.getInstance();
        AbstractClusterMonitor monitor;
        monitor=asCtx.getClusterMonitor(clusterId);
        if (null == monitor) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
          }
          return;
        }
        monitor.handleMemberReadyToShutdownEvent(memberReadyToShutdownEvent);
      }
 catch (      Exception e) {
        String msg="String_Node_Str" + e.getLocalizedMessage();
        log.error(msg,e);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberStartedEventListener(){
    @Override protected void onEvent(    Event event){
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberTerminatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        MemberTerminatedEvent memberTerminatedEvent=(MemberTerminatedEvent)event;
        String clusterId=memberTerminatedEvent.getClusterId();
        AbstractClusterMonitor monitor;
        AutoscalerContext asCtx=AutoscalerContext.getInstance();
        monitor=asCtx.getClusterMonitor(clusterId);
        if (null == monitor) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
          }
          return;
        }
        monitor.handleMemberTerminatedEvent(memberTerminatedEvent);
      }
 catch (      Exception e) {
        String msg="String_Node_Str" + e.getLocalizedMessage();
        log.error(msg,e);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        MemberActivatedEvent memberActivatedEvent=(MemberActivatedEvent)event;
        String clusterId=memberActivatedEvent.getClusterId();
        AbstractClusterMonitor monitor;
        AutoscalerContext asCtx=AutoscalerContext.getInstance();
        monitor=asCtx.getClusterMonitor(clusterId);
        if (null == monitor) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
          }
          return;
        }
        monitor.handleMemberActivatedEvent(memberActivatedEvent);
      }
 catch (      Exception e) {
        String msg="String_Node_Str" + e.getLocalizedMessage();
        log.error(msg,e);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberMaintenanceListener(){
    @Override protected void onEvent(    Event event){
      try {
        MemberMaintenanceModeEvent maintenanceModeEvent=(MemberMaintenanceModeEvent)event;
        String clusterId=maintenanceModeEvent.getClusterId();
        AbstractClusterMonitor monitor;
        AutoscalerContext asCtx=AutoscalerContext.getInstance();
        monitor=asCtx.getClusterMonitor(clusterId);
        if (null == monitor) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
          }
          return;
        }
        monitor.handleMemberMaintenanceModeEvent(maintenanceModeEvent);
      }
 catch (      Exception e) {
        String msg="String_Node_Str" + e.getLocalizedMessage();
        log.error(msg,e);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterInstanceCreatedEventListener(){
    @Override protected void onEvent(    Event event){
      ClusterInstanceCreatedEvent clusterInstanceCreatedEvent=(ClusterInstanceCreatedEvent)event;
      AbstractClusterMonitor clusterMonitor=AutoscalerContext.getInstance().getClusterMonitor(clusterInstanceCreatedEvent.getClusterId());
      ClusterInstance clusterInstance=((ClusterInstanceCreatedEvent)event).getClusterInstance();
      String instanceId=clusterInstance.getInstanceId();
      if (clusterMonitor != null) {
        TopologyManager.acquireReadLockForCluster(clusterInstanceCreatedEvent.getServiceName(),clusterInstanceCreatedEvent.getClusterId());
        try {
          Service service=TopologyManager.getTopology().getService(clusterInstanceCreatedEvent.getServiceName());
          if (service != null) {
            Cluster cluster=service.getCluster(clusterInstanceCreatedEvent.getClusterId());
            if (cluster != null) {
              try {
                if (cluster.isKubernetesCluster()) {
                  clusterMonitor.setClusterContext(ClusterContextFactory.getKubernetesClusterContext(instanceId,cluster));
                }
 else {
                  VMClusterContext clusterContext=(VMClusterContext)clusterMonitor.getClusterContext();
                  if (clusterContext == null) {
                    clusterContext=ClusterContextFactory.getVMClusterContext(instanceId,cluster);
                    clusterMonitor.setClusterContext(clusterContext);
                  }
                  clusterContext.addInstanceContext(instanceId,cluster);
                  if (clusterMonitor.getInstance(instanceId) == null) {
                    ClusterInstance clusterInstance1=cluster.getInstanceContexts(instanceId);
                    clusterMonitor.addInstance(clusterInstance1);
                  }
                }
                if (clusterMonitor.hasMonitoringStarted().compareAndSet(false,true)) {
                  clusterMonitor.startScheduler();
                  log.info("String_Node_Str" + clusterInstanceCreatedEvent.getClusterId() + "String_Node_Str");
                }
              }
 catch (              PolicyValidationException e) {
                log.error(e.getMessage(),e);
              }
catch (              PartitionValidationException e) {
                log.error(e.getMessage(),e);
              }
            }
          }
 else {
            log.error("String_Node_Str" + clusterInstanceCreatedEvent.getServiceName() + "String_Node_Str"+ clusterInstanceCreatedEvent.getClusterId());
          }
        }
  finally {
          TopologyManager.releaseReadLockForCluster(clusterInstanceCreatedEvent.getServiceName(),clusterInstanceCreatedEvent.getClusterId());
        }
      }
 else {
        log.error("String_Node_Str" + clusterInstanceCreatedEvent.getClusterId());
      }
    }
  }
);
}