Example #1
0
  /**
   * Called by our background reaper thread to check if Sessions saved in our store are subject of
   * being expired. If so expire the Session and remove it from the Store.
   */
  public void processExpires() {
    long timeNow = System.currentTimeMillis();
    String[] keys = null;

    if (!started) {
      return;
    }

    try {
      keys = keys();
    } catch (IOException e) {
      manager.getContainer().getLogger().error("Error getting keys", e);
      return;
    }
    if (manager.getContainer().getLogger().isDebugEnabled()) {
      manager
          .getContainer()
          .getLogger()
          .debug(getStoreName() + ": processExpires check number of " + keys.length + " sessions");
    }

    for (int i = 0; i < keys.length; i++) {
      try {
        StandardSession session = (StandardSession) load(keys[i]);
        if (session == null) {
          continue;
        }
        int timeIdle = (int) ((timeNow - session.thisAccessedTime) / 1000L);
        if (timeIdle < session.getMaxInactiveInterval()) {
          continue;
        }
        if (manager.getContainer().getLogger().isDebugEnabled()) {
          manager
              .getContainer()
              .getLogger()
              .debug(getStoreName() + ": processExpires expire store session " + keys[i]);
        }
        if (((PersistentManagerBase) manager).isLoaded(keys[i])) {
          // recycle old backup session
          session.recycle();
        } else {
          // expire swapped out session
          session.expire();
        }
        remove(keys[i]);
      } catch (Exception e) {
        manager.getContainer().getLogger().error("Session: " + keys[i] + "; ", e);
        try {
          remove(keys[i]);
        } catch (IOException e2) {
          manager.getContainer().getLogger().error("Error removing key", e2);
        }
      }
    }
  }