Re-factoring in support of https://issues.apache.org/bugzilla/show_bug.cgi?id=50360
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 8 Dec 2010 17:15:50 +0000 (17:15 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 8 Dec 2010 17:15:50 +0000 (17:15 +0000)
ProtocolHandler should register itself with MBean server rather than have the connector do it.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1043531 13f79535-47bb-0310-9956-ffa450edef68

checkstyle.xml
java/org/apache/catalina/connector/Connector.java
java/org/apache/catalina/connector/CoyoteAdapter.java
java/org/apache/coyote/AbstractProtocolHandler.java
java/org/apache/coyote/Adapter.java

index 325d24f..024bf91 100644 (file)
   <module name="FileTabCharacter"/>
 
   <module name="TreeWalker">
+    <!-- Block Checks -->
+    <!--  ~60 errors
+    <module name="AvoidNestedBlocks"/>
+    -->
+
     <!-- Coding -->
     <module name="IllegalInstantiation"/>
     
     https://sourceforge.net/tracker/?func=detail&aid=3039718&group_id=29721&atid=397078
     <module name="GenericWhitespace"/>
     -->
+    <module name="EmptyForInitializerPad"/>
+    <module name="EmptyForIteratorPad"/>
     <!--  ~ 1000 errors
     <module name="OperatorWrap">
       <property name="option" value="oel"/>
     </module>
     -->
-    <module name="EmptyForInitializerPad"/>
-    <module name="EmptyForIteratorPad"/>
   </module>
 </module>
\ No newline at end of file
index b65250e..609bbc8 100644 (file)
@@ -907,9 +907,6 @@ public class Connector extends LifecycleMBeanBase  {
                  ("coyoteConnector.protocolHandlerInitializationFailed"), e);
         }
 
-        onameProtocolHandler = register(protocolHandler,
-                createObjectNameKeyProperties("ProtocolHandler"));
-
         // Initialize mapper listener
         mapperListener.init();
     }
@@ -967,7 +964,6 @@ public class Connector extends LifecycleMBeanBase  {
     @Override
     protected void destroyInternal() throws LifecycleException {
         mapperListener.destroy();
-        unregister(onameProtocolHandler);
         
         try {
             protocolHandler.destroy();
index 082b9c4..0cb736e 100644 (file)
@@ -464,6 +464,12 @@ public class CoyoteAdapter implements Adapter {
     }
     
     
+    @Override
+    public String getDomain() {
+        return connector.getDomain();
+    }
+
+
     // ------------------------------------------------------ Protected Methods
 
 
index 43eaf90..a8040eb 100644 (file)
@@ -23,6 +23,7 @@ import java.util.concurrent.Executor;
 
 import javax.management.MBeanRegistration;
 import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
 import org.apache.juli.logging.Log;
@@ -334,6 +335,24 @@ public abstract class AbstractProtocolHandler implements ProtocolHandler,
         // NOOP
     }
 
+    private ObjectName createObjectName() throws MalformedObjectNameException {
+        // Use the same domain as the connector
+        domain = adapter.getDomain();
+        
+        if (domain == null) {
+            return null;
+        }
+
+        StringBuilder name = new StringBuilder(getDomain());
+        name.append(":type=ProtocolHandler,port=");
+        name.append(getPort());
+        InetAddress address = getAddress();
+        if (address != null) {
+            name.append(",address=");
+            name.append(ObjectName.quote(address.toString()));
+        }
+        return new ObjectName(name.toString());
+    }
 
     // ------------------------------------------------------- Lifecycle methods
 
@@ -349,6 +368,15 @@ public abstract class AbstractProtocolHandler implements ProtocolHandler,
             getLog().info(sm.getString("abstractProtocolHandler.init",
                     getName()));
 
+        if (oname == null) {
+            // Component not pre-registered so register it
+            oname = createObjectName();
+            if (oname != null) {
+                Registry.getRegistry(null, null).registerComponent(this, oname,
+                    null);
+            }
+        }
+
         if (this.domain != null) {
             try {
                 tpOname = new ObjectName(domain + ":" +
@@ -450,6 +478,12 @@ public abstract class AbstractProtocolHandler implements ProtocolHandler,
                     getName()), e);
         }
         
+        // If object was pre-registered (mserver != null) what ever registered
+        // the ProtocolHandler should de-register it
+        if (oname != null && mserver == null) {
+                Registry.getRegistry(null, null).unregisterComponent(oname);
+        }
+
         if (tpOname != null)
             Registry.getRegistry(null, null).unregisterComponent(tpOname);
         if (rgOname != null)
index ffa5d35..e9496e7 100644 (file)
@@ -54,4 +54,12 @@ public interface Adapter {
             throws Exception;
 
     public void log(Request req, Response res, long time);
+
+    /**
+     * Provide the name of the domain to use to register MBeans for conponents
+     * associated with the connector.
+     * 
+     * @return  The MBean domain name
+     */
+    public String getDomain();
 }