/** Cleans up the sessions when the Application shuts down gracefully. */
  public void close() {
    synchronized (this) {
      if (_isClosed) return;
      _isClosed = true;
    }

    if (_sessions == null) return;

    // _alarm.dequeue();

    _sessionList.clear();

    ArrayList<SessionArrayValue> list = new ArrayList<SessionArrayValue>();

    boolean isError = false;

    synchronized (_sessions) {
      _sessionIter = _sessions.values(_sessionIter);

      while (_sessionIter.hasNext()) {
        SessionArrayValue session = _sessionIter.next();

        if (session.isValid()) list.add(session);
      }
    }

    for (int i = list.size() - 1; i >= 0; i--) {
      SessionArrayValue session = list.get(i);

      try {
        if (session.isValid()) {
          synchronized (session) {
            if (!session.isEmpty()) session.storeOnShutdown();
          }
        }

        _sessions.remove(session.getId());
      } catch (Exception e) {
        if (!isError) log.log(Level.WARNING, "Can't store session: " + e, e);
        isError = true;
      }
    }
  }
  /** Checks if the session is empty. */
  public boolean isEmpty(Object obj) {
    SessionArrayValue session = (SessionArrayValue) obj;

    return session.isEmpty();
  }