/*
   * (non-Javadoc)
   *
   * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
   */
  public void contextDestroyed(ServletContextEvent event) {

    String contextid = event.getServletContext().getAttribute("CONTEXTID").toString();
    LOG.info("系统退出,系统ID......" + contextid);
    try {
      Globals globals = new Globals();
      SysLoginLogService service = (SysLoginLogService) globals.getBean("sysLoginLogService");
      service.updateLogoutInfo(contextid);
      LOG.info("容器退出时,记录用户的会话失效信息OK!");
    } catch (Exception e) {
      LOG.error("容器退出时,记录用户的会话失效信息失败!" + e);
    }

    // 停止对所有号码的追踪
    Iterator<String> iterator = EricssonTrace.TRACE_MOBILES.keySet().iterator();
    long now = 0;
    EricssonTrace service = new EricssonTrace();
    while (iterator.hasNext()) {
      now = System.currentTimeMillis();
      String key = iterator.next();
      String mobile = key.split(",")[0];
      service.mobileTracStop(EricssonTrace.TRACE_MOBILES.get(key), mobile, now + "");
      LOG.info("停止" + key + "追踪的执行时间:::" + (System.currentTimeMillis() - now));
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
   */
  public void contextInitialized(ServletContextEvent event) {

    try {

      BasicService basicService = (BasicService) Globals.getBean("basicService");
      List list = basicService.findAll(SysParameter.class);
      // List chanellist=basicService.findAll(CoreChannel.class);
      int length = list == null ? 0 : list.size();
      for (int i = 0; i < length; i++) {
        SysParameter param = (SysParameter) list.get(i);
        CommonDatas.SysParameter.put(param.getParamname(), param.getParamvalue());
      }

      if (CommonDatas.SysParameter.containsKey("sysname")) {
        Constants.SYS_NAME = CommonDatas.SysParameter.get("sysname").toString();
      }
      if (CommonDatas.SysParameter.containsKey("resourcepath")) {
        Constants.RESOURCE_PATH = CommonDatas.SysParameter.get("resourcepath").toString();
      }
      if (CommonDatas.SysParameter.containsKey("resourcepathmanage")) {
        Constants.RESOURCE_PATH_MANAGE =
            CommonDatas.SysParameter.get("resourcepathmanage").toString();
      }
      // 获得所有的权限列表信息
      RightTree.setRightList(basicService.findAll(SysRight.class));

      com.sxit.system.util.CommonDatas.getUsers();
      com.sxit.system.util.CommonDatas.getGroups();
      BasicSetService setservice = (BasicSetService) Globals.getBean("basicSetService");
      //			setservice.getAllSets();
      ChrQueryService queryservice = (ChrQueryService) Globals.getBean("chrQueryService");
      queryservice.getFlowids();

      // BasicSetService setservice = (BasicSetService)
      // Globals.getBean("basicSetService");
      // setservice.getAllSets();
      // LOG.info("得到所有的配置参数信息");

    } catch (ServiceException e) {
      LOG.error("系统启动初始化权限列表为空" + e);
    }
    String contextid = System.currentTimeMillis() / 1000 + "";
    event.getServletContext().setAttribute("CONTEXTID", contextid);
    LOG.info("系统启动初始化,系统ID......" + contextid);
  }