/** {@inheritDoc} */
  @Override
  public void onApplicationEvent(AgentMappingsUpdateEvent event) {
    Map<Long, AgentCacheEntry> agentCacheMap = nextGenInstrumentationManager.getAgentCacheMap();
    // iterate all caches
    for (AgentCacheEntry agentCacheEntry : agentCacheMap.values()) {
      ConfigurationHolder configurationHolder = agentCacheEntry.getConfigurationHolder();
      Environment cachedEnvironment = configurationHolder.getEnvironment();
      PlatformIdent platformIdent = platformIdentDao.load(agentCacheEntry.getId());
      try {
        // see what 's the new environment for the agent
        Environment environment =
            configurationResolver.getEnvironmentForAgent(
                platformIdent.getDefinedIPs(), platformIdent.getAgentName());

        // fire job only if we have new environment or we were not bounded to any
        // environment
        if ((null == cachedEnvironment)
            || !ObjectUtils.equals(cachedEnvironment.getId(), environment.getId())) {
          EnvironmentMappingUpdateJob mappingUpdateJob = mappingUpdateJobFactory.getObject();
          mappingUpdateJob.setEnvironment(environment);
          mappingUpdateJob.setAgentCacheEntry(agentCacheEntry);

          executor.execute(mappingUpdateJob);
        }
      } catch (BusinessException e) {
        // if we have exception by resolving new environment run job with no new
        // environment
        EnvironmentMappingUpdateJob mappingUpdateJob = mappingUpdateJobFactory.getObject();
        mappingUpdateJob.setAgentCacheEntry(agentCacheEntry);

        executor.execute(mappingUpdateJob);
      }
    }
  }
  /** {@inheritDoc} */
  @Override
  public void environmentDeleted(
      Environment environment, CmrRepositoryDefinition repositoryDefinition) {
    if (!Objects.equals(repositoryDefinition, displayedCmrRepositoryDefinition)) {
      return;
    }

    for (Iterator<IEnvironmentProvider> it = environmentLeafs.iterator(); it.hasNext(); ) {
      IEnvironmentProvider provider = it.next();
      if (Objects.equals(environment.getId(), provider.getEnvironment().getId())) {
        it.remove();

        performUpdate(false);
        break;
      }
    }
  }