Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.apache.catalina.session;
 
 import static org.jboss.web.CatalinaMessages.MESSAGES;
 
 
Abstract implementation of the Store interface to support most of the functionality required by a Store.

Author(s):
Bip Thelin
Version:
$Revision: 1672 $, $Date: 2011-03-04 01:39:31 +0100 (Fri, 04 Mar 2011) $
 
 
 public abstract class StoreBase
     implements LifecycleStore {
 
     // ----------------------------------------------------- Instance Variables
 
    
The descriptive information about this implementation.
 
     protected static String info = "StoreBase/1.0";

    
Name to register for this Store, used for logging.
 
     protected static String storeName = "StoreBase";

    
Has this component been started yet?
 
     protected boolean started = false;

    
The lifecycle event support for this component.
 
     protected LifecycleSupport lifecycle = new LifecycleSupport(this);

    
The property change support for this component.
 
     protected PropertyChangeSupport support = new PropertyChangeSupport(this);

    
The Manager with which this JDBCStore is associated.
 
     protected Manager manager;
 
     // ------------------------------------------------------------- Properties
 
    
Return the info for this Store.
 
     public String getInfo() {
         return();
     }


    
Return the name for this Store, used for logging.
 
     public String getStoreName() {
         return();
     }


    
Set the Manager with which this Store is associated.

Parameters:
manager The newly associated Manager
 
     public void setManager(Manager manager) {
        Manager oldManager = this.;
        this. = manager;
        .firePropertyChange("manager"oldManagerthis.);
    }

    
Return the Manager with which the Store is associated.
    public Manager getManager() {
        return(this.);
    }
    // --------------------------------------------------------- Public Methods

    
Add a lifecycle event listener to this component.

Parameters:
listener The listener to add
    public void addLifecycleListener(LifecycleListener listener) {
        .addLifecycleListener(listener);
    }


    
Get the lifecycle listeners associated with this lifecycle. If this Lifecycle has no listeners registered, a zero-length array is returned.
        return .findLifecycleListeners();
    }


    
Remove a lifecycle event listener from this component.

Parameters:
listener The listener to add
    public void removeLifecycleListener(LifecycleListener listener) {
        .removeLifecycleListener(listener);
    }

    
Add a property change listener to this component.

Parameters:
listener a value of type 'PropertyChangeListener'
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        .addPropertyChangeListener(listener);
    }

    
Remove a property change listener from this component.

Parameters:
listener The listener to remove
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        .removePropertyChangeListener(listener);
    }
    // --------------------------------------------------------- Protected Methods

    
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.
    public void processExpires() {
        String[] keys = null;
         if(!) {
            return;
        }
        try {
            keys = keys();
        } catch (IOException e) {
            .getContainer().getLogger().error(.errorGettingKeys(), e);
            return;
        }
        if (.getContainer().getLogger().isDebugEnabled()) {
            .getContainer().getLogger().debug(getStoreName()+ ": processExpires check number of " + keys.length + " sessions" );
        }
    
        long timeNow = System.currentTimeMillis();
        for (int i = 0; i < keys.lengthi++) {
            try {
                StandardSession session = (StandardSessionload(keys[i]);
                if (session == null) {
                    continue;
                }
                int timeIdle = (int) ((timeNow - session.getLastAccessedTime()) / 1000L);
                if (timeIdle < session.getMaxInactiveInterval()) {
                    continue;
                }
                if (.getContainer().getLogger().isDebugEnabled()) {
                    .getContainer().getLogger().debug(getStoreName()+ ": processExpires expire store session " + keys[i] );
                }
                if ( ( (PersistentManagerBase).isLoadedkeys[i] )) {
                    // recycle old backup session
                    session.recycle();
                } else {
                    // expire swapped out session
                    session.expire();
                }
                remove(keys[i]);
            } catch (Exception e) {
                .getContainer().getLogger().error(.errorProcessingSessionExpires(keys[i]), e);
                try {
                    remove(keys[i]);
                } catch (IOException e2) {
                    .getContainer().getLogger().error(.errorRemovingKey(keys[i]), e2);
                }
            }
        }
    }
    // --------------------------------------------------------- Thread Methods


    
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.

Throws:
org.apache.catalina.LifecycleException if this component detects a fatal error that prevents this component from being used
    public void start() throws LifecycleException {
        // Validate and update our current component state
        if ()
            throw new LifecycleException(.storeAlreadyStarted());
         = true;
    }


    
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.

Throws:
org.apache.catalina.LifecycleException if this component detects a fatal error that needs to be reported
    public void stop() throws LifecycleException {
        // Validate and update our current component state
        if (!)
            throw new LifecycleException(.storeNotStarted());
        .fireLifecycleEvent(null);
         = false;
    }
New to GrepCode? Check out our FAQ X