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 Object
get an object from the session manager.protected Object
Returns the object associated with the given Session ID and ident.static Object
getSession
(Object session, Object ident, Class type) Returns the object associated with the given Session ID.protected String
Invent a single key from the 2 separate onesstatic void
put an object into the session manager.protected void
Associates an object with a session id and ident.static void
Remove an object from the session manager.protected void
Removes the object associated with the given Session ID and ident.static void
Installs the givenSessionManager
object as the default session manager to be invoked whengetSession
is called.
-
Field Details
-
sessions
NOTE: The previous implementation breaks for java > 1.1. Use this one instead. AHashtable
used 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 givenSessionManager
object as the default session manager to be invoked whengetSession
is called.- Parameters:
mgr
- TheSessionManager
object.
-
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 givensession
andident
did not specify an existing object, a new one is created by callingnewInstance
based on thetype
. Ifnull
, then this method returnsnull
if 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 andtype
is null.
-
get
get an object from the session manager. This static method will dispatch to the currently installedSessionManager
instance. -
put
put an object into the session manager. This static method will dispatch to the currently installedSessionManager
instance. -
remove
Remove an object from the session manager. This static method will dispatch to the currently installedSessionManager
instance. -
getObj
Returns the object associated with the given Session ID and ident. -
putObj
Associates an object with a session id and ident. "value" may not be null. -
removeObj
Removes the object associated with the given Session ID and ident. -
makeKey
Invent a single key from the 2 separate ones
-