PATH |
WOSessionStore
Inherits from: Object
Package: com.webobjects.appserver
Class Description
WOSessionStore, an abstract superclass, offers an object abstraction for storing client state per session. The application object (WOApplication) uses an instance of a concrete WOSessionStore subclass to implement a strategy for storing and retrieving session state. You typically set the WOSessionStore during application initialization through WOApplication's setSessionStore method.
An application first creates a session (WOSession) when it receives a request without a session ID. When this first request has been handled, the application stores the WOSession object under a randomly generated session ID by invoking its own saveSessionForContext method. This method by default forwards the message to the chosen WOSessionStore and that WOSessionStore takes care of the details of saving session state. When the next request comes in for that session, the application restores the session by sending itself restoreSessionWithID, which by default is forwarded to the application's WOSessionStore. The WOSessionStore then asks the WOContext of the transaction for the session ID of the session. Based on the implementation of the WOSessionStore, the session object is located and returned.
There is one subclass of WOSessionStore implemented for the developer's convenience. A server WOSessionStore (the default) stores session state in the server, in application memory. The serverSessionStore method returns this WOSessionStore.
See the chapter "Managing State" in the WebObjects Developers Guide for the purposes, mechanisms, and limitations of session store in the server, page, and cookies.
You can create a custom session store by making a subclass of WOSessionStore. The subclass should properly implement the saveSessionForContext and restoreSessionWithID methods (using the session ID as the key for storage) and should have a public method that the application object can use to obtain an instance. Some interesting session stores could be:
- A database session store that stores session data in a database as blobs, with the session ID as the primary key. This kind of WOSessionStore can be shared by many instances of the same WebObjects application, thus distributing the load (requests) among the instances.
- An adaptive session store that stores session state either in cookies or on the server, depending on what the client supports.
If you create your own WOSessionStore class that generates persistent objects, you should implement an algorithm that cleans up session state after the session is inactive for a long time. The server WOSessionStore provided by WebObjects performs this clean-up properly, but the API is not yet public.
Method Types
Obtaining a session store serverSessionStore Checking a session in and out checkInSessionForContext checkOutSessionWithID Session utilities allSessionIDs allSessionIDsCheckedOut isSessionIDCheckedOut removeSessionWithID Saving and restoring a context restoreSessionWithID saveSessionForContext
Constructors
WOSessionStore
public WOSessionStore()
Static Methods
serverSessionStore
public static WOSessionStore serverSessionStore()
State storage in the server is the most secure and is the easiest to implement. You can also easily manage the amount of storage consumed by setting session timeouts, limiting the size of the page-instance cache, and page uniquing. (See "Managing State" in the WebObjects Developers Guide for details on these techniques.)
You may use the coding constructor for the session (WOSession(NSCoder)) to restore session state from the archived data.
Instance Methods
allSessionIDs
public abstract NSArray allSessionIDs()
allSessionIDsCheckedOut
public NSArray allSessionIDsCheckedOut()
checkInSessionForContext
public void checkInSessionForContext(WOContext aContext)
checkOutSessionWithID
public WOSession checkOutSessionWithID( String aSessionID, WORequest aRequest)
isSessionIDCheckedOut
public boolean isSessionIDCheckedOut(String sessionID)
true
if the specified session ID is checked out of the session store.
removeSessionWithID
public abstract WOSession removeSessionWithID(String sessionID)
restoreSessionWithID
public abstract WOSession restoreSessionWithID( String aSessionID, WORequest aRequest)
The default implementation of this method does nothing
saveSessionForContext
public abstract void saveSessionForContext(WOContext aContext)
You may use the NSCoding interface method encodeWithCoder: to save session state to archived data.
toString
public String toString()
© 2001 Apple Computer, Inc. (Last Published April 15, 2001)