Package sunlabs.brazil.session
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
ThisSessionManagerassociates 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)
-
-
Field Summary
-
Fields inherited from class sunlabs.brazil.session.SessionManager
sessions
-
-
Constructor Summary
Constructors Constructor Description CacheManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidflush()The active hashtable is too big, find the hashtable with the worst Score, clear it, and set it as the active table.protected java.lang.ObjectgetObj(java.lang.Object session, java.lang.Object ident)Returns the object associated with the given Session ID and ident.booleaninit(Server server, java.lang.String prefix)Install this class as the session manager.protected java.lang.StringmakeKey(java.lang.Object session, java.lang.Object ident)Invent a single key from the 2 separate onesprotected voidputObj(java.lang.Object session, java.lang.Object ident, java.lang.Object value)Associates an object with a session id and ident.protected voidputObj(java.lang.String key, java.lang.Object value)voidremoveObj(java.lang.Object session, java.lang.Object ident)Remove an object from a session table.booleanrespond(Request request)Don't handle any URL requests (yet)-
Methods inherited from class sunlabs.brazil.session.SessionManager
get, getSession, put, remove, setSessionManager
-
-
-
-
Method Detail
-
init
public boolean init(Server server, java.lang.String prefix)
Install this class as the session manager. Get the number of tables, and the max size per table.- Specified by:
initin interfaceHandler- Parameters:
server- The HTTP server that created thisHandler. TypicalHandlers will useServer.propsto obtain run-time configuration information.prefix- The handlers name. The string thisHandlermay prepend to all of the keys that it uses to extract configuration information fromServer.props. This is set (by theServerandChainHandler) to help avoid configuration parameter namespace collisions.- Returns:
trueif thisHandlerinitialized successfully,falseotherwise. Iffalseis returned, thisHandlershould not be used.
-
respond
public boolean respond(Request request)
Don't handle any URL requests (yet)
-
getObj
protected java.lang.Object getObj(java.lang.Object session, java.lang.Object ident)Description copied from class:SessionManagerReturns the object associated with the given Session ID and ident.- Overrides:
getObjin classSessionManager
-
putObj
protected void putObj(java.lang.String key, java.lang.Object value)
-
putObj
protected void putObj(java.lang.Object session, java.lang.Object ident, java.lang.Object value)Description copied from class:SessionManagerAssociates an object with a session id and ident. "value" may not be null.- Overrides:
putObjin classSessionManager
-
removeObj
public void removeObj(java.lang.Object session, java.lang.Object ident)Remove an object from a session table. Don't bother to remove the table if its empty- Overrides:
removeObjin classSessionManager
-
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 java.lang.String makeKey(java.lang.Object session, java.lang.Object ident)Invent a single key from the 2 separate ones- Overrides:
makeKeyin classSessionManager
-
-