From 2a1894f884ea0624b1c08cef2669572546510dc4 Mon Sep 17 00:00:00 2001 From: markt Date: Thu, 4 Mar 2010 18:34:36 +0000 Subject: [PATCH] Lifecycle refactoring Connector - relatively straight forward git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@919115 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/catalina/connector/Connector.java | 109 +++++---------------- .../catalina/connector/LocalStrings.properties | 2 - .../catalina/connector/LocalStrings_es.properties | 2 - .../catalina/connector/LocalStrings_fr.properties | 2 - .../catalina/connector/LocalStrings_ja.properties | 2 - 5 files changed, 25 insertions(+), 92 deletions(-) diff --git a/java/org/apache/catalina/connector/Connector.java b/java/org/apache/catalina/connector/Connector.java index f134e6538..73e143f45 100644 --- a/java/org/apache/catalina/connector/Connector.java +++ b/java/org/apache/catalina/connector/Connector.java @@ -28,10 +28,10 @@ import javax.management.ObjectName; import org.apache.catalina.Container; import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleException; -import org.apache.catalina.LifecycleListener; +import org.apache.catalina.LifecycleState; import org.apache.catalina.Service; import org.apache.catalina.core.AprLifecycleListener; -import org.apache.catalina.util.LifecycleSupport; +import org.apache.catalina.util.LifecycleBase; import org.apache.tomcat.util.res.StringManager; import org.apache.coyote.Adapter; import org.apache.coyote.ProtocolHandler; @@ -51,9 +51,9 @@ import org.apache.tomcat.util.modeler.Registry; */ -public class Connector - implements Lifecycle, MBeanRegistration -{ +public class Connector extends LifecycleBase + implements Lifecycle, MBeanRegistration { + private static final Log log = LogFactory.getLog(Connector.class); @@ -132,12 +132,6 @@ public class Connector /** - * The lifecycle event support for this component. - */ - protected LifecycleSupport lifecycle = new LifecycleSupport(this); - - - /** * The port number on which we listen for requests. */ protected int port = 0; @@ -209,12 +203,6 @@ public class Connector /** - * Has this component been started yet? - */ - protected boolean started = false; - - - /** * The shutdown signal to our background thread */ protected boolean stopped = false; @@ -273,7 +261,7 @@ public class Connector */ protected boolean useBodyEncodingForURI = false; - + protected static HashMap replacements = new HashMap(); static { @@ -383,15 +371,6 @@ public class Connector } - /** - * Is this connector available for processing requests? - */ - public boolean isAvailable() { - - return (started); - - } - /** * Return the Container used for processing requests received by this @@ -889,44 +868,6 @@ public class Connector } - // ------------------------------------------------------ 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); - - } - - protected ObjectName createObjectName(String domain, String type) throws MalformedObjectNameException { Object addressObj = getProperty("address"); @@ -1026,18 +967,11 @@ public class Connector * * @exception LifecycleException if a fatal startup error occurs */ - public void start() throws LifecycleException { + protected void startInternal() throws LifecycleException { if( !initialized ) initialize(); - // Validate and update our current state - if (started ) { - if(log.isInfoEnabled()) - log.info(sm.getString("coyoteConnector.alreadyStarted")); - return; - } - lifecycle.fireLifecycleEvent(START_EVENT, null); - started = true; + setState(LifecycleState.STARTING); // We can't register earlier - the JMX registration of this happens // in Server.start callback @@ -1093,16 +1027,9 @@ public class Connector * * @exception LifecycleException if a fatal shutdown error occurs */ - public void stop() throws LifecycleException { + protected void stopInternal() throws LifecycleException { - // Validate and update our current state - if (!started) { - log.error(sm.getString("coyoteConnector.notStarted")); - return; - - } - lifecycle.fireLifecycleEvent(STOP_EVENT, null); - started = false; + setState(LifecycleState.STOPPING); try { mapperListener.destroy(); @@ -1125,6 +1052,20 @@ public class Connector } + /** + * Provide a useful toString() implementation as it may be used when logging + * Lifecycle errors to identify the component. + */ + @Override + public String toString() { + // Not worth caching this right now + StringBuilder sb = new StringBuilder("Connector-"); + sb.append(getProtocol()); + sb.append(getPort()); + return sb.toString(); + } + + // -------------------- JMX registration -------------------- protected String domain; protected ObjectName oname; @@ -1163,7 +1104,7 @@ public class Connector public void postDeregister() { try { - if( started ) { + if(getState().isAvailable()) { stop(); } } catch( Throwable t ) { diff --git a/java/org/apache/catalina/connector/LocalStrings.properties b/java/org/apache/catalina/connector/LocalStrings.properties index efeedd2b0..cf0847103 100644 --- a/java/org/apache/catalina/connector/LocalStrings.properties +++ b/java/org/apache/catalina/connector/LocalStrings.properties @@ -18,9 +18,7 @@ # CoyoteConnector # coyoteConnector.alreadyInitialized=The connector has already been initialized -coyoteConnector.alreadyStarted=The connector has already been started coyoteConnector.cannotRegisterProtocol=Cannot register MBean for the Protocol -coyoteConnector.notStarted=Coyote connector has not been started coyoteConnector.protocolHandlerDestroyFailed=Protocol handler destroy failed: {0} coyoteConnector.protocolHandlerInitializationFailed=Protocol handler initialization failed: {0} coyoteConnector.protocolHandlerInstantiationFailed=Protocol handler instantiation failed: {0} diff --git a/java/org/apache/catalina/connector/LocalStrings_es.properties b/java/org/apache/catalina/connector/LocalStrings_es.properties index 4842583ad..891207cad 100644 --- a/java/org/apache/catalina/connector/LocalStrings_es.properties +++ b/java/org/apache/catalina/connector/LocalStrings_es.properties @@ -15,9 +15,7 @@ # # CoyoteConnector coyoteConnector.alreadyInitialized = Ya ha sido inicializado el conector -coyoteConnector.alreadyStarted = Ya ha sido arrancado el conector coyoteConnector.cannotRegisterProtocol = No puedo registrar MBean para el Protocolo -coyoteConnector.notStarted = El conector Coyote no ha sido arrancado coyoteConnector.protocolHandlerDestroyFailed = Fall\u00F3 la destrucci\u00F3n del manejador de protocolo\: {0} coyoteConnector.protocolHandlerInitializationFailed = Fall\u00F3 la inicializaci\u00F3n del manejador de protocolo\: {0} coyoteConnector.protocolHandlerInstantiationFailed = Fall\u00F3 la instanciaci\u00F3n del manejador de protocolo\: {0} diff --git a/java/org/apache/catalina/connector/LocalStrings_fr.properties b/java/org/apache/catalina/connector/LocalStrings_fr.properties index 1eca27a6c..d70582fc3 100644 --- a/java/org/apache/catalina/connector/LocalStrings_fr.properties +++ b/java/org/apache/catalina/connector/LocalStrings_fr.properties @@ -19,9 +19,7 @@ # coyoteConnector.alreadyInitialized=Le connecteur a d\u00e9j\u00e0 \u00e9t\u00e9 initialis\u00e9 -coyoteConnector.alreadyStarted=Le connecteur a d\u00e9j\u00e0 \u00e9t\u00e9 d\u00e9marr\u00e9 coyoteConnector.cannotRegisterProtocol=Impossible d''enregistrer le MBean pour le Protocol -coyoteConnector.notStarted=Le connecteur Coyote n''a pas \u00e9t\u00e9 d\u00e9marr\u00e9 coyoteConnector.protocolHandlerDestroyFailed=La destruction du gestionnaire de protocole a \u00e9chou\u00e9: {0} coyoteConnector.protocolHandlerInitializationFailed=L''initialisation du gestionnaire de protocole a \u00e9chou\u00e9: {0} coyoteConnector.protocolHandlerInstantiationFailed=L''instantiation du gestionnaire de protocole a \u00e9chou\u00e9: {0} diff --git a/java/org/apache/catalina/connector/LocalStrings_ja.properties b/java/org/apache/catalina/connector/LocalStrings_ja.properties index 0b493adb3..8d1eb77aa 100644 --- a/java/org/apache/catalina/connector/LocalStrings_ja.properties +++ b/java/org/apache/catalina/connector/LocalStrings_ja.properties @@ -19,9 +19,7 @@ # coyoteConnector.alreadyInitialized=\u30b3\u30cd\u30af\u30bf\u306f\u65e2\u306b\u521d\u671f\u5316\u3055\u308c\u3066\u3044\u307e\u3059 -coyoteConnector.alreadyStarted=\u30b3\u30cd\u30af\u30bf\u306f\u65e2\u306b\u8d77\u52d5\u3055\u308c\u3066\u3044\u307e\u3059 coyoteConnector.cannotRegisterProtocol=\u305d\u306e\u30d7\u30ed\u30c8\u30b3\u30eb\u306bMBean\u3092\u767b\u9332\u3067\u304d\u307e\u305b\u3093 -coyoteConnector.notStarted=Coyote\u30b3\u30cd\u30af\u30bf\u306f\u8d77\u52d5\u3055\u308c\u3066\u3044\u307e\u305b\u3093 coyoteConnector.protocolHandlerDestroyFailed=\u30d7\u30ed\u30c8\u30b3\u30eb\u30cf\u30f3\u30c9\u30e9\u306e\u5ec3\u68c4\u306b\u5931\u6557\u3057\u307e\u3057\u305f: {0} coyoteConnector.protocolHandlerInitializationFailed=\u30d7\u30ed\u30c8\u30b3\u30eb\u30cf\u30f3\u30c9\u30e9\u306e\u521d\u671f\u5316\u306b\u5931\u6557\u3057\u307e\u3057\u305f: {0} coyoteConnector.protocolHandlerInstantiationFailed=\u30d7\u30ed\u30c8\u30b3\u30eb\u30cf\u30f3\u30c9\u30e9\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u306b\u5931\u6557\u3057\u307e\u3057\u305f: {0} -- 2.11.0