@Override
  public boolean postStateTransitionEvent(
      State oldState,
      Event event,
      State newState,
      VirtualMachine vm,
      boolean status,
      Long oldHostId) {
    if (!status) {
      return false;
    }

    if (VirtualMachine.State.isVmStarted(oldState, event, newState)) {
      if (s_logger.isTraceEnabled()) {
        s_logger.trace("Security Group Mgr: handling start of vm id" + vm.getId());
      }
      handleVmStarted((VMInstanceVO) vm);
    } else if (VirtualMachine.State.isVmStopped(oldState, event, newState)) {
      if (s_logger.isTraceEnabled()) {
        s_logger.trace("Security Group Mgr: handling stop of vm id" + vm.getId());
      }
      handleVmStopped((VMInstanceVO) vm);
    } else if (VirtualMachine.State.isVmMigrated(oldState, event, newState)) {
      if (s_logger.isTraceEnabled()) {
        s_logger.trace("Security Group Mgr: handling migration of vm id" + vm.getId());
      }
      handleVmMigrated((VMInstanceVO) vm);
    }

    return true;
  }
  @Override
  public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {

    Map<String, String> configs = _configDao.getConfiguration("Network", params);
    _numWorkerThreads =
        NumbersUtil.parseInt(
            configs.get(Config.SecurityGroupWorkerThreads.key()), WORKER_THREAD_COUNT);
    _timeBetweenCleanups =
        NumbersUtil.parseInt(
            configs.get(Config.SecurityGroupWorkCleanupInterval.key()), TIME_BETWEEN_CLEANUPS);
    _globalWorkLockTimeout =
        NumbersUtil.parseInt(configs.get(Config.SecurityGroupWorkGlobalLockTimeout.key()), 300);
    /* register state listener, no matter security group is enabled or not */
    VirtualMachine.State.getStateMachine().registerListener(this);

    _answerListener = new SecurityGroupListener(this, _agentMgr, _workDao);
    _agentMgr.registerForHostEvents(_answerListener, true, true, true);

    _serverId = ((ManagementServer) ComponentLocator.getComponent(ManagementServer.Name)).getId();

    s_logger.info(
        "SecurityGroupManager: num worker threads="
            + _numWorkerThreads
            + ", time between cleanups="
            + _timeBetweenCleanups
            + " global lock timeout="
            + _globalWorkLockTimeout);
    createThreadPools();

    return true;
  }
  @Override
  public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
    _vmCapacityReleaseInterval =
        NumbersUtil.parseInt(_configDao.getValue(Config.CapacitySkipcountingHours.key()), 3600);
    _storageOverProvisioningFactor =
        NumbersUtil.parseFloat(
            _configDao.getValue(Config.StorageOverprovisioningFactor.key()), 1.0f);

    _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("HostCapacity-Checker"));
    VirtualMachine.State.getStateMachine().registerListener(this);
    _agentManager.registerForHostEvents(
        new StorageCapacityListener(_capacityDao, _storageOverProvisioningFactor),
        true,
        false,
        false);
    _agentManager.registerForHostEvents(
        new ComputeCapacityListener(_capacityDao, this), true, false, false);

    return true;
  }