From: markt Date: Sat, 6 Mar 2010 12:02:19 +0000 (+0000) Subject: Lifecycle refactoring - Store X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=931370a9005e2871d6e2a585da95ac91fec5f21a;p=tomcat7.0 Lifecycle refactoring - Store Added toString() for use in Lifecycle error messages git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@919750 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/session/JDBCStore.java b/java/org/apache/catalina/session/JDBCStore.java index 11300dbe6..9d3925409 100644 --- a/java/org/apache/catalina/session/JDBCStore.java +++ b/java/org/apache/catalina/session/JDBCStore.java @@ -22,6 +22,8 @@ import org.apache.catalina.LifecycleException; 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 @@ public class JDBCStore extends StoreBase { } /** - * 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) { diff --git a/java/org/apache/catalina/session/LocalStrings.properties b/java/org/apache/catalina/session/LocalStrings.properties index 88b8c2c3d..0f7b85bc3 100644 --- a/java/org/apache/catalina/session/LocalStrings.properties +++ b/java/org/apache/catalina/session/LocalStrings.properties @@ -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} diff --git a/java/org/apache/catalina/session/LocalStrings_es.properties b/java/org/apache/catalina/session/LocalStrings_es.properties index 56135e9af..b94cfb359 100644 --- a/java/org/apache/catalina/session/LocalStrings_es.properties +++ b/java/org/apache/catalina/session/LocalStrings_es.properties @@ -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} diff --git a/java/org/apache/catalina/session/LocalStrings_fr.properties b/java/org/apache/catalina/session/LocalStrings_fr.properties index ee4eb3a8a..0db95aadc 100644 --- a/java/org/apache/catalina/session/LocalStrings_fr.properties +++ b/java/org/apache/catalina/session/LocalStrings_fr.properties @@ -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} diff --git a/java/org/apache/catalina/session/LocalStrings_ja.properties b/java/org/apache/catalina/session/LocalStrings_ja.properties index d270172af..368819ba0 100644 --- a/java/org/apache/catalina/session/LocalStrings_ja.properties +++ b/java/org/apache/catalina/session/LocalStrings_ja.properties @@ -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 diff --git a/java/org/apache/catalina/session/StoreBase.java b/java/org/apache/catalina/session/StoreBase.java index 5f3570d36..7892cc75f 100644 --- a/java/org/apache/catalina/session/StoreBase.java +++ b/java/org/apache/catalina/session/StoreBase.java @@ -21,12 +21,11 @@ import java.beans.PropertyChangeListener; 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 @@ import org.apache.tomcat.util.res.StringManager; * @version $Revision$, $Date$ */ -public abstract class StoreBase - implements Lifecycle, Store { +public abstract class StoreBase extends LifecycleBase implements Store { // ----------------------------------------------------- Instance Variables @@ -53,16 +51,6 @@ public abstract class StoreBase 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 abstract class StoreBase // --------------------------------------------------------- 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 abstract class StoreBase public void processExpires() { String[] keys = null; - if(!started) { + if(!getState().isAvailable()) { return; } @@ -224,45 +182,47 @@ public abstract class StoreBase } - // --------------------------------------------------------- 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. + * 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(); } - - }