Class SessionManager
- Direct Known Subclasses:
CacheManager, PJamaSessionManager
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.
The SessionManager operates as a bag of globally
accessible resources. Existing subclasses of the
SessionManager also provide persistence, that is, a way to
recover these resources even if the server process is terminated and
later restarted, to get back to the state things were in.
A session manager is like a Dictionary only with fewer guarantees. Enumeration is not possible, and a "get" might return null even if there was a previous "put", so users should be prepared to handle that case.
Unlike a typical dictionary, a session manager uses two keys to identify to identify each resource. The first key, by convention, represents a client session id. The second (or resource) key is chosen to identify the resource within a session.
Care should be used when choosing resource keys, as they are global to a JVM, which may have several unrelated Brazil servers running at once. Sharing session manager resources between servers can cause unexpected behavior if done unintentionally.
Existing session manager implementations arrange for session resources
that are Java Properties to be saved across restarts
of the JVM, and should be used when practical.
- Version:
- 2.2, 04/04/05
- Author:
- Stephen Uhler (stephen.uhler@sun.com), Colin Stevens (colin.stevens@sun.com)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Objectget an object from the session manager.protected ObjectReturns the object associated with the given Session ID and ident.static ObjectgetSession(Object session, Object ident, Class type) Returns the object associated with the given Session ID.protected StringInvent a single key from the 2 separate onesstatic voidput an object into the session manager.protected voidAssociates an object with a session id and ident.static voidRemove an object from the session manager.protected voidRemoves the object associated with the given Session ID and ident.static voidInstalls the givenSessionManagerobject as the default session manager to be invoked whengetSessionis called.
-
Field Details
-
sessions
NOTE: The previous implementation breaks for java > 1.1. Use this one instead. AHashtableused when mapping Session IDs to objects.the key for the hashtable is derived from the "session" and "ident" objects.
-
-
Constructor Details
-
SessionManager
public SessionManager()
-
-
Method Details
-
setSessionManager
Installs the givenSessionManagerobject as the default session manager to be invoked whengetSessionis called.- Parameters:
mgr- TheSessionManagerobject.
-
getSession
Returns the object associated with the given Session ID. Passing in the same (hash-key equivalent) Session ID will return the same object. This convenience method reflects common usage.- Parameters:
session- The Session ID for the persistent session information. If the session does not exist, a new one is created.ident- An arbitray identifier used to determine which object (associated with the givensession) the caller wants.type- The Class of the object to create. If the givensessionandidentdid not specify an existing object, a new one is created by callingnewInstancebased on thetype. Ifnull, then this method returnsnullif the object didn't exist, instead of allocating a new object.- Returns:
- an object of type
type, or null if the object doesn't exist andtypeis null.
-
get
-
put
-
remove
-
getObj
-
putObj
-
removeObj
-
makeKey
-