From 7b8df5f2408f47c4ebd7211171b59578d1ae310d Mon Sep 17 00:00:00 2001 From: markt Date: Sat, 6 Mar 2010 09:31:47 +0000 Subject: [PATCH] Lifecycle refactoring - Valves Most valves were firing the LifecycleState.STARTING event too early Make the toString() consistent for all Valves Some copy and paste errors in i18n start/stop messages are fixed as a side effect. Some unused messages were also removed. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@919723 13f79535-47bb-0310-9956-ffa450edef68 --- .../catalina/authenticator/AuthenticatorBase.java | 98 +++-------------- .../catalina/authenticator/LocalStrings.properties | 2 - .../authenticator/LocalStrings_es.properties | 3 +- .../authenticator/LocalStrings_fr.properties | 2 - .../authenticator/LocalStrings_ja.properties | 2 - .../catalina/authenticator/SSLAuthenticator.java | 36 ------- .../catalina/authenticator/SingleSignOn.java | 116 +-------------------- .../ha/authenticator/ClusterSingleSignOn.java | 64 ++++-------- .../catalina/ha/session/JvmRouteBinderValve.java | 106 +++++-------------- .../catalina/ha/session/LocalStrings.properties | 2 - .../catalina/ha/session/LocalStrings_es.properties | 2 - .../apache/catalina/ha/tcp/ReplicationValve.java | 13 --- .../org/apache/catalina/valves/AccessLogValve.java | 93 ++++------------- .../valves/CometConnectionManagerValve.java | 97 +++-------------- .../apache/catalina/valves/ErrorReportValve.java | 4 +- .../apache/catalina/valves/JDBCAccessLogValve.java | 97 ++++------------- .../apache/catalina/valves/LocalStrings.properties | 8 -- .../catalina/valves/LocalStrings_es.properties | 8 -- .../catalina/valves/LocalStrings_fr.properties | 6 -- .../catalina/valves/LocalStrings_ja.properties | 6 -- .../apache/catalina/valves/PersistentValve.java | 3 +- .../org/apache/catalina/valves/SemaphoreValve.java | 103 +++--------------- java/org/apache/catalina/valves/ValveBase.java | 44 +++++++- 23 files changed, 174 insertions(+), 741 deletions(-) diff --git a/java/org/apache/catalina/authenticator/AuthenticatorBase.java b/java/org/apache/catalina/authenticator/AuthenticatorBase.java index 558c14d2f..5caed3f34 100644 --- a/java/org/apache/catalina/authenticator/AuthenticatorBase.java +++ b/java/org/apache/catalina/authenticator/AuthenticatorBase.java @@ -35,9 +35,7 @@ import javax.servlet.http.HttpServletResponse; import org.apache.catalina.Authenticator; import org.apache.catalina.Container; import org.apache.catalina.Context; -import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleException; -import org.apache.catalina.LifecycleListener; import org.apache.catalina.Manager; import org.apache.catalina.Pipeline; import org.apache.catalina.Realm; @@ -48,7 +46,7 @@ import org.apache.catalina.connector.Response; import org.apache.catalina.deploy.LoginConfig; import org.apache.catalina.deploy.SecurityConstraint; import org.apache.catalina.util.DateTool; -import org.apache.catalina.util.LifecycleSupport; +import org.apache.catalina.util.LifecycleBase; import org.apache.tomcat.util.res.StringManager; import org.apache.catalina.valves.ValveBase; import org.apache.juli.logging.Log; @@ -76,9 +74,9 @@ import org.apache.juli.logging.LogFactory; */ -public abstract class AuthenticatorBase - extends ValveBase - implements Authenticator, Lifecycle { +public abstract class AuthenticatorBase extends ValveBase + implements Authenticator { + private static final Log log = LogFactory.getLog(AuthenticatorBase.class); @@ -168,12 +166,6 @@ public abstract class AuthenticatorBase protected boolean securePagesWithPragma = true; /** - * The lifecycle event support for this component. - */ - protected LifecycleSupport lifecycle = new LifecycleSupport(this); - - - /** * A random number generator to use when generating session identifiers. */ protected Random random = null; @@ -201,12 +193,6 @@ public abstract class AuthenticatorBase /** - * Has this component been started? - */ - protected boolean started = false; - - - /** * "Expires" header always set to Date(1), so generate once only */ private static final String DATE_ONE = @@ -836,61 +822,16 @@ public abstract class AuthenticatorBase } - // ------------------------------------------------------ Lifecycle 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 remove - */ - public void removeLifecycleListener(LifecycleListener listener) { - - lifecycle.removeLifecycleListener(listener); - - } - - - /** - * 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("authenticator.alreadyStarted")); - lifecycle.fireLifecycleEvent(START_EVENT, null); - started = true; - + @Override + protected synchronized void startInternal() throws LifecycleException { + // Look up the SingleSignOn implementation in our request processing // path, if there is one Container parent = context.getParent(); @@ -916,29 +857,22 @@ public abstract class AuthenticatorBase log.debug("No SingleSignOn Valve is present"); } + super.startInternal(); } /** - * 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 { + @Override + protected synchronized void stopInternal() throws LifecycleException { - // Validate and update our current component state - if (!started) - throw new LifecycleException - (sm.getString("authenticator.notStarted")); - lifecycle.fireLifecycleEvent(STOP_EVENT, null); - started = false; + super.stopInternal(); sso = null; - } - - } diff --git a/java/org/apache/catalina/authenticator/LocalStrings.properties b/java/org/apache/catalina/authenticator/LocalStrings.properties index e96e5ed1c..37dda3111 100644 --- a/java/org/apache/catalina/authenticator/LocalStrings.properties +++ b/java/org/apache/catalina/authenticator/LocalStrings.properties @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -authenticator.alreadyStarted=Security Interceptor has already been started authenticator.certificates=No client certificate chain in this request authenticator.forbidden=Access to the requested resource has been denied authenticator.formlogin=Invalid direct reference to form login page @@ -22,7 +21,6 @@ authenticator.keystore=Exception loading key store authenticator.manager=Exception initializing trust managers authenticator.notAuthenticated=Configuration error: Cannot perform access control without an authenticated principal authenticator.notContext=Configuration error: Must be attached to a Context -authenticator.notStarted=Security Interceptor has not yet been started authenticator.requestBodyTooBig=The request body was too large to be cached during the authentication process authenticator.sessionExpired=The time allowed for the login process has been exceeded. If you wish to continue you must either click back twice and re-click the link you requested or close and re-open your browser authenticator.unauthorized=Cannot authenticate with the provided credentials diff --git a/java/org/apache/catalina/authenticator/LocalStrings_es.properties b/java/org/apache/catalina/authenticator/LocalStrings_es.properties index 0997f889f..8cabcfc99 100644 --- a/java/org/apache/catalina/authenticator/LocalStrings_es.properties +++ b/java/org/apache/catalina/authenticator/LocalStrings_es.properties @@ -12,7 +12,7 @@ # 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. -authenticator.alreadyStarted = El interceptor de seguridad ya ha sido arrancado + authenticator.certificates = No hay cadena de certificados del cliente en esta petici\u00F3n authenticator.forbidden = El acceso al recurso pedido ha sido denegado authenticator.formlogin = Referencia directa al formulario de conexi\u00F3n (p\u00E1gina de formulario de login) inv\u00E1lida @@ -21,7 +21,6 @@ authenticator.keystore = Excepci\u00F3n cargando el almac\u00E9n de claves authenticator.manager = Excepci\u00F3n inicializando administradores de confianza authenticator.notAuthenticated = Error de Configuraci\u00F3n\: No se pueden realizar funciones de control de acceso sin un principal autenticado authenticator.notContext = Error de Configuraci\u00F3n\: Debe de estar unido a un Contexto -authenticator.notStarted = El Interceptor de seguridad no sido a\u00FAn iniciado authenticator.requestBodyTooBig = El cuerpo del requerimiento era demasiado grande para realizar cach\u00E9 durante el proceso de autenticaci\u00F3n authenticator.sessionExpired = El tiempo permitido para realizar login ha sido excedido. Si deseas continuar, debes hacer clik dos veces y volver a hacer clik otra vez o cerrar y reabrir tu navegador authenticator.unauthorized = Imposible autenticar mediante las credenciales suministradas diff --git a/java/org/apache/catalina/authenticator/LocalStrings_fr.properties b/java/org/apache/catalina/authenticator/LocalStrings_fr.properties index a13d48663..3303ae6b9 100644 --- a/java/org/apache/catalina/authenticator/LocalStrings_fr.properties +++ b/java/org/apache/catalina/authenticator/LocalStrings_fr.properties @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -authenticator.alreadyStarted=L''intercepteur de s\u00e9curit\u00e9 (security interceptor) a d\u00e9j\u00e0 \u00e9t\u00e9 d\u00e9marr\u00e9 authenticator.certificates=Aucune cha\u00eene de certificat client (client certificate chain) dans cette requ\u00eate authenticator.forbidden=L''acc\u00e8s \u00e0 la ressource demand\u00e9e a \u00e9t\u00e9 interdit authenticator.formlogin=R\u00e9f\u00e9rence directe \u00e0 la form de connexion (form login page) invalide @@ -22,6 +21,5 @@ authenticator.keystore=Exception lors du chargement du r\u00e9f\u00e9rentiel de authenticator.manager=Exception lors de l''initialisation des gestionnaires d''authentification (trust managers) authenticator.notAuthenticated=Erreur de configuration: Impossible de proc\u00e9der \u00e0 un contr\u00f4le d''acc\u00e8s sans un principal authentifi\u00e9 (authenticated principal) authenticator.notContext=Erreur de configuration: Doit \u00eatre attach\u00e9 \u00e0 un contexte -authenticator.notStarted=L''intercepteur de s\u00e9curit\u00e9 (security interceptor) n''a pas encore \u00e9t\u00e9 d\u00e9marr\u00e9 authenticator.unauthorized=Impossible d''authentifier avec les cr\u00e9dits fournis (provided credentials) authenticator.userDataConstraint=Cette requ\u00eate viole une contrainte donn\u00e9e utilisateur (user data constraint) pour cette application diff --git a/java/org/apache/catalina/authenticator/LocalStrings_ja.properties b/java/org/apache/catalina/authenticator/LocalStrings_ja.properties index 2363fc579..ec5fbf34d 100644 --- a/java/org/apache/catalina/authenticator/LocalStrings_ja.properties +++ b/java/org/apache/catalina/authenticator/LocalStrings_ja.properties @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -authenticator.alreadyStarted=\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u30a4\u30f3\u30bf\u30fc\u30bb\u30d7\u30bf\u306f\u65e2\u306b\u8d77\u52d5\u3055\u308c\u3066\u3044\u307e\u3059 authenticator.certificates=\u3053\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u306b\u306f\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u8a8d\u8a3c\u30c1\u30a7\u30fc\u30f3\u304c\u3042\u308a\u307e\u305b\u3093 authenticator.forbidden=\u30ea\u30af\u30a8\u30b9\u30c8\u3055\u308c\u305f\u30ea\u30bd\u30fc\u30b9\u3078\u306e\u30a2\u30af\u30bb\u30b9\u304c\u62d2\u5426\u3055\u308c\u307e\u3057\u305f authenticator.formlogin=\u30d5\u30a9\u30fc\u30e0\u30ed\u30b0\u30a4\u30f3\u30da\u30fc\u30b8\u3078\u306e\u7121\u52b9\u306a\u76f4\u63a5\u53c2\u7167\u3067\u3059 @@ -22,7 +21,6 @@ authenticator.keystore=\u30ad\u30fc\u30b9\u30c8\u30a2\u3092\u30ed\u30fc\u30c9\u4 authenticator.manager=\u30c8\u30e9\u30b9\u30c8\u30de\u30cd\u30fc\u30b8\u30e3\u3092\u521d\u671f\u5316\u4e2d\u306e\u4f8b\u5916\u3067\u3059 authenticator.notAuthenticated=\u8a2d\u5b9a\u30a8\u30e9\u30fc: \u8a8d\u8a3c\u3055\u308c\u305f\u4e3b\u4f53\u306a\u3057\u306b\u30a2\u30af\u30bb\u30b9\u5236\u5fa1\u3092\u5b9f\u884c\u3067\u304d\u307e\u305b\u3093 authenticator.notContext=\u8a2d\u5b9a\u30a8\u30e9\u30fc: \u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u306b\u6307\u5b9a\u3057\u306a\u3051\u308c\u3070\u3044\u3051\u307e\u305b\u3093 -authenticator.notStarted=\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u30a4\u30f3\u30bf\u30fc\u30bb\u30d7\u30bf\u306f\u307e\u3060\u8d77\u52d5\u3055\u308c\u3066\u3044\u307e\u305b\u3093 authenticator.sessionExpired=\u30ed\u30b0\u30a4\u30f3\u30d7\u30ed\u30bb\u30b9\u306b\u8a8d\u3081\u3089\u308c\u3066\u3044\u305f\u6642\u9593\u304c\u904e\u304e\u307e\u3057\u305f\u3002\u7d99\u7d9a\u3057\u305f\u3044\u306a\u3089\u3070\uff0c\u30d0\u30c3\u30af\u30dc\u30bf\u30f3\u30922\u5ea6\u62bc\u3057\u3066\u304b\u3089\u518d\u5ea6\u30ea\u30f3\u30af\u3092\u62bc\u3059\u304b\uff0c\u30d6\u30e9\u30a6\u30b6\u3092\u7acb\u3061\u4e0a\u3052\u76f4\u3057\u3066\u304f\u3060\u3055\u3044 authenticator.unauthorized=\u7528\u610f\u3055\u308c\u305f\u8a3c\u660e\u66f8\u3067\u8a8d\u8a3c\u3067\u304d\u307e\u305b\u3093 authenticator.userDataConstraint=\u3053\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u306f\u3001\u3053\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30e6\u30fc\u30b6\u30c7\u30fc\u30bf\u306e\u5236\u9650\u306b\u9055\u53cd\u3057\u3066\u3044\u307e\u3059 diff --git a/java/org/apache/catalina/authenticator/SSLAuthenticator.java b/java/org/apache/catalina/authenticator/SSLAuthenticator.java index e696f4f7f..0bc2e0d16 100644 --- a/java/org/apache/catalina/authenticator/SSLAuthenticator.java +++ b/java/org/apache/catalina/authenticator/SSLAuthenticator.java @@ -27,7 +27,6 @@ import javax.servlet.http.HttpServletResponse; import org.apache.coyote.ActionCode; import org.apache.catalina.Globals; -import org.apache.catalina.LifecycleException; import org.apache.catalina.connector.Request; import org.apache.catalina.deploy.LoginConfig; @@ -162,39 +161,4 @@ public class SSLAuthenticator return (true); } - - - // ------------------------------------------------------ Lifecycle Methods - - - /** - * Initialize the database we will be using for client verification - * and certificate validation (if any). - * - * @exception LifecycleException if this component detects a fatal error - * that prevents this component from being used - */ - @Override - public void start() throws LifecycleException { - - super.start(); - - } - - - /** - * Finalize the database we used for client verification and - * certificate validation (if any). - * - * @exception LifecycleException if this component detects a fatal error - * that prevents this component from being used - */ - @Override - public void stop() throws LifecycleException { - - super.stop(); - - } - - } diff --git a/java/org/apache/catalina/authenticator/SingleSignOn.java b/java/org/apache/catalina/authenticator/SingleSignOn.java index 6a4d6ce33..026d7585b 100644 --- a/java/org/apache/catalina/authenticator/SingleSignOn.java +++ b/java/org/apache/catalina/authenticator/SingleSignOn.java @@ -27,16 +27,12 @@ import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.Cookie; -import org.apache.catalina.Lifecycle; -import org.apache.catalina.LifecycleException; -import org.apache.catalina.LifecycleListener; import org.apache.catalina.Realm; import org.apache.catalina.Session; import org.apache.catalina.SessionEvent; import org.apache.catalina.SessionListener; import org.apache.catalina.connector.Request; import org.apache.catalina.connector.Response; -import org.apache.catalina.util.LifecycleSupport; import org.apache.tomcat.util.res.StringManager; import org.apache.catalina.valves.ValveBase; @@ -62,9 +58,7 @@ import org.apache.catalina.valves.ValveBase; * @version $Revision$ $Date$ */ -public class SingleSignOn - extends ValveBase - implements Lifecycle, SessionListener { +public class SingleSignOn extends ValveBase implements SessionListener { //------------------------------------------------------ Constructor public SingleSignOn() { @@ -90,11 +84,6 @@ public class SingleSignOn /** - * The lifecycle event support for this component. - */ - protected LifecycleSupport lifecycle = new LifecycleSupport(this); - - /** * Indicates whether this valve should require a downstream Authenticator to * reauthenticate each request, or if it itself can bind a UserPrincipal * and AuthType object to the request. @@ -116,11 +105,6 @@ public class SingleSignOn /** - * Component started flag. - */ - protected boolean started = false; - - /** * Optional SSO cookie domain. */ private String cookieDomain; @@ -217,84 +201,6 @@ public class SingleSignOn } - // ------------------------------------------------------ Lifecycle 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 remove - */ - public void removeLifecycleListener(LifecycleListener listener) { - - lifecycle.removeLifecycleListener(listener); - - } - - - /** - * 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 - */ - public void start() throws LifecycleException { - - // Validate and update our current component state - if (started) - throw new LifecycleException - (sm.getString("authenticator.alreadyStarted")); - lifecycle.fireLifecycleEvent(START_EVENT, null); - started = 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. - * - * @exception 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 (!started) - throw new LifecycleException - (sm.getString("authenticator.notStarted")); - lifecycle.fireLifecycleEvent(STOP_EVENT, null); - started = false; - - } - - // ------------------------------------------------ SessionListener Methods @@ -429,26 +335,6 @@ public class SingleSignOn } - // --------------------------------------------------------- Public Methods - - - /** - * Return a String rendering of this object. - */ - @Override - public String toString() { - - StringBuilder sb = new StringBuilder("SingleSignOn["); - if (container == null ) - sb.append("Container is null"); - else - sb.append(container.getName()); - sb.append("]"); - return (sb.toString()); - - } - - // ------------------------------------------------------ Protected Methods diff --git a/java/org/apache/catalina/ha/authenticator/ClusterSingleSignOn.java b/java/org/apache/catalina/ha/authenticator/ClusterSingleSignOn.java index 0801fc42a..3e627c718 100644 --- a/java/org/apache/catalina/ha/authenticator/ClusterSingleSignOn.java +++ b/java/org/apache/catalina/ha/authenticator/ClusterSingleSignOn.java @@ -31,6 +31,7 @@ import org.apache.catalina.Session; import org.apache.catalina.authenticator.SingleSignOn; import org.apache.catalina.ha.CatalinaCluster; import org.apache.catalina.ha.ClusterManager; +import org.apache.catalina.util.LifecycleBase; @@ -105,20 +106,17 @@ public class ClusterSingleSignOn /** - * 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 */ @Override - public void start() throws LifecycleException { - - super.start(); - - clusterSSOListener = new ClusterSingleSignOnListener(); - clusterSSOListener.setClusterSSO(this); + protected synchronized void startInternal() throws LifecycleException { + + clusterSSOListener = new ClusterSingleSignOnListener(); + clusterSSOListener.setClusterSSO(this); // Load the cluster component, if any try { @@ -147,55 +145,33 @@ public class ClusterSingleSignOn } } if (cluster == null) { - throw new LifecycleException - ("There is no Cluster for ClusterSingleSignOn"); + throw new LifecycleException( + "There is no Cluster for ClusterSingleSignOn"); } - } catch (Throwable t) { - throw new LifecycleException - ("ClusterSingleSignOn exception during clusterLoad " + t); + throw new LifecycleException( + "ClusterSingleSignOn exception during clusterLoad " + t); } + super.startInternal(); } /** - * 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 - */ - @Override - public void stop() throws LifecycleException { - - super.stop(); - - if (getCluster() != null) { - getCluster().removeClusterListener(clusterSSOListener); - } - - } - - - // --------------------------------------------------------- Public Methods - - - /** - * Return a String rendering of this object. + * that prevents this component from being used */ @Override - public String toString() { + protected synchronized void stopInternal() throws LifecycleException { - StringBuilder sb = new StringBuilder("ClusterSingleSignOn["); - if (container == null ) - sb.append("Container is null"); - else - sb.append(container.getName()); - sb.append("]"); - return (sb.toString()); + super.stopInternal(); + if (getCluster() != null) { + getCluster().removeClusterListener(clusterSSOListener); + } } diff --git a/java/org/apache/catalina/ha/session/JvmRouteBinderValve.java b/java/org/apache/catalina/ha/session/JvmRouteBinderValve.java index cb1bb19e2..410e04361 100644 --- a/java/org/apache/catalina/ha/session/JvmRouteBinderValve.java +++ b/java/org/apache/catalina/ha/session/JvmRouteBinderValve.java @@ -24,9 +24,7 @@ import org.apache.catalina.Container; import org.apache.catalina.Context; import org.apache.catalina.Engine; import org.apache.catalina.Host; -import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleException; -import org.apache.catalina.LifecycleListener; import org.apache.catalina.Manager; import org.apache.catalina.Session; import org.apache.catalina.ha.CatalinaCluster; @@ -38,7 +36,7 @@ import org.apache.catalina.connector.Request; import org.apache.catalina.connector.Response; import org.apache.catalina.session.ManagerBase; import org.apache.catalina.session.PersistentManager; -import org.apache.catalina.util.LifecycleSupport; +import org.apache.catalina.util.LifecycleBase; import org.apache.tomcat.util.res.StringManager; import org.apache.catalina.valves.ValveBase; @@ -94,7 +92,7 @@ import org.apache.catalina.valves.ValveBase; * @author Peter Rossbach * @version $Revision$ $Date$ */ -public class JvmRouteBinderValve extends ValveBase implements ClusterValve, Lifecycle { +public class JvmRouteBinderValve extends ValveBase implements ClusterValve { /*--Static Variables----------------------------------------*/ public static final org.apache.juli.logging.Log log = org.apache.juli.logging.LogFactory @@ -123,11 +121,6 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve, Life protected static final StringManager sm = StringManager.getManager(Constants.Package); /** - * Has this component been started yet? - */ - protected boolean started = false; - - /** * enabled this component */ protected boolean enabled = true; @@ -139,10 +132,6 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve, Life protected String sessionIdAttribute = "org.apache.catalina.ha.session.JvmRouteOrignalSessionID"; - /** - * The lifecycle event support for this component. - */ - protected LifecycleSupport lifecycle = new LifecycleSupport(this); /*--Logic---------------------------------------------------*/ @@ -370,8 +359,7 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve, Life */ protected void changeSessionID(Request request, String sessionId, String newSessionID, Session catalinaSession) { - lifecycle.fireLifecycleEvent("Before session migration", - catalinaSession); + fireLifecycleEvent("Before session migration", catalinaSession); // FIXME: setId trigger session Listener, but only chance to register manager with correct id! catalinaSession.setId(newSessionID); // FIXME: Why we remove change data from other running request? @@ -386,7 +374,7 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve, Life sendSessionIDClusterBackup(manager,request,sessionId, newSessionID); } - lifecycle.fireLifecycleEvent("After session migration", catalinaSession); + fireLifecycleEvent("After session migration", catalinaSession); if (log.isDebugEnabled()) { log.debug(sm.getString("jvmRoute.changeSession", sessionId, newSessionID)); @@ -439,59 +427,16 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve, Life cluster.send(msg); } - // ------------------------------------------------------ Lifecycle 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 + * 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 removeLifecycleListener(LifecycleListener listener) { - - lifecycle.removeLifecycleListener(listener); - - } - - /** - * 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 - */ - public void start() throws LifecycleException { - - // Validate and update our current component state - if (started) - throw new LifecycleException(sm - .getString("jvmRoute.valve.alreadyStarted")); - lifecycle.fireLifecycleEvent(START_EVENT, null); - started = true; + @Override + protected synchronized void startInternal() throws LifecycleException { + if (cluster == null) { Container hostContainer = getContainer(); // compatibility with JvmRouteBinderValve version 1.1 @@ -519,25 +464,22 @@ public class JvmRouteBinderValve extends ValveBase implements ClusterValve, Life log.info(sm.getString("jvmRoute.noCluster")); } + super.startInternal(); } + /** - * 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 + * 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 */ - public void stop() throws LifecycleException { - - // Validate and update our current component state - if (!started) - throw new LifecycleException(sm - .getString("jvmRoute.valve.notStarted")); - lifecycle.fireLifecycleEvent(STOP_EVENT, null); - started = false; + @Override + protected synchronized void stopInternal() throws LifecycleException { + + super.stopInternal(); + cluster = null; numberOfSessions = 0; if (log.isInfoEnabled()) diff --git a/java/org/apache/catalina/ha/session/LocalStrings.properties b/java/org/apache/catalina/ha/session/LocalStrings.properties index 5dc3f3522..3b52609fa 100644 --- a/java/org/apache/catalina/ha/session/LocalStrings.properties +++ b/java/org/apache/catalina/ha/session/LocalStrings.properties @@ -85,8 +85,6 @@ jvmRoute.receiveMessage.sessionIDChanged=Cluster JvmRouteSessionIDBinderListener jvmRoute.run.already=jvmRoute SessionID receiver run already jvmRoute.skipURLSessionIDs=Skip reassign jvm route check, sessionid comes from URL! jvmRoute.turnoverInfo=Turnover Check time {0} msec -jvmRoute.valve.alreadyStarted=jvmRoute backup sessionID correction is started -jvmRoute.valve.notStarted=jvmRoute backup sessionID correction run already jvmRoute.valve.started=JvmRouteBinderValve started jvmRoute.valve.stopped=JvmRouteBinderValve stopped jvmRoute.set.orignalsessionid=Set Orginal Session id at request attriute {0} value: {1} diff --git a/java/org/apache/catalina/ha/session/LocalStrings_es.properties b/java/org/apache/catalina/ha/session/LocalStrings_es.properties index 1eef9f058..42fcbfb68 100644 --- a/java/org/apache/catalina/ha/session/LocalStrings_es.properties +++ b/java/org/apache/catalina/ha/session/LocalStrings_es.properties @@ -84,8 +84,6 @@ jvmRoute.receiveMessage.sessionIDChanged = Cl\u00FAster JvmRouteSessionIDBinderL jvmRoute.run.already = receptor jvmRoute SessionID ya ejecutado jvmRoute.skipURLSessionIDs = \u00A1Saltado chequeo de reasignaci\u00F3n de ruta jvm, la sessionid viene desde URL\! jvmRoute.turnoverInfo = Ajustado tiempo de Chequeo a {0} mseg -jvmRoute.valve.alreadyStarted = se ha iniciado la correcci\u00F3n de respaldo de sessionID de jvmRoute -jvmRoute.valve.notStarted = ya se ha iniciado la correcci\u00F3n de respaldo de sessionID de jvmRoute jvmRoute.valve.started = JvmRouteBinderValve arrancada jvmRoute.valve.stopped = JvmRouteBinderValve parada jvmRoute.set.orignalsessionid = Puesta id Orginal de Sesi\u00F3n en atributo de requerimiento {0} valor\: {1} diff --git a/java/org/apache/catalina/ha/tcp/ReplicationValve.java b/java/org/apache/catalina/ha/tcp/ReplicationValve.java index c4898d938..bd4146e66 100644 --- a/java/org/apache/catalina/ha/tcp/ReplicationValve.java +++ b/java/org/apache/catalina/ha/tcp/ReplicationValve.java @@ -397,19 +397,6 @@ public class ReplicationValve nrOfCrossContextSendRequests = 0; } - /** - * Return a String rendering of this object. - */ - @Override - public String toString() { - - StringBuilder sb = new StringBuilder("ReplicationValve["); - if (container != null) - sb.append(container.getName()); - sb.append("]"); - return (sb.toString()); - - } // --------------------------------------------------------- Protected Methods diff --git a/java/org/apache/catalina/valves/AccessLogValve.java b/java/org/apache/catalina/valves/AccessLogValve.java index 05e54a30e..5bae26b6c 100644 --- a/java/org/apache/catalina/valves/AccessLogValve.java +++ b/java/org/apache/catalina/valves/AccessLogValve.java @@ -36,12 +36,11 @@ import javax.servlet.ServletException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpSession; -import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleException; -import org.apache.catalina.LifecycleListener; +import org.apache.catalina.LifecycleState; import org.apache.catalina.connector.Request; import org.apache.catalina.connector.Response; -import org.apache.catalina.util.LifecycleSupport; +import org.apache.catalina.util.LifecycleBase; import org.apache.tomcat.util.res.StringManager; import org.apache.coyote.RequestInfo; import org.apache.juli.logging.Log; @@ -119,9 +118,7 @@ import org.apache.juli.logging.LogFactory; * @version $Revision$ $Date$ */ -public class AccessLogValve - extends ValveBase - implements Lifecycle { +public class AccessLogValve extends ValveBase { private static final Log log = LogFactory.getLog(AccessLogValve.class); @@ -154,12 +151,6 @@ public class AccessLogValve /** - * The lifecycle event support for this component. - */ - protected LifecycleSupport lifecycle = new LifecycleSupport(this); - - - /** * The set of month abbreviations for log messages. */ protected static final String months[] = @@ -204,12 +195,6 @@ public class AccessLogValve /** - * Has this component been started yet? - */ - protected boolean started = false; - - - /** * The suffix that is added to log file filenames. */ protected String suffix = ""; @@ -539,7 +524,8 @@ public class AccessLogValve */ @Override public void backgroundProcess() { - if (started && getEnabled() && writer != null && buffered) { + if (getState().isAvailable() && getEnabled() && writer != null && + buffered) { writer.flush(); } } @@ -558,7 +544,7 @@ public class AccessLogValve public void invoke(Request request, Response response) throws IOException, ServletException { - if (started && getEnabled()) { + if (getState().isAvailable() && getEnabled()) { // Pass this request on to the next valve in our pipeline long t1 = System.currentTimeMillis(); @@ -799,54 +785,15 @@ public class AccessLogValve } - // ------------------------------------------------------ Lifecycle 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); - } - - - /** - * 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("accessLogValve.alreadyStarted")); - lifecycle.fireLifecycleEvent(START_EVENT, null); - started = true; + @Override + protected synchronized void startInternal() throws LifecycleException { // Initialize the timeZone, Date formatters, and currentDate timezone = TimeZone.getDefault(); @@ -860,26 +807,22 @@ public class AccessLogValve fileDateFormatter.setTimeZone(timezone); dateStamp = fileDateFormatter.format(currentDateStruct.get().currentDate); open(); + + 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("accessLogValve.notStarted")); - lifecycle.fireLifecycleEvent(STOP_EVENT, null); - started = false; + @Override + protected synchronized void stopInternal() throws LifecycleException { + setState(LifecycleState.STOPPING); close(); } diff --git a/java/org/apache/catalina/valves/CometConnectionManagerValve.java b/java/org/apache/catalina/valves/CometConnectionManagerValve.java index 0ce5e9590..58025f819 100644 --- a/java/org/apache/catalina/valves/CometConnectionManagerValve.java +++ b/java/org/apache/catalina/valves/CometConnectionManagerValve.java @@ -35,12 +35,13 @@ import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleEvent; import org.apache.catalina.LifecycleException; import org.apache.catalina.LifecycleListener; +import org.apache.catalina.LifecycleState; import org.apache.catalina.comet.CometEvent; import org.apache.catalina.comet.CometProcessor; import org.apache.catalina.connector.CometEventImpl; import org.apache.catalina.connector.Request; import org.apache.catalina.connector.Response; -import org.apache.catalina.util.LifecycleSupport; +import org.apache.catalina.util.LifecycleBase; import org.apache.tomcat.util.res.StringManager; @@ -54,9 +55,8 @@ import org.apache.tomcat.util.res.StringManager; * @version $Revision$ $Date$ */ -public class CometConnectionManagerValve - extends ValveBase - implements Lifecycle, HttpSessionListener, LifecycleListener { +public class CometConnectionManagerValve extends ValveBase + implements HttpSessionListener, LifecycleListener { //------------------------------------------------------ Constructor public CometConnectionManagerValve() { @@ -82,18 +82,6 @@ public class CometConnectionManagerValve /** - * The lifecycle event support for this component. - */ - protected LifecycleSupport lifecycle = new LifecycleSupport(this); - - - /** - * Has this component been started yet? - */ - protected boolean started = false; - - - /** * List of current Comet connections. */ protected List cometRequests = @@ -107,92 +95,39 @@ public class CometConnectionManagerValve "org.apache.tomcat.comet.connectionList"; - // ------------------------------------------------------------- Properties - - - // ------------------------------------------------------ Lifecycle 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); - - } - - - /** - * 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("semaphoreValve.alreadyStarted")); - lifecycle.fireLifecycleEvent(START_EVENT, null); - started = true; + @Override + protected synchronized void startInternal() throws LifecycleException { if (container instanceof Context) { container.addLifecycleListener(this); } - + + 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 { + @Override + protected synchronized void stopInternal() throws LifecycleException { - // Validate and update our current component state - if (!started) - throw new LifecycleException - (sm.getString("semaphoreValve.notStarted")); - lifecycle.fireLifecycleEvent(STOP_EVENT, null); - started = false; + setState(LifecycleState.STOPPING); if (container instanceof Context) { container.removeLifecycleListener(this); } - } diff --git a/java/org/apache/catalina/valves/ErrorReportValve.java b/java/org/apache/catalina/valves/ErrorReportValve.java index bc663a283..e381ce612 100644 --- a/java/org/apache/catalina/valves/ErrorReportValve.java +++ b/java/org/apache/catalina/valves/ErrorReportValve.java @@ -48,8 +48,7 @@ import org.apache.tomcat.util.res.StringManager; * @version $Revision$ $Date$ */ -public class ErrorReportValve - extends ValveBase { +public class ErrorReportValve extends ValveBase { //------------------------------------------------------ Constructor public ErrorReportValve() { @@ -296,5 +295,4 @@ public class ErrorReportValve } return trace.toString(); } - } diff --git a/java/org/apache/catalina/valves/JDBCAccessLogValve.java b/java/org/apache/catalina/valves/JDBCAccessLogValve.java index ca3370b35..8d085d3eb 100644 --- a/java/org/apache/catalina/valves/JDBCAccessLogValve.java +++ b/java/org/apache/catalina/valves/JDBCAccessLogValve.java @@ -29,12 +29,11 @@ import java.util.Properties; import javax.servlet.ServletException; -import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleException; -import org.apache.catalina.LifecycleListener; +import org.apache.catalina.LifecycleState; import org.apache.catalina.connector.Request; import org.apache.catalina.connector.Response; -import org.apache.catalina.util.LifecycleSupport; +import org.apache.catalina.util.LifecycleBase; import org.apache.tomcat.util.res.StringManager; /** @@ -114,9 +113,7 @@ import org.apache.tomcat.util.res.StringManager; * @author Peter Rossbach */ -public final class JDBCAccessLogValve - extends ValveBase - implements Lifecycle { +public final class JDBCAccessLogValve extends ValveBase { // ----------------------------------------------------------- Constructors @@ -222,23 +219,11 @@ public final class JDBCAccessLogValve /** - * The lifecycle event support for this component. - */ - protected LifecycleSupport lifecycle = new LifecycleSupport(this); - - - /** * The string manager for this package. */ private static final StringManager sm = StringManager.getManager(Constants.Package); - /** - * Has this component been started yet? - */ - private boolean started = false; - - // ------------------------------------------------------------- Properties /** @@ -528,40 +513,6 @@ public final class JDBCAccessLogValve /** - * Adds a Lifecycle listener. - * - * @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(); - - } - - - /** - * Removes a Lifecycle listener. - * - * @param listener The listener to remove. - */ - public void removeLifecycleListener(LifecycleListener listener) { - - lifecycle.removeLifecycleListener(listener); - - } - - /** * Open (if necessary) and return a database connection for use by * this AccessLogValve. * @@ -640,45 +591,41 @@ public final class JDBCAccessLogValve } } + + /** - * Invoked by Tomcat on startup. The database connection is set here. - * - * @exception LifecycleException Can be thrown on lifecycle - * inconsistencies or on database errors (as a wrapped SQLException). + * 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 { - - if (started) - throw new LifecycleException - (sm.getString("accessLogValve.alreadyStarted")); - lifecycle.fireLifecycleEvent(START_EVENT, null); - started = true; - + @Override + protected synchronized void startInternal() throws LifecycleException { + try { open() ; } catch (SQLException e) { throw new LifecycleException(e); } + setState(LifecycleState.STARTING); } /** - * Invoked by tomcat on shutdown. The database connection is closed here. - * - * @exception LifecycleException Can be thrown on lifecycle - * inconsistencies or on database errors (as a wrapped SQLException). + * 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 */ - public void stop() throws LifecycleException { + @Override + protected synchronized void stopInternal() throws LifecycleException { - if (!started) - throw new LifecycleException - (sm.getString("accessLogValve.notStarted")); - lifecycle.fireLifecycleEvent(STOP_EVENT, null); - started = false; + setState(LifecycleState.STOPPING); close() ; - } diff --git a/java/org/apache/catalina/valves/LocalStrings.properties b/java/org/apache/catalina/valves/LocalStrings.properties index 7252cc66d..b35c559c3 100644 --- a/java/org/apache/catalina/valves/LocalStrings.properties +++ b/java/org/apache/catalina/valves/LocalStrings.properties @@ -13,14 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -accessLogValve.alreadyStarted=Access Logger has already been started -accessLogValve.notStarted=Access Logger has not yet been started -semaphoreValve.alreadyStarted=Semaphore valve has already been started -semaphoreValve.notStarted=Semaphore valve has not yet been started -certificatesValve.alreadyStarted=Certificates Valve has already been started -certificatesValve.notStarted=Certificates Valve has not yet been started -interceptorValve.alreadyStarted=Interceptor Valve has already been started -interceptorValve.notStarted=Interceptor Valve has not yet been started requestFilterValve.next=No ''next'' valve has been configured requestFilterValve.syntax=Syntax error in request filter pattern {0} valveBase.noNext=Configuration error: No ''next'' valve configured diff --git a/java/org/apache/catalina/valves/LocalStrings_es.properties b/java/org/apache/catalina/valves/LocalStrings_es.properties index 10b167086..0e1b5dd28 100644 --- a/java/org/apache/catalina/valves/LocalStrings_es.properties +++ b/java/org/apache/catalina/valves/LocalStrings_es.properties @@ -12,14 +12,6 @@ # 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. -accessLogValve.alreadyStarted = El Registrador de accesos ya se hab\u00EDa iniciado -accessLogValve.notStarted = El Registrador de accesos no se ha iniciado -semaphoreValve.alreadyStarted = La v\u00E1lvula del sem\u00E1foro ya ha sido arrancada -semaphoreValve.notStarted = La v\u00E1lvula del sem\u00E1foro a\u00FAn no ha sido arrancada -certificatesValve.alreadyStarted = La v\u00E1lvula de certificados ya se hab\u00EDa iniciado -certificatesValve.notStarted = La v\u00E1lvula de certificados no se ha iniciado -interceptorValve.alreadyStarted = La v\u00E1lvula interceptora ya se hab\u00EDa iniciado -interceptorValve.notStarted = La v\u00E1lvula interceptora no se ha iniciado requestFilterValve.next = No hay ''siguiente'' v\u00E1lvula configurada requestFilterValve.syntax = Error de sint\u00E1xis en petici\u00F3n de filtro patr\u00F3n {0} valveBase.noNext = Error de configuraci\u00F3n\: No hay ''siguiente'' v\u00E1lvula configurada diff --git a/java/org/apache/catalina/valves/LocalStrings_fr.properties b/java/org/apache/catalina/valves/LocalStrings_fr.properties index d3ba5c40f..ad9ad38d0 100644 --- a/java/org/apache/catalina/valves/LocalStrings_fr.properties +++ b/java/org/apache/catalina/valves/LocalStrings_fr.properties @@ -13,12 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -accessLogValve.alreadyStarted=Le traceur d''acc\u00e8s a d\u00e9j\u00e0 \u00e9t\u00e9 d\u00e9marr\u00e9 -accessLogValve.notStarted=Le traceur d''acc\u00e8s n''a pas encore \u00e9t\u00e9 d\u00e9marr\u00e9 -certificatesValve.alreadyStarted=La Valve de Certificats a d\u00e9j\u00e0 \u00e9t\u00e9 d\u00e9marr\u00e9e -certificatesValve.notStarted=La Valve de Certificats n''a pas encore \u00e9t\u00e9 d\u00e9marr\u00e9e -interceptorValve.alreadyStarted=La Valve d''Interception a d\u00e9j\u00e0 \u00e9t\u00e9 d\u00e9marr\u00e9e -interceptorValve.notStarted=La Valve d''Interception n''a pas encore \u00e9t\u00e9 d\u00e9marr\u00e9e requestFilterValve.next=Aucune Valve ''suivante'' n''a \u00e9t\u00e9 configur\u00e9e requestFilterValve.syntax=Erreur de syntaxe dans le pattern de filtre de requ\u00eate {0} valveBase.noNext=Erreur de configuration: aucune Valve ''suivante'' n''a \u00e9t\u00e9 configur\u00e9e diff --git a/java/org/apache/catalina/valves/LocalStrings_ja.properties b/java/org/apache/catalina/valves/LocalStrings_ja.properties index d3182cc8f..533a2ee1f 100644 --- a/java/org/apache/catalina/valves/LocalStrings_ja.properties +++ b/java/org/apache/catalina/valves/LocalStrings_ja.properties @@ -13,12 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -accessLogValve.alreadyStarted=\u30a2\u30af\u30bb\u30b9\u30ed\u30ac\u30fc\u306f\u65e2\u306b\u8d77\u52d5\u3055\u308c\u3066\u3044\u307e\u3059 -accessLogValve.notStarted=\u30a2\u30af\u30bb\u30b9\u30ed\u30ac\u30fc\u306f\u307e\u3060\u8d77\u52d5\u3055\u308c\u3066\u3044\u307e\u305b\u3093 -certificatesValve.alreadyStarted=\u8a8d\u8a3c\u30d0\u30eb\u30d6\u306f\u65e2\u306b\u8d77\u52d5\u3055\u308c\u3066\u3044\u307e\u3059 -certificatesValve.notStarted=\u8a8d\u8a3c\u30d0\u30eb\u30d6\u306f\u307e\u3060\u8d77\u52d5\u3055\u308c\u3066\u3044\u307e\u305b\u3093 -interceptorValve.alreadyStarted=\u30a4\u30f3\u30bf\u30fc\u30bb\u30d7\u30bf\u30d0\u30eb\u30d6\u306f\u65e2\u306b\u8d77\u52d5\u3055\u308c\u3066\u3044\u307e\u3059 -interceptorValve.notStarted=\u30a4\u30f3\u30bf\u30fc\u30bb\u30d7\u30bf\u30d0\u30eb\u30d6\u306f\u307e\u3060\u8d77\u52d5\u3055\u308c\u3066\u3044\u307e\u305b\u3093 requestFilterValve.next=\u6b21\u306e\u30d0\u30eb\u30d6\u304c\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u307e\u305b\u3093 requestFilterValve.syntax=\u30ea\u30af\u30a8\u30b9\u30c8\u30d5\u30a3\u30eb\u30bf\u30d1\u30bf\u30fc\u30f3 {0} \u306b\u69cb\u6587\u30a8\u30e9\u30fc\u304c\u3042\u308a\u307e\u3059 jdbcAccessLogValve.exception=\u30a2\u30af\u30bb\u30b9\u30a8\u30f3\u30c8\u30ea\u306e\u633f\u5165\u3092\u5b9f\u884c\u4e2d\u306e\u4f8b\u5916\u3067\u3059 diff --git a/java/org/apache/catalina/valves/PersistentValve.java b/java/org/apache/catalina/valves/PersistentValve.java index c866bcfaf..8ba1127ac 100644 --- a/java/org/apache/catalina/valves/PersistentValve.java +++ b/java/org/apache/catalina/valves/PersistentValve.java @@ -47,8 +47,7 @@ import org.apache.tomcat.util.res.StringManager; * @version $Revision$ $Date$ */ -public class PersistentValve - extends ValveBase { +public class PersistentValve extends ValveBase { //------------------------------------------------------ Constructor public PersistentValve() { diff --git a/java/org/apache/catalina/valves/SemaphoreValve.java b/java/org/apache/catalina/valves/SemaphoreValve.java index 107b4c1fa..644ba246a 100644 --- a/java/org/apache/catalina/valves/SemaphoreValve.java +++ b/java/org/apache/catalina/valves/SemaphoreValve.java @@ -24,13 +24,11 @@ import java.util.concurrent.Semaphore; import javax.servlet.ServletException; -import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleException; -import org.apache.catalina.LifecycleListener; +import org.apache.catalina.LifecycleState; import org.apache.catalina.connector.Request; import org.apache.catalina.connector.Response; -import org.apache.catalina.util.LifecycleSupport; -import org.apache.tomcat.util.res.StringManager; +import org.apache.catalina.util.LifecycleBase; /** @@ -43,9 +41,7 @@ import org.apache.tomcat.util.res.StringManager; * @version $Revision$ $Date$ */ -public class SemaphoreValve - extends ValveBase - implements Lifecycle { +public class SemaphoreValve extends ValveBase { //------------------------------------------------------ Constructor public SemaphoreValve() { @@ -63,30 +59,11 @@ public class SemaphoreValve /** - * The string manager for this package. - */ - private static final StringManager sm = - StringManager.getManager(Constants.Package); - - - /** * Semaphore. */ protected Semaphore semaphore = null; - /** - * The lifecycle event support for this component. - */ - protected LifecycleSupport lifecycle = new LifecycleSupport(this); - - - /** - * Has this component been started yet? - */ - private boolean started = false; - - // ------------------------------------------------------------- Properties @@ -122,85 +99,35 @@ public class SemaphoreValve public void setInterruptible(boolean interruptible) { this.interruptible = interruptible; } - // ------------------------------------------------------ Lifecycle 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); - - } - - - /** - * 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("semaphoreValve.alreadyStarted")); - lifecycle.fireLifecycleEvent(START_EVENT, null); - started = true; - + @Override + protected synchronized void startInternal() throws LifecycleException { + semaphore = new Semaphore(concurrency, fairness); + 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 { + @Override + protected synchronized void stopInternal() throws LifecycleException { - // Validate and update our current component state - if (!started) - throw new LifecycleException - (sm.getString("semaphoreValve.notStarted")); - lifecycle.fireLifecycleEvent(STOP_EVENT, null); - started = false; + setState(LifecycleState.STOPPING); semaphore = null; - } diff --git a/java/org/apache/catalina/valves/ValveBase.java b/java/org/apache/catalina/valves/ValveBase.java index 9ad0e1929..76ee3164a 100644 --- a/java/org/apache/catalina/valves/ValveBase.java +++ b/java/org/apache/catalina/valves/ValveBase.java @@ -32,6 +32,8 @@ import org.apache.catalina.Container; import org.apache.catalina.Context; import org.apache.catalina.Engine; import org.apache.catalina.Host; +import org.apache.catalina.LifecycleException; +import org.apache.catalina.LifecycleState; import org.apache.catalina.Pipeline; import org.apache.catalina.Valve; import org.apache.catalina.Wrapper; @@ -39,6 +41,7 @@ import org.apache.catalina.comet.CometEvent; import org.apache.catalina.connector.Request; import org.apache.catalina.connector.Response; import org.apache.catalina.core.ContainerBase; +import org.apache.catalina.util.LifecycleBase; import org.apache.tomcat.util.res.StringManager; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; @@ -55,7 +58,7 @@ import org.apache.juli.logging.LogFactory; * @version $Revision$ $Date$ */ -public abstract class ValveBase +public abstract class ValveBase extends LifecycleBase implements Contained, Valve, MBeanRegistration { private static final Log log = LogFactory.getLog(ValveBase.class); @@ -225,16 +228,47 @@ public abstract class ValveBase /** + * 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 + protected synchronized void startInternal() throws LifecycleException { + + setState(LifecycleState.STARTING); + } + + + /** + * 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 + 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 (container != null) + sb.append('['); + if (container == null) { + sb.append("Container is null"); + } else { sb.append(container.getName()); - sb.append("]"); - return (sb.toString()); + } + sb.append(']'); + return sb.toString(); } -- 2.11.0