FileDocCategorySizeDatePackage
StoreBase.javaAPI DocGlassfish v2 API13503Mon Sep 03 22:32:26 BST 2007org.apache.catalina.session

StoreBase

public abstract class StoreBase extends Object implements org.apache.catalina.Lifecycle, org.apache.catalina.Store
Abstract implementation of the Store interface to support most of the functionality required by a Store.
author
Bip Thelin
version
$Revision: 1.8.6.1 $, $Date: 2007/09/04 05:32:26 $

Fields Summary
protected String
info
The descriptive information about this implementation.
protected String
storeName
Name to register for this Store, used for logging.
protected int
debug
The debugging detail level for this component.
protected boolean
started
Has this component been started yet?
protected org.apache.catalina.util.LifecycleSupport
lifecycle
The lifecycle event support for this component.
protected PropertyChangeSupport
support
The property change support for this component.
protected static final org.apache.catalina.util.StringManager
sm
The string manager for this package.
protected org.apache.catalina.Manager
manager
The Manager with which this JDBCStore is associated.
Constructors Summary
Methods Summary
public voidaddLifecycleListener(org.apache.catalina.LifecycleListener listener)
Add a lifecycle event listener to this component.

param
listener The listener to add

        lifecycle.addLifecycleListener(listener);
    
public voidaddPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a property change listener to this component.

param
listener a value of type 'PropertyChangeListener'

        support.addPropertyChangeListener(listener);
    
public voiddoProcessExpires()
public wrapper for processExpires() don't want to make processExpires() public called from manager background thread Hercules: added method

        this.processExpires();
    
public org.apache.catalina.LifecycleListener[]findLifecycleListeners()
Get the lifecycle listeners associated with this lifecycle. If this Lifecycle has no listeners registered, a zero-length array is returned.


        return lifecycle.findLifecycleListeners();

    
public intgetDebug()
Return the debugging detail level for this Store.

        return(this.debug);
    
public java.lang.StringgetInfo()
Return the info for this Store.


    // ------------------------------------------------------------- Properties

               
       
        return(info);
    
public org.apache.catalina.ManagergetManager()
Return the Manager with which the Store is associated.

        return(this.manager);
    
public java.lang.StringgetStoreName()
Return the name for this Store, used for logging.

        return(storeName);
    
public org.apache.catalina.Sessionload(java.lang.String id, java.lang.String version)
Load and return the Session associated with the specified session identifier from this Store, without removing it. If there is no such stored Session, return null.

param
id Session identifier of the session to load
param
version The requested session version
exception
ClassNotFoundException if a deserialization error occurs
exception
IOException if an input/output error occurs

        return load(id);
    
protected voidlog(java.lang.String message)
Log a message on the Logger associated with our Container (if any).

param
message Message to be logged

        Logger logger = null;
        Container container = manager.getContainer();

        if (container != null) {
            logger = container.getLogger();
        }

        if (logger != null) {
            logger.log(getStoreName()+"[" + container.getName() + "]: "
                       + message);
        } else {
            String containerName = null;
            if (container != null) {
                containerName = container.getName();
            }
            System.out.println(getStoreName()+"[" + containerName
                               + "]: " + message);
        }
    
public voidprocessExpires()
Called by our background reaper thread to check if Sessions saved in our store are subject of being expired. If so expire the Session and remove it from the Store.

        long timeNow = System.currentTimeMillis();
        String[] keys = null;

        if(!started) {
            return;
        }

        try {
            keys = keys();
        } catch (IOException e) {
            log (e.toString());
            e.printStackTrace();
            return;
        }

        for (int i = 0; i < keys.length; i++) {
            try {
                StandardSession session = (StandardSession) load(keys[i]);
                if (session == null) {
                    continue;
                }
                if (session.isValid()) {
                    continue;
                }
                if ( ( (PersistentManagerBase) manager).isLoaded( keys[i] )) {
                    // recycle old backup session
                    session.recycle();
                } else {
                    // expire swapped out session
                    session.expire();
                }
                remove(session.getIdInternal());
            } catch (IOException e) {
                log (e.toString());
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                log (e.toString());
                e.printStackTrace();
            }
        }
    
public org.apache.catalina.SessionreadSession(org.apache.catalina.Manager manager, java.io.ObjectInputStream ois)
Create a session object from an input stream.

param
manager The manager that will own this session
param
ois The input stream containing the serialized session
return
The resulting session object Hercules: added method


        StandardSession sess = StandardSession.deserialize(ois, manager);
        sess.setManager(manager);
      
        return sess;
    
public voidremoveFromStoreCache(java.lang.String id)
no-op method - sub classes will implement to remove a session from the store cache Hercules: added method

        //do nothing
    
public voidremoveLifecycleListener(org.apache.catalina.LifecycleListener listener)
Remove a lifecycle event listener from this component.

param
listener The listener to add

        lifecycle.removeLifecycleListener(listener);
    
public voidremovePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a property change listener from this component.

param
listener The listener to remove

        support.removePropertyChangeListener(listener);
    
public voidsetDebug(int debug)
Set the debugging detail level for this Store.

param
debug The new debugging detail level

        this.debug = debug;
    
public voidsetManager(org.apache.catalina.Manager manager)
Set the Manager with which this Store is associated.

param
manager The newly associated Manager

        Manager oldManager = this.manager;
        this.manager = manager;
        support.firePropertyChange("manager", oldManager, this.manager);
    
public voidstart()
Prepare for the beginning of active use of the public methods of this component. This method should be called after configure(), and before any of the public methods of the component are utilized.

exception
LifecycleException if this component detects a fatal error that prevents this component from being used

        // Validate and update our current component state
        if (started)
            throw new LifecycleException
                (sm.getString(getStoreName()+".alreadyStarted"));
        lifecycle.fireLifecycleEvent(START_EVENT, null);
        started = true;

    
public voidstop()
Gracefully terminate the active use of the public methods of this component. This method should be the last one called on a given instance of this component.

exception
LifecycleException if this component detects a fatal error that needs to be reported

        // Validate and update our current component state
        if (!started)
            throw new LifecycleException
                (sm.getString(getStoreName()+".notStarted"));
        lifecycle.fireLifecycleEvent(STOP_EVENT, null);
        started = false;

    
public voidwriteSession(org.apache.catalina.Session sess, java.io.ObjectOutputStream oos)
Serialize a session into an output stream.

param
sess The session to be serialized
param
oos The output stream the session should be written to Hercules: added method

      if ( sess == null )  {
        return;
      }
      
      oos.writeObject(sess);