sunlabs.brazil.session
Class SerialPersist

java.lang.Object
  |
  +--sunlabs.brazil.session.SessionManager
        |
        +--sunlabs.brazil.session.SerialPersist
All Implemented Interfaces:
Handler, sun.misc.SignalHandler

public class SerialPersist
extends SessionManager
implements Handler, sun.misc.SignalHandler

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.


Field Summary
 
Fields inherited from interface sun.misc.SignalHandler
SIG_DFL, SIG_IGN
 
Constructor Summary
SerialPersist()
           
 
Method Summary
static Object cleanForSerialization(Object obj)
          Recursively decend through an object "Cleaning" it for serialization.
 void handle(sun.misc.Signal sig)
           
 boolean init(Server server, String prefix)
          Initializes the handler.
 boolean respond(Request request)
          Responds to an HTTP request.
 
Methods inherited from class sunlabs.brazil.session.SessionManager
get, getSession, put, remove, setSessionManager
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SerialPersist

public SerialPersist()
Method Detail

init

public boolean init(Server server,
                    String prefix)
Description copied from interface: Handler
Initializes the handler.

Specified by:
init in interface Handler
Parameters:
server - The HTTP server that created this Handler. Typical Handlers will use Server.props to obtain run-time configuration information.
prefix - The handlers name. The string this Handler may prepend to all of the keys that it uses to extract configuration information from Server.props. This is set (by the Server and ChainHandler) to help avoid configuration parameter namespace collisions.
Returns:
true if this Handler initialized successfully, false otherwise. If false is returned, this Handler should not be used.

respond

public boolean respond(Request request)
Description copied from interface: Handler
Responds to an HTTP request.

Specified by:
respond in interface Handler
Parameters:
request - The Request object that represents the HTTP request.
Returns:
true if the request was handled. A request was handled if a response was supplied to the client, typically by calling Request.sendResponse() or Request.sendError.

handle

public void handle(sun.misc.Signal sig)
Specified by:
handle in interface sun.misc.SignalHandler

cleanForSerialization

public static Object cleanForSerialization(Object obj)
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
Returns:
The cleaned object, or null if nothing is serializable.

Version 2.1, Generated 12/30/04
Copyright (c) 2001-2004, Sun Microsystems.