コード例 #1
0
  /** Close OpenKM and free resources */
  public static synchronized void stop(GenericServlet gs) {
    if (!running) {
      throw new IllegalStateException("OpenKM not started");
    }

    // Shutdown plugin framework
    ExtensionManager.getInstance().shutdown();

    try {
      if (!Config.SYSTEM_OPENOFFICE_PATH.equals("")) {
        if (log == null && gs != null) {
          gs.log("*** Shutting down OpenOffice manager ***");
        } else {
          log.info("*** Shutting down OpenOffice manager ***");
        }

        DocConverter.getInstance().stop();
      }
    } catch (Throwable e) {
      log.warn(e.getMessage(), e);
    }

    if (hasConfiguredDataStore) {
      if (log == null && gs != null)
        gs.log("*** Shutting down datastore garbage collection... ***");
      else log.info("*** Shutting down datastore garbage collection... ***");
      dsgc.cancel();
    }

    if (Config.SCHEDULE_MAIL_IMPORTER > 0) {
      if (log == null && gs != null) gs.log("*** Shutting down user mail importer ***");
      else log.info("*** Shutting down user mail importer ***");
      umi.cancel();
    }

    if (Config.MANAGED_TEXT_EXTRACTION_SCHEDULE > 0) {
      if (log == null && gs != null) gs.log("*** Shutting down text extractor worker ***");
      else log.info("*** Shutting down text extractor worker ***");
      tew.cancel();
    }

    if (log == null && gs != null) gs.log("*** Shutting down repository info... ***");
    else log.info("*** Shutting down repository info... ***");
    ri.cancel();

    if (log == null && gs != null) gs.log("*** Shutting down UI Notification... ***");
    else log.info("*** Shutting down UI Notification... ***");
    uin.cancel();

    if (log == null && gs != null) gs.log("*** Shutting down cron... ***");
    else log.info("*** Shutting down cron... ***");
    cron.cancel();

    if (log == null && gs != null) gs.log("*** Shutting down watchdog... ***");
    else log.info("*** Shutting down watchdog... ***");
    wd.cancel();

    if (Config.UPDATE_INFO) {
      if (log == null && gs != null) gs.log("*** Shutting down update info... ***");
      else log.info("*** Shutting down update info... ***");
      ui.cancel();
    }

    // Cancel timers
    dsgcTimer.cancel();
    umiTimer.cancel();
    riTimer.cancel();
    cronTimer.cancel();
    uinTimer.cancel();
    wdTimer.cancel();
    uiTimer.cancel();
    tewTimer.cancel();

    if (log == null && gs != null) gs.log("*** Shutting down repository... ***");
    else log.info("*** Shutting down repository... ***");

    if (Config.USER_ITEM_CACHE) {
      // Serialize
      try {
        log.info("*** Cache serialization ***");
        UserItemsManager.serialize();
        UserNodeKeywordsManager.serialize();
      } catch (DatabaseException e) {
        log.warn(e.getMessage(), e);
      }
    }

    try {
      // Preserve system user config
      if (!Config.REPOSITORY_NATIVE) {
        JcrRepositoryModule.shutdown();
      }
    } catch (Exception e) {
      log.error(e.getMessage(), e);
    }

    if (log == null && gs != null) gs.log("*** Repository shutted down ***");
    else log.info("*** Repository shutted down ***");

    try {
      if (log == null && gs != null) gs.log("*** Ejecute stop script ***");
      else log.info("*** Ejecute stop script ***");
      File script = new File(Config.HOME_DIR + File.separatorChar + Config.STOP_SCRIPT);
      ExecutionUtils.runScript(script);
      File jar = new File(Config.HOME_DIR + File.separatorChar + Config.STOP_JAR);
      ExecutionUtils.getInstance().runJar(jar);
    } catch (Throwable e) {
      log.warn(e.getMessage(), e);
    }

    if (log == null && gs != null) gs.log("*** Shutting down workflow engine... ***");
    else log.info("*** Shutting down workflow engine... ***");
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    jbpmContext.getJbpmConfiguration().getJobExecutor().stop();
    jbpmContext.getJbpmConfiguration().close();
    jbpmContext.close();

    // OpenKM is stopped
    running = false;
  }