| java.lang.Object sunlabs.brazil.session.SessionManager sunlabs.brazil.session.SerialPersist
SerialPersist | public class SerialPersist extends SessionManager implements Handler,SignalHandler(Code) | | The SerialPersist class is a SessionManager
that uses Java object serialization to make a persistent store of the
session information for a server. See
SessionManager for a description of sessions.
This class uses the signal-handling capabilities of the Solaris-specific
sun.misc package. When the program is interrupted by a
Ctrl-C (SIGINT), the current session information is serialized to
a "store" file. When the program is restarted, the session information
is restored from the store file.
To use this SessionManager effectively, the developer should
try to ensure that only Serializable objects are stored in
the session manager. With default object serialization, the developer
will get a runtime IOException if an object in the hierarchy is not
actually serializable, for example, if a (Serializable )
Hashtable contains an arbitrary non-serializable object.
This class will traverse the session hierarchy and attempt to remove
all non-serializable objects before writing to the store file. This
means that after restoring, the session information may not correspond
exactly to what it was present before. Consumers of session information
should be prepared to deal with some session information disappearing.
For instance, the TemplateRunner keeps the templates for each
session in the SessionManager and will reconstruct the
templates if some or all of them disappear during a restore.
This class will recursively traverse the elements of (specifically) any
Hashtable , Vector , or array it finds in the
session hierarchy to ensure that the elements themselves are
Serializable . If the element is not, it is removed from
its container. If the container becomes zero-length because all its
elements were removed, the container is then itself removed. For
arrays, the offending non-serializable element is instead replaced with
null , since arrays cannot be resized.
This SessionManager implements the Handler
interface,and examines the following request properties at init time:
- store
- The name of the store file to hold the session information. The
default value is
"store" .
- saveUrl
- The name of a url that will cause the session information to be
saved without terminating the server. WARNING! this has the side
effect of removing non serializable elements from the session
table, which can lead to disturbing behavior.
author: Stephen Uhler (stephen.uhler@sun.com) author: Colin Stevens (colin.stevens@sun.com) version: 1.11, 00/12/11 |
cleanForSerialization | public static Object cleanForSerialization(Object obj)(Code) | | Recursively decend through an object "Cleaning" it for serialization.
For the container objects "Hashtable", "Vector", and "Array", look at
every object contained within it, removing all those that are not
serializable by either removing them, or setting them to null.
This allows successful serialization even if some elements of the
base object, or its desendents can't be serialized.
This is intended for saving and restoring typical session information.
Care must be taken by the caller that data integrety is maintained
when non-serializable objects are zapped.
Parameters: obj - The object to Clean |
handle | public void handle(Signal sig)(Code) | | |
readStore | void readStore()(Code) | | Call this first, to read in the store, if available.
One store per application
|
saveStore | void saveStore()(Code) | | Call this to "save" the store, typically before exiting.
This should be done on a signal handler
Before calling writeObject, we need to iterate through the
sessions table, and remove all values that are not serializable
|
|
|