You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2010/03/06 13:02:20 UTC

svn commit: r919750 - in /tomcat/trunk/java/org/apache/catalina/session: JDBCStore.java LocalStrings.properties LocalStrings_es.properties LocalStrings_fr.properties LocalStrings_ja.properties StoreBase.java

Author: markt
Date: Sat Mar  6 12:02:19 2010
New Revision: 919750

URL: http://svn.apache.org/viewvc?rev=919750&view=rev
Log:
Lifecycle refactoring - Store
Added toString() for use in Lifecycle error messages

Modified:
    tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java
    tomcat/trunk/java/org/apache/catalina/session/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/session/LocalStrings_es.properties
    tomcat/trunk/java/org/apache/catalina/session/LocalStrings_fr.properties
    tomcat/trunk/java/org/apache/catalina/session/LocalStrings_ja.properties
    tomcat/trunk/java/org/apache/catalina/session/StoreBase.java

Modified: tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java?rev=919750&r1=919749&r2=919750&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java (original)
+++ tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java Sat Mar  6 12:02:19 2010
@@ -22,6 +22,8 @@
 import org.apache.catalina.Loader;
 import org.apache.catalina.Session;
 import org.apache.catalina.util.CustomObjectInputStream;
+import org.apache.catalina.util.LifecycleBase;
+
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.ByteArrayInputStream;
@@ -959,24 +961,32 @@
     }
 
     /**
-     * Called once when this Store is first started.
+     * Start this component and implement the requirements
+     * of {@link LifecycleBase#startInternal()}.
+     *
+     * @exception LifecycleException if this component detects a fatal error
+     *  that prevents this component from being used
      */
     @Override
-    public void start() throws LifecycleException {
-        super.start();
+    protected synchronized void startInternal() throws LifecycleException {
 
         // Open connection to the database
         this.dbConnection = getConnection();
+        
+        super.startInternal();
     }
 
     /**
-     * Gracefully terminate everything associated with our db.
-     * Called once when this Store is stopping.
+     * Stop this component and implement the requirements
+     * of {@link LifecycleBase#stopInternal()}.
      *
+     * @exception LifecycleException if this component detects a fatal error
+     *  that prevents this component from being used
      */
     @Override
-    public void stop() throws LifecycleException {
-        super.stop();
+    protected synchronized void stopInternal() throws LifecycleException {
+        
+        super.stopInternal();
 
         // Close and release everything associated with our db.
         if (dbConnection != null) {

Modified: tomcat/trunk/java/org/apache/catalina/session/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/LocalStrings.properties?rev=919750&r1=919749&r2=919750&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/session/LocalStrings.properties Sat Mar  6 12:02:19 2010
@@ -15,14 +15,10 @@
 
 applicationSession.session.ise=invalid session state
 applicationSession.value.iae=null value
-fileStore.alreadyStarted=File Store has already been started
-fileStore.notStarted=File Store has not yet been started
 fileStore.saving=Saving Session {0} to file {1}
 fileStore.loading=Loading Session {0} from file {1}
 fileStore.removing=Removing Session {0} at file {1}
-JDBCStore.alreadyStarted=JDBC Store has already been started
 JDBCStore.close=Exception closing database connection {0}
-JDBCStore.notStarted=JDBC Store has not yet been started
 JDBCStore.saving=Saving Session {0} to database {1}
 JDBCStore.loading=Loading Session {0} from database {1}
 JDBCStore.removing=Removing Session {0} at database {1}

Modified: tomcat/trunk/java/org/apache/catalina/session/LocalStrings_es.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/LocalStrings_es.properties?rev=919750&r1=919749&r2=919750&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/LocalStrings_es.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/session/LocalStrings_es.properties Sat Mar  6 12:02:19 2010
@@ -14,14 +14,10 @@
 # limitations under the License.
 applicationSession.session.ise = estado inv\u00E1lido de sesi\u00F3n
 applicationSession.value.iae = valor nulo
-fileStore.alreadyStarted = Ya ha sido arrancado el Almac\u00E9n de Archivos
-fileStore.notStarted = A\u00FAn no se ha arrancado el Almac\u00E9n de Archivos
 fileStore.saving = Salvando Sesi\u00F3n {0} en archivo {1}
 fileStore.loading = Cargando Sesi\u00F3n {0} desde archivo {1}
 fileStore.removing = Quitando Sesi\u00F3n {0} en archivo {1}
-JDBCStore.alreadyStarted = Ya ha sido arrancado el Almac\u00E9n JDBC
 JDBCStore.close = Excepci\u00F3n cerrando conexi\u00F3n a base de datos {0}
-JDBCStore.notStarted = A\u00FAn no se ha arrancado el Almac\u00E9n JDBC
 JDBCStore.saving = Salvando Sesi\u00F3n {0} en base de datos {1}
 JDBCStore.loading = Cargando Sesi\u00F3n {0} desde base de datos {1}
 JDBCStore.removing = Quitando Sesi\u00F3n {0} en base de datos {1}

Modified: tomcat/trunk/java/org/apache/catalina/session/LocalStrings_fr.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/LocalStrings_fr.properties?rev=919750&r1=919749&r2=919750&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/LocalStrings_fr.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/session/LocalStrings_fr.properties Sat Mar  6 12:02:19 2010
@@ -15,13 +15,9 @@
 
 applicationSession.session.ise=\u00e9tat de session invalide
 applicationSession.value.iae=valeur nulle
-fileStore.alreadyStarted=Le "File Store" a d\u00e9j\u00e0 \u00e9t\u00e9 d\u00e9marr\u00e9
-fileStore.notStarted=Le "File Store" n''a pas encore \u00e9t\u00e9 d\u00e9marr\u00e9
 fileStore.saving=Sauvegarde de la Session {0} vers le fichier {1}
 fileStore.loading=Chargement de la Session {0} depuis le fichier {1}
 fileStore.removing=Retrait de la Session {0} du fichier {1}
-JDBCStore.alreadyStarted=Le "JDBC Store" a d\u00e9j\u00e0 \u00e9t\u00e9 d\u00e9marr\u00e9
-JDBCStore.notStarted=Le "JDBC Store" n''a pas encore \u00e9t\u00e9 d\u00e9marr\u00e9
 JDBCStore.saving=Sauvegarde de la Session {0} vers la base de donn\u00e9es {1}
 JDBCStore.loading=Chargement de la Session {0} depuis la base de donn\u00e9es {1}
 JDBCStore.removing=Retrait de la Session {0} de la base de donn\u00e9es {1}

Modified: tomcat/trunk/java/org/apache/catalina/session/LocalStrings_ja.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/LocalStrings_ja.properties?rev=919750&r1=919749&r2=919750&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/LocalStrings_ja.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/session/LocalStrings_ja.properties Sat Mar  6 12:02:19 2010
@@ -15,14 +15,10 @@
 
 applicationSession.session.ise=\u7121\u52b9\u306a\u30bb\u30c3\u30b7\u30e7\u30f3\u72b6\u614b\u3067\u3059
 applicationSession.value.iae=null\u5024\u3067\u3059
-fileStore.alreadyStarted=\u30d5\u30a1\u30a4\u30eb\u30b9\u30c8\u30a2\u304c\u65e2\u306b\u8d77\u52d5\u3055\u308c\u3066\u3044\u307e\u3059
-fileStore.notStarted=\u30d5\u30a1\u30a4\u30eb\u30b9\u30c8\u30a2\u304c\u307e\u3060\u8d77\u52d5\u3055\u308c\u3066\u3044\u307e\u305b\u3093
 fileStore.saving=\u30bb\u30c3\u30b7\u30e7\u30f3 {0} \u3092\u30d5\u30a1\u30a4\u30eb {1} \u306b\u4fdd\u5b58\u3057\u307e\u3059
 fileStore.loading=\u30bb\u30c3\u30b7\u30e7\u30f3 {0} \u3092\u30d5\u30a1\u30a4\u30eb {1} \u304b\u3089\u30ed\u30fc\u30c9\u3057\u307e\u3059
 fileStore.removing=\u30bb\u30c3\u30b7\u30e7\u30f3 {0} \u3092\u30d5\u30a1\u30a4\u30eb {1} \u304b\u3089\u524a\u9664\u3057\u307e\u3059
-JDBCStore.alreadyStarted=JDBC\u30b9\u30c8\u30a2\u306f\u65e2\u306b\u8d77\u52d5\u3055\u308c\u3066\u3044\u307e\u3059
 JDBCStore.close=\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u63a5\u7d9a {0} \u3092\u30af\u30ed\u30fc\u30ba\u4e2d\u306e\u4f8b\u5916\u3067\u3059
-JDBCStore.notStarted=JDBC\u30b9\u30c8\u30a2\u306f\u307e\u3060\u8d77\u52d5\u3055\u308c\u3066\u307e\u305b\u3093
 JDBCStore.saving=\u30bb\u30c3\u30b7\u30e7\u30f3 {0} \u3092\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9 {1} \u306b\u4fdd\u5b58\u3057\u307e\u3059
 JDBCStore.loading=\u30bb\u30c3\u30b7\u30e7\u30f3 {0} \u3092\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9 {1} \u304b\u3089\u30ed\u30fc\u30c9\u3057\u307e\u3059
 JDBCStore.removing= \u30bb\u30c3\u30b7\u30e7\u30f3 {0} \u3092\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9 {1} \u304b\u3089\u524a\u9664\u3057\u307e\u3059

Modified: tomcat/trunk/java/org/apache/catalina/session/StoreBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/StoreBase.java?rev=919750&r1=919749&r2=919750&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/StoreBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/session/StoreBase.java Sat Mar  6 12:02:19 2010
@@ -21,12 +21,11 @@
 import java.beans.PropertyChangeSupport;
 import java.io.IOException;
 
-import org.apache.catalina.Lifecycle;
 import org.apache.catalina.LifecycleException;
-import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.LifecycleState;
 import org.apache.catalina.Manager;
 import org.apache.catalina.Store;
-import org.apache.catalina.util.LifecycleSupport;
+import org.apache.catalina.util.LifecycleBase;
 import org.apache.tomcat.util.res.StringManager;
 
 /**
@@ -37,8 +36,7 @@
  * @version $Revision$, $Date$
  */
 
-public abstract class StoreBase
-    implements Lifecycle, Store {
+public abstract class StoreBase extends LifecycleBase implements Store {
 
     // ----------------------------------------------------- Instance Variables
 
@@ -53,16 +51,6 @@
     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);
@@ -117,36 +105,6 @@
     // --------------------------------------------------------- Public Methods
 
     /**
-     * Add a lifecycle event listener to this component.
-     *
-     * @param listener The listener to add
-     */
-    public void addLifecycleListener(LifecycleListener listener) {
-        lifecycle.addLifecycleListener(listener);
-    }
-
-
-    /**
-     * Get the lifecycle listeners associated with this lifecycle. If this 
-     * Lifecycle has no listeners registered, a zero-length array is returned.
-     */
-    public LifecycleListener[] findLifecycleListeners() {
-
-        return lifecycle.findLifecycleListeners();
-
-    }
-
-
-    /**
-     * Remove a lifecycle event listener from this component.
-     *
-     * @param listener The listener to add
-     */
-    public void removeLifecycleListener(LifecycleListener listener) {
-        lifecycle.removeLifecycleListener(listener);
-    }
-
-    /**
      * Add a property change listener to this component.
      *
      * @param listener a value of type 'PropertyChangeListener'
@@ -175,7 +133,7 @@
     public void processExpires() {
         String[] keys = null;
 
-        if(!started) {
+        if(!getState().isAvailable()) {
             return;
         }
 
@@ -224,45 +182,47 @@
     }
 
 
-    // --------------------------------------------------------- Thread Methods
-
-
     /**
-     * Prepare for the beginning of active use of the public methods of this
-     * component.  This method should be called after <code>configure()</code>,
-     * and before any of the public methods of the component are utilized.
+     * Start this component and implement the requirements
+     * of {@link LifecycleBase#startInternal()}.
      *
      * @exception 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 (started)
-            throw new LifecycleException
-                (sm.getString(getStoreName()+".alreadyStarted"));
-        lifecycle.fireLifecycleEvent(START_EVENT, null);
-        started = true;
-
+    @Override
+    protected synchronized void startInternal() throws LifecycleException {
+        
+        setState(LifecycleState.STARTING);
     }
 
 
     /**
-     * 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.
+     * Stop this component and implement the requirements
+     * of {@link LifecycleBase#stopInternal()}.
      *
      * @exception LifecycleException if this component detects a fatal error
-     *  that needs to be reported
+     *  that prevents this component from being used
      */
-    public void stop() throws LifecycleException {
-        // Validate and update our current component state
-        if (!started)
-            throw new LifecycleException
-                (sm.getString(getStoreName()+".notStarted"));
-        lifecycle.fireLifecycleEvent(STOP_EVENT, null);
-        started = false;
+    @Override
+    protected synchronized void stopInternal() throws LifecycleException {
 
+        setState(LifecycleState.STOPPING);
+    }
+    
+    
+    /**
+     * Return a String rendering of this object.
+     */
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder(this.getClass().getName());
+        sb.append('[');
+        if (manager == null) {
+            sb.append("Manager is null");
+        } else {
+            sb.append(manager);
+        }
+        sb.append(']');
+        return sb.toString();
     }
-
-
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org