FileDocCategorySizeDatePackage
StoreBase.javaAPI DocApache Tomcat 6.0.148614Fri Jul 20 04:20:34 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: 467222 $, $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $

Fields Summary
protected static String
info
The descriptive information about this implementation.
protected static String
storeName
Name to register for this Store, used for logging.
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 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 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 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 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) {
            manager.getContainer().getLogger().error("Error getting keys", e);
            return;
        }
        if (manager.getContainer().getLogger().isDebugEnabled()) {
            manager.getContainer().getLogger().debug(getStoreName()+ ": processExpires check number of " + keys.length + " sessions" );
        }
    
        for (int i = 0; i < keys.length; i++) {
            try {
                StandardSession session = (StandardSession) load(keys[i]);
                if (session == null) {
                    continue;
                }
                if (session.isValid()) {
                    continue;
                }
                if (manager.getContainer().getLogger().isDebugEnabled()) {
                    manager.getContainer().getLogger().debug(getStoreName()+ ": processExpires expire store session " + keys[i] );
                }
                if ( ( (PersistentManagerBase) manager).isLoaded( keys[i] )) {
                    // recycle old backup session
                    session.recycle();
                } else {
                    // expire swapped out session
                    session.expire();
                }
                remove(session.getIdInternal());
            } catch (Exception e) {
                manager.getContainer().getLogger().error("Session: "+keys[i]+"; ", e);
                try {
                    remove(keys[i]);
                } catch (IOException e2) {
                    manager.getContainer().getLogger().error("Error removing key", e2);
                }
            }
        }
    
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 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;