Class CacheManager

java.lang.Object
sunlabs.brazil.session.SessionManager
sunlabs.brazil.session.CacheManager
All Implemented Interfaces:
Handler
Direct Known Subclasses:
PropertiesCacheManager

public class CacheManager extends SessionManager implements Handler
This SessionManager associates an object with a Session ID to give Handlers the ability to maintain state that lasts for the duration of a session instead of just for the duration of a request. It should be installed as a handler, whoses init method will replace the default session manager.

This version maintains a pool of hashtables. Once they all fill up - one of them gets tossed, causing any session info in it to be lost. It uses a simplified approximate LRU scheme. The default session manager doesn't loose any session information, but grows the heap without bound as the number of sessions increase.

properties:

tables
The number of Hashtables in the pool (defaults to 6)
size
The max number of entries in each table (defaults to 1000).
Version:
%V% CacheManager.java
Author:
Stephen Uhler (stephen.uhler@sun.com)
  • Constructor Details

    • CacheManager

      public CacheManager()
  • Method Details

    • init

      public boolean init(Server server, String prefix)
      Install this class as the session manager. Get the number of tables, and the max size per table.
      Specified by:
      init in interface Handler
      Parameters:
      server - The HTTP server that created this Handler. Typical Handlers will use Server.props to obtain run-time configuration information.
      prefix - The handlers name. The string this Handler may prepend to all of the keys that it uses to extract configuration information from Server.props. This is set (by the Server and ChainHandler) to help avoid configuration parameter namespace collisions.
      Returns:
      true if this Handler initialized successfully, false otherwise. If false is returned, this Handler should not be used.
    • respond

      public boolean respond(Request request)
      Don't handle any URL requests (yet)
      Specified by:
      respond in interface Handler
      Parameters:
      request - The Request object that represents the HTTP request.
      Returns:
      true if the request was handled. A request was handled if a response was supplied to the client, typically by calling Request.sendResponse() or Request.sendError.
    • getObj

      protected Object getObj(Object session, Object ident)
      Description copied from class: SessionManager
      Returns the object associated with the given Session ID and ident.
      Overrides:
      getObj in class SessionManager
    • putObj

      protected void putObj(String key, Object value)
    • putObj

      protected void putObj(Object session, Object ident, Object value)
      Description copied from class: SessionManager
      Associates an object with a session id and ident. "value" may not be null.
      Overrides:
      putObj in class SessionManager
    • removeObj

      public void removeObj(Object session, Object ident)
      Remove an object from a session table. Don't bother to remove the table if its empty
      Overrides:
      removeObj in class SessionManager
    • flush

      protected void flush()
      The active hashtable is too big, find the hashtable with the worst Score, clear it, and set it as the active table.
    • makeKey

      protected String makeKey(Object session, Object ident)
      Invent a single key from the 2 separate ones
      Overrides:
      makeKey in class SessionManager