public class SessionManager
extends java.lang.Object
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.
Modifier and Type | Field and Description |
---|---|
protected java.util.Hashtable |
sessions
NOTE: The previous implementation breaks for java > 1.1.
|
Constructor and Description |
---|
SessionManager() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Object |
get(java.lang.Object session,
java.lang.Object ident)
get an object from the session manager.
|
protected java.lang.Object |
getObj(java.lang.Object session,
java.lang.Object ident)
Returns the object associated with the given Session ID and ident.
|
static java.lang.Object |
getSession(java.lang.Object session,
java.lang.Object ident,
java.lang.Class type)
Returns the object associated with the given Session ID.
|
protected java.lang.String |
makeKey(java.lang.Object session,
java.lang.Object ident)
Invent a single key from the 2 separate ones
|
static void |
put(java.lang.Object session,
java.lang.Object ident,
java.lang.Object data)
put an object into the session manager.
|
protected void |
putObj(java.lang.Object session,
java.lang.Object ident,
java.lang.Object value)
Associates an object with a session id and ident.
|
static void |
remove(java.lang.Object session,
java.lang.Object ident)
Remove an object from the session manager.
|
protected void |
removeObj(java.lang.Object session,
java.lang.Object ident)
Removes the object associated with the given Session ID and ident.
|
static void |
setSessionManager(SessionManager mgr)
Installs the given
SessionManager object as the
default session manager to be invoked when getSession
is called. |
protected java.util.Hashtable sessions
Hashtable
used when mapping Session IDs to objects.
the key for the hashtable is derived from the "session" and "ident" objects.
public static void setSessionManager(SessionManager mgr)
SessionManager
object as the
default session manager to be invoked when getSession
is called.mgr
- The SessionManager
object.public static java.lang.Object getSession(java.lang.Object session, java.lang.Object ident, java.lang.Class type)
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 given session
) the caller
wants.type
- The Class of the object to create. If the given
session
and ident
did not specify
an existing object, a new one is created by calling
newInstance
based on the type
.
If null
, then this method returns
null
if the object didn't exist, instead of
allocating a new object.type
, or null if
the object doesn't exist and type
is null.public static java.lang.Object get(java.lang.Object session, java.lang.Object ident)
SessionManager
instance.public static void put(java.lang.Object session, java.lang.Object ident, java.lang.Object data)
SessionManager
instance.public static void remove(java.lang.Object session, java.lang.Object ident)
SessionManager
instance.protected java.lang.Object getObj(java.lang.Object session, java.lang.Object ident)
protected void putObj(java.lang.Object session, java.lang.Object ident, java.lang.Object value)
protected void removeObj(java.lang.Object session, java.lang.Object ident)
protected java.lang.String makeKey(java.lang.Object session, java.lang.Object ident)