tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1240105 - in /tomcat/trunk/java/org/apache/catalina: Container.java core/ContainerBase.java core/StandardHost.java deploy/NamingResources.java mbeans/MBeanUtils.java realm/RealmBase.java startup/FailedContext.java valves/ValveBase.java
Date Fri, 03 Feb 2012 12:08:09 GMT
Author: markt
Date: Fri Feb  3 12:08:09 2012
New Revision: 1240105

URL: http://svn.apache.org/viewvc?rev=1240105&view=rev
Log:
Refactor to remove some circular dependencies

Modified:
    tomcat/trunk/java/org/apache/catalina/Container.java
    tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java
    tomcat/trunk/java/org/apache/catalina/core/StandardHost.java
    tomcat/trunk/java/org/apache/catalina/deploy/NamingResources.java
    tomcat/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java
    tomcat/trunk/java/org/apache/catalina/realm/RealmBase.java
    tomcat/trunk/java/org/apache/catalina/startup/FailedContext.java
    tomcat/trunk/java/org/apache/catalina/valves/ValveBase.java

Modified: tomcat/trunk/java/org/apache/catalina/Container.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Container.java?rev=1240105&r1=1240104&r2=1240105&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Container.java (original)
+++ tomcat/trunk/java/org/apache/catalina/Container.java Fri Feb  3 12:08:09 2012
@@ -159,6 +159,17 @@ public interface Container extends Lifec
      */
     public ObjectName getObjectName();
 
+
+    /**
+     * Calculate the key properties string to be added to an object's
+     * {@link ObjectName} to indicate that it is associated with this container.
+     *
+     * @return          A string suitable for appending to the ObjectName
+     *
+     */
+    public String getMBeanKeyProperties();
+
+
     /**
      * Return the Pipeline object that manages the Valves associated with
      * this Container.

Modified: tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java?rev=1240105&r1=1240104&r2=1240105&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java Fri Feb  3 12:08:09 2012
@@ -45,7 +45,10 @@ import org.apache.catalina.Cluster;
 import org.apache.catalina.Container;
 import org.apache.catalina.ContainerEvent;
 import org.apache.catalina.ContainerListener;
+import org.apache.catalina.Context;
+import org.apache.catalina.Engine;
 import org.apache.catalina.Globals;
+import org.apache.catalina.Host;
 import org.apache.catalina.Lifecycle;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.LifecycleState;
@@ -54,9 +57,11 @@ import org.apache.catalina.Manager;
 import org.apache.catalina.Pipeline;
 import org.apache.catalina.Realm;
 import org.apache.catalina.Valve;
+import org.apache.catalina.Wrapper;
 import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;
 import org.apache.catalina.mbeans.MBeanUtils;
+import org.apache.catalina.util.ContextName;
 import org.apache.catalina.util.LifecycleMBeanBase;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
@@ -1405,6 +1410,44 @@ public abstract class ContainerBase exte
         return MBeanUtils.getDomain(this);
     }
 
+
+    @Override
+    public String getMBeanKeyProperties() {
+        Container c = this;
+        StringBuilder keyProperties = new StringBuilder();
+        int containerCount = 0;
+
+        // Work up container hierarchy, add a component to the name for
+        // each container
+        while (!(c instanceof Engine)) {
+            if (c instanceof Wrapper) {
+                keyProperties.append(",servlet=");
+                keyProperties.append(c.getName());
+            } else if (c instanceof Context) {
+                keyProperties.append(",context=");
+                ContextName cn = new ContextName(c.getName());
+                keyProperties.append(cn.getDisplayName());
+            } else if (c instanceof Host) {
+                keyProperties.append(",host=");
+                keyProperties.append(c.getName());
+            } else if (c == null) {
+                // May happen in unit testing and/or some embedding scenarios
+                keyProperties.append(",container");
+                keyProperties.append(containerCount++);
+                keyProperties.append("=null");
+                break;
+            } else {
+                // Should never happen...
+                keyProperties.append(",container");
+                keyProperties.append(containerCount++);
+                keyProperties.append('=');
+                keyProperties.append(c.getName());
+            }
+            c = c.getParent();
+        }
+        return keyProperties.toString();
+    }
+
     public ObjectName[] getChildren() {
         ObjectName result[]=new ObjectName[children.size()];
         Iterator<Container> it=children.values().iterator();

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardHost.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardHost.java?rev=1240105&r1=1240104&r2=1240105&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardHost.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardHost.java Fri Feb  3 12:08:09 2012
@@ -35,7 +35,6 @@ import org.apache.catalina.LifecycleExce
 import org.apache.catalina.LifecycleListener;
 import org.apache.catalina.Valve;
 import org.apache.catalina.loader.WebappClassLoader;
-import org.apache.catalina.mbeans.MBeanUtils;
 import org.apache.catalina.valves.ValveBase;
 import org.apache.tomcat.util.ExceptionUtils;
 
@@ -825,7 +824,7 @@ public class StandardHost extends Contai
     protected String getObjectNameKeyProperties() {
 
         StringBuilder keyProperties = new StringBuilder("type=Host");
-        keyProperties.append(MBeanUtils.getContainerKeyProperties(this));
+        keyProperties.append(getMBeanKeyProperties());
 
         return keyProperties.toString();
     }

Modified: tomcat/trunk/java/org/apache/catalina/deploy/NamingResources.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/deploy/NamingResources.java?rev=1240105&r1=1240104&r2=1240105&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/deploy/NamingResources.java (original)
+++ tomcat/trunk/java/org/apache/catalina/deploy/NamingResources.java Fri Feb  3 12:08:09
2012
@@ -1088,7 +1088,7 @@ public class NamingResources extends Lif
         Object c = getContainer();
         if (c instanceof Container) {
             return "type=NamingResources" +
-                    MBeanUtils.getContainerKeyProperties((Container) c);
+                    ((Container) c).getMBeanKeyProperties();
         }
         // Server or just unknown
         return "type=NamingResources";

Modified: tomcat/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java?rev=1240105&r1=1240104&r2=1240105&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java (original)
+++ tomcat/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java Fri Feb  3 12:08:09 2012
@@ -1562,6 +1562,7 @@ public class MBeanUtils {
      *
      * @param container The container the object is associated with
      * @return          A string suitable for appending to the ObjectName
+     *
      */
     public static String getContainerKeyProperties(Container container) {
 

Modified: tomcat/trunk/java/org/apache/catalina/realm/RealmBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/realm/RealmBase.java?rev=1240105&r1=1240104&r2=1240105&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/realm/RealmBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/realm/RealmBase.java Fri Feb  3 12:08:09 2012
@@ -1313,7 +1313,7 @@ public abstract class RealmBase extends 
 
         StringBuilder keyProperties = new StringBuilder("type=Realm");
         keyProperties.append(getRealmSuffix());
-        keyProperties.append(MBeanUtils.getContainerKeyProperties(container));
+        keyProperties.append(container.getMBeanKeyProperties());
 
         return keyProperties.toString();
     }

Modified: tomcat/trunk/java/org/apache/catalina/startup/FailedContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/FailedContext.java?rev=1240105&r1=1240104&r2=1240105&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/FailedContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/FailedContext.java Fri Feb  3 12:08:09 2012
@@ -35,6 +35,8 @@ import org.apache.catalina.Cluster;
 import org.apache.catalina.Container;
 import org.apache.catalina.ContainerListener;
 import org.apache.catalina.Context;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Host;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.Loader;
 import org.apache.catalina.Manager;
@@ -53,6 +55,7 @@ import org.apache.catalina.deploy.Naming
 import org.apache.catalina.deploy.SecurityConstraint;
 import org.apache.catalina.mbeans.MBeanUtils;
 import org.apache.catalina.util.CharsetMapper;
+import org.apache.catalina.util.ContextName;
 import org.apache.catalina.util.LifecycleMBeanBase;
 import org.apache.juli.logging.Log;
 import org.apache.tomcat.JarScanner;
@@ -123,6 +126,41 @@ public class FailedContext extends Lifec
 
 
     @Override
+    public String getMBeanKeyProperties() {
+        Container c = this;
+        StringBuilder keyProperties = new StringBuilder();
+        int containerCount = 0;
+
+        // Work up container hierarchy, add a component to the name for
+        // each container
+        while (!(c instanceof Engine)) {
+            if (c instanceof Context) {
+                keyProperties.append(",context=");
+                ContextName cn = new ContextName(c.getName());
+                keyProperties.append(cn.getDisplayName());
+            } else if (c instanceof Host) {
+                keyProperties.append(",host=");
+                keyProperties.append(c.getName());
+            } else if (c == null) {
+                // May happen in unit testing and/or some embedding scenarios
+                keyProperties.append(",container");
+                keyProperties.append(containerCount++);
+                keyProperties.append("=null");
+                break;
+            } else {
+                // Should never happen...
+                keyProperties.append(",container");
+                keyProperties.append(containerCount++);
+                keyProperties.append('=');
+                keyProperties.append(c.getName());
+            }
+            c = c.getParent();
+        }
+        return keyProperties.toString();
+    }
+
+
+    @Override
     protected String getObjectNameKeyProperties() {
 
         StringBuilder keyProperties =

Modified: tomcat/trunk/java/org/apache/catalina/valves/ValveBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/ValveBase.java?rev=1240105&r1=1240104&r2=1240105&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/valves/ValveBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/valves/ValveBase.java Fri Feb  3 12:08:09 2012
@@ -266,7 +266,7 @@ public abstract class ValveBase extends 
 
         Container container = getContainer();
 
-        name.append(MBeanUtils.getContainerKeyProperties(container));
+        name.append(container.getMBeanKeyProperties());
 
         int seq = 0;
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message