Author: markt Date: Thu Mar 4 18:34:36 2010 New Revision: 919115 URL: http://svn.apache.org/viewvc?rev=919115&view=rev Log: Lifecycle refactoring Connector - relatively straight forward
Modified: tomcat/trunk/java/org/apache/catalina/connector/Connector.java tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_es.properties tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_fr.properties tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_ja.properties Modified: tomcat/trunk/java/org/apache/catalina/connector/Connector.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/Connector.java?rev=919115&r1=919114&r2=919115&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/connector/Connector.java (original) +++ tomcat/trunk/java/org/apache/catalina/connector/Connector.java Thu Mar 4 18:34:36 2010 @@ -28,10 +28,10 @@ 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 @@ */ -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 @@ /** - * 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 @@ /** - * 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 @@ */ protected boolean useBodyEncodingForURI = false; - + protected static HashMap<String,String> replacements = new HashMap<String,String>(); static { @@ -383,15 +371,6 @@ } - /** - * 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 @@ } - // ------------------------------------------------------ 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 @@ * * @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 @@ * * @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 @@ } + /** + * 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 void postDeregister() { try { - if( started ) { + if(getState().isAvailable()) { stop(); } } catch( Throwable t ) { Modified: tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties?rev=919115&r1=919114&r2=919115&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties (original) +++ tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties Thu Mar 4 18:34:36 2010 @@ -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} Modified: tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_es.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_es.properties?rev=919115&r1=919114&r2=919115&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_es.properties (original) +++ tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_es.properties Thu Mar 4 18:34:36 2010 @@ -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} Modified: tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_fr.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_fr.properties?rev=919115&r1=919114&r2=919115&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_fr.properties (original) +++ tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_fr.properties Thu Mar 4 18:34:36 2010 @@ -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} Modified: tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_ja.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_ja.properties?rev=919115&r1=919114&r2=919115&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_ja.properties (original) +++ tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_ja.properties Thu Mar 4 18:34:36 2010 @@ -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} --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org