コード例 #1
0
  /**
   * Initialize and load our initial database from persistent storage.
   *
   * @param servlet The ActionServlet for this web application
   * @param config The ApplicationConfig for our owning module
   * @exception ServletException if we cannot configure ourselves correctly
   */
  public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {

    log.info("Initializing memory database plug in from '" + pathname + "'");

    // Remember our associated configuration and servlet
    this.servlet = servlet;

    // Construct a new database and make it available
    database = new MemoryUserDatabase();
    try {
      String path = calculatePath();
      if (log.isDebugEnabled()) {
        log.debug(" Loading database from '" + path + "'");
      }
      database.setPathname(path);
      database.open();
    } catch (Exception e) {
      log.error("Opening memory database", e);
      throw new ServletException("Cannot load database from '" + pathname + "'", e);
    }

    // Make the initialized database available
    servlet.getServletContext().setAttribute(Constants.DATABASE_KEY, database);
  }
コード例 #2
0
  /**
   * Gracefully shut down this database, releasing any resources that were allocated at
   * initialization.
   */
  public void destroy() {

    log.info("Finalizing memory database plug in");

    if (database != null) {
      try {
        database.close();
      } catch (Exception e) {
        log.error("Closing memory database", e);
      }
    }

    servlet.getServletContext().removeAttribute(Constants.DATABASE_KEY);
    database = null;
    servlet = null;
    database = null;
  }