tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1068416 - in /tomcat/trunk: java/org/apache/catalina/core/ java/org/apache/catalina/deploy/ java/org/apache/catalina/mbeans/ webapps/docs/
Date Tue, 08 Feb 2011 14:30:18 GMT
Author: markt
Date: Tue Feb  8 14:30:17 2011
New Revision: 1068416

URL: http://svn.apache.org/viewvc?rev=1068416&view=rev
Log:
Make NamingResources implement MBeanLifecycle
Environments, Resources and ResourceLinks are once again available via JMX

Modified:
    tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
    tomcat/trunk/java/org/apache/catalina/core/StandardServer.java
    tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/deploy/NamingResources.java
    tomcat/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties?rev=1068416&r1=1068415&r2=1068416&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties Tue Feb  8 14:30:17
2011
@@ -122,6 +122,8 @@ standardContext.loginConfig.loginWarning
 standardContext.loginConfig.required=LoginConfig cannot be null
 standardContext.manager=Configured a manager of class [{0}]
 standardContext.mappingError=MAPPING configuration error for relative URI {0}
+standardContext.namingResource.init.fail=Failed to init new naming resources
+standardContext.namingResource.destroy.fail=Failed to destroy old naming resources
 standardContext.noResourceJar=Resource JARs are not supported. The JAR found at [{0}] will
not be used to provide static content for context with name [{1}]
 standardContext.notFound=The requested resource ({0}) is not available.
 standardContext.notReloadable=Reloading is disabled on this Context

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardContext.java?rev=1068416&r1=1068415&r2=1068416&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardContext.java Tue Feb  8 14:30:17 2011
@@ -448,7 +448,6 @@ public class StandardContext extends Con
      * The naming resources for this web application.
      */
     private NamingResources namingResources = null;
-    private ObjectName onameNamingResources;
 
     /**
      * The message destinations for this web application.
@@ -1934,16 +1933,29 @@ public class StandardContext extends Con
         // Process the property setting change
         NamingResources oldNamingResources = this.namingResources;
         this.namingResources = namingResources;
-        namingResources.setContainer(this);
+        if (namingResources != null) {
+            namingResources.setContainer(this);
+        }
         support.firePropertyChange("namingResources",
                                    oldNamingResources, this.namingResources);
         
         // If set from server.xml, getObjectKeyPropertiesNameOnly() will
         // trigger an NPE. Initial registration takes place on INIT. 
         if (getState() != LifecycleState.NEW) {
-            unregister(onameNamingResources);
-            onameNamingResources = register(namingResources,
-                    "type=NamingResources," + getObjectKeyPropertiesNameOnly());
+            if (oldNamingResources != null) {
+                try {
+                    oldNamingResources.destroy();
+                } catch (LifecycleException e) {
+                    log.warn("standardContext.namingResource.destroy.fail", e);
+                }
+            }
+            if (namingResources != null) {
+                try {
+                    namingResources.init();
+                } catch (LifecycleException e) {
+                    log.warn("standardContext.namingResource.init.fail", e);
+                }
+            }
         }
     }
 
@@ -5435,7 +5447,9 @@ public class StandardContext extends Con
                              sequenceNumber.getAndIncrement());
         broadcaster.sendNotification(notification);
 
-        unregister(onameNamingResources);
+        if (namingResources != null) {
+            namingResources.destroy();
+        }
 
         synchronized (instanceListenersLock) {
             instanceListeners = new String[0];
@@ -6087,8 +6101,7 @@ public class StandardContext extends Con
 
         // Register the naming resources
         if (namingResources != null) {
-            onameNamingResources = register(namingResources,
-                    "type=NamingResources," + getObjectNameKeyProperties());
+            namingResources.init();
         }
 
         // Send j2ee.object.created notification 

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardServer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardServer.java?rev=1068416&r1=1068415&r2=1068416&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardServer.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardServer.java Tue Feb  8 14:30:17 2011
@@ -718,6 +718,8 @@ public final class StandardServer extend
         fireLifecycleEvent(CONFIGURE_START_EVENT, null);
         setState(LifecycleState.STARTING);
 
+        globalNamingResources.start();
+        
         // Start our defined Services
         synchronized (services) {
             for (int i = 0; i < services.length; i++) {
@@ -745,8 +747,9 @@ public final class StandardServer extend
             services[i].stop();
         }
 
+        globalNamingResources.stop();
+        
         stopAwait();
-
     }
 
     /**
@@ -770,8 +773,7 @@ public final class StandardServer extend
         onameMBeanFactory = register(factory, "type=MBeanFactory");
         
         // Register the naming resources
-        onameNamingResoucres = register(globalNamingResources,
-                "type=NamingResources");
+        globalNamingResources.init();
         
         // Initialize our defined Services
         for (int i = 0; i < services.length; i++) {
@@ -786,12 +788,12 @@ public final class StandardServer extend
             services[i].destroy();
         }
 
+        globalNamingResources.destroy();
+        
         unregister(onameMBeanFactory);
         
         unregister(onameStringCache);
-        
-        unregister(onameNamingResoucres);
-        
+                
         super.destroyInternal();
     }
 
@@ -824,7 +826,6 @@ public final class StandardServer extend
     
     private ObjectName onameStringCache;
     private ObjectName onameMBeanFactory;
-    private ObjectName onameNamingResoucres;
     
     /**
      * Obtain the MBean domain for this server. The domain is obtained using

Modified: tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties?rev=1068416&r1=1068415&r2=1068416&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/deploy/LocalStrings.properties Tue Feb  8 14:30:17
2011
@@ -42,3 +42,7 @@ webXml.multipleOther=Multiple others ent
 webxml.unrecognisedPublicId=The public ID [{0}] did not match any of the known public ID's
for web.xml files so the version could not be identified
 webXml.version.nfe=Unable to parse [{0}] from the version string [{1}]. This component of
the version string will be ignored. 
 webXml.wrongFragmentName=Used a wrong fragment name {0} at web.xml absolute-ordering tag!
+
+namingResources.mbeanCreateFail=Failed to create MBean for naming resource [{0}]
+namingResoucres.mbeanDestroyFail=Failed to destroy MBean for naming resource [{1}]
+

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=1068416&r1=1068415&r2=1068416&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/deploy/NamingResources.java (original)
+++ tomcat/trunk/java/org/apache/catalina/deploy/NamingResources.java Tue Feb  8 14:30:17
2011
@@ -25,9 +25,17 @@ import java.io.Serializable;
 import java.util.HashMap;
 import java.util.Hashtable;
 
+import org.apache.catalina.Container;
 import org.apache.catalina.Context;
 import org.apache.catalina.Engine;
+import org.apache.catalina.LifecycleException;
+import org.apache.catalina.LifecycleState;
 import org.apache.catalina.Server;
+import org.apache.catalina.mbeans.MBeanUtils;
+import org.apache.catalina.util.LifecycleMBeanBase;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.util.res.StringManager;
 
 
 /**
@@ -38,9 +46,16 @@ import org.apache.catalina.Server;
  * @version $Id$
  */
 
-public class NamingResources implements Serializable {
+public class NamingResources extends LifecycleMBeanBase implements Serializable {
 
     private static final long serialVersionUID = 1L;
+    
+    private static final Log log = LogFactory.getLog(NamingResources.class);
+    
+    private static final StringManager sm =
+        StringManager.getManager(Constants.Package);
+
+    private volatile boolean resourceRequireExplicitRegistration = false;
 
     // ----------------------------------------------------------- Constructors
 
@@ -238,6 +253,15 @@ public class NamingResources implements 
         }
         support.firePropertyChange("environment", null, environment);
 
+        // Register with JMX
+        if (resourceRequireExplicitRegistration) {
+            try {
+                MBeanUtils.createMBean(environment);
+            } catch (Exception e) {
+                log.warn(sm.getString("namingResources.mbeanCreateFail",
+                        environment.getName()), e);
+            }
+        }
     }
 
     // Container should be an instance of Server or Context. If it is anything
@@ -330,6 +354,15 @@ public class NamingResources implements 
         }
         support.firePropertyChange("resource", null, resource);
 
+        // Register with JMX
+        if (resourceRequireExplicitRegistration) {
+            try {
+                MBeanUtils.createMBean(resource);
+            } catch (Exception e) {
+                log.warn(sm.getString("namingResources.mbeanCreateFail",
+                        resource.getName()), e);
+            }
+        }
     }
 
 
@@ -378,6 +411,15 @@ public class NamingResources implements 
         }
         support.firePropertyChange("resourceLink", null, resourceLink);
 
+        // Register with JMX
+        if (resourceRequireExplicitRegistration) {
+            try {
+                MBeanUtils.createMBean(resourceLink);
+            } catch (Exception e) {
+                log.warn(sm.getString("namingResources.mbeanCreateFail",
+                        resourceLink.getName()), e);
+            }
+        }
     }
 
 
@@ -689,9 +731,17 @@ public class NamingResources implements 
         }
         if (environment != null) {
             support.firePropertyChange("environment", environment, null);
+            // De-register with JMX
+            if (resourceRequireExplicitRegistration) {
+                try {
+                    MBeanUtils.destroyMBean(environment);
+                } catch (Exception e) {
+                    log.warn(sm.getString("namingResources.mbeanDestroyFail",
+                            environment.getName()), e);
+                }
+            }
             environment.setNamingResources(null);
         }
-
     }
 
 
@@ -765,9 +815,17 @@ public class NamingResources implements 
         }
         if (resource != null) {
             support.firePropertyChange("resource", resource, null);
+            // De-register with JMX
+            if (resourceRequireExplicitRegistration) {
+                try {
+                    MBeanUtils.destroyMBean(resource);
+                } catch (Exception e) {
+                    log.warn(sm.getString("namingResources.mbeanDestroyFail",
+                            resource.getName()), e);
+                }
+            }
             resource.setNamingResources(null);
         }
-
     }
 
 
@@ -808,9 +866,17 @@ public class NamingResources implements 
         }
         if (resourceLink != null) {
             support.firePropertyChange("resourceLink", resourceLink, null);
+            // De-register with JMX
+            if (resourceRequireExplicitRegistration) {
+                try {
+                    MBeanUtils.destroyMBean(resourceLink);
+                } catch (Exception e) {
+                    log.warn(sm.getString("namingResources.mbeanDestroyFail",
+                            resourceLink.getName()), e);
+                }
+            }
             resourceLink.setNamingResources(null);
         }
-
     }
 
 
@@ -835,4 +901,119 @@ public class NamingResources implements 
     }
 
 
+    // ------------------------------------------------------- Lifecycle methods
+    
+    @Override
+    protected void initInternal() throws LifecycleException {
+        super.initInternal();
+        
+        // Set this before we register currently known naming resources to avoid
+        // timing issues. Duplication registration is not an issue.
+        resourceRequireExplicitRegistration = true;
+        
+        for (ContextResource cr : resources.values()) {
+            try {
+                MBeanUtils.createMBean(cr);
+            } catch (Exception e) {
+                log.warn(sm.getString(
+                        "namingResources.mbeanCreateFail", cr.getName()), e);
+            }
+        }
+        
+        for (ContextEnvironment ce : envs.values()) {
+            try {
+                MBeanUtils.createMBean(ce);
+            } catch (Exception e) {
+                log.warn(sm.getString(
+                        "namingResources.mbeanCreateFail", ce.getName()), e);
+            }
+        }
+        
+        for (ContextResourceLink crl : resourceLinks.values()) {
+            try {
+                MBeanUtils.createMBean(crl);
+            } catch (Exception e) {
+                log.warn(sm.getString(
+                        "namingResources.mbeanCreateFail", crl.getName()), e);
+            }
+        }
+    }
+
+
+    @Override
+    protected void startInternal() throws LifecycleException {
+        fireLifecycleEvent(CONFIGURE_START_EVENT, null);
+        setState(LifecycleState.STARTING);
+    }
+
+
+    @Override
+    protected void stopInternal() throws LifecycleException {
+        setState(LifecycleState.STOPPING);
+        fireLifecycleEvent(CONFIGURE_STOP_EVENT, null);
+    }
+
+    
+    @Override
+    protected void destroyInternal() throws LifecycleException {
+
+        // Set this before we de-register currently known naming resources to
+        // avoid timing issues. Duplication de-registration is not an issue.
+        resourceRequireExplicitRegistration = false;
+
+        // Destroy in reverse order to create, although it should not matter
+        for (ContextResourceLink crl : resourceLinks.values()) {
+            try {
+                MBeanUtils.destroyMBean(crl);
+            } catch (Exception e) {
+                log.warn(sm.getString(
+                        "namingResources.mbeanDestroyFail", crl.getName()), e);
+            }
+        }
+        
+        for (ContextEnvironment ce : envs.values()) {
+            try {
+                MBeanUtils.destroyMBean(ce);
+            } catch (Exception e) {
+                log.warn(sm.getString(
+                        "namingResources.mbeanDestroyFail", ce.getName()), e);
+            }
+        }
+        
+        for (ContextResource cr : resources.values()) {
+            try {
+                MBeanUtils.destroyMBean(cr);
+            } catch (Exception e) {
+                log.warn(sm.getString(
+                        "namingResources.mbeanDestroyFail", cr.getName()), e);
+            }
+        }
+        
+        super.destroyInternal();
+    }
+
+
+    @Override
+    protected String getDomainInternal() {
+        // Use the same domain as our associated container if we have one
+        Object c = getContainer();
+        
+        if (c instanceof LifecycleMBeanBase) {
+            return ((LifecycleMBeanBase) c).getDomain();
+        }
+
+        return null;
+    }
+
+
+    @Override
+    protected String getObjectNameKeyProperties() {
+        Object c = getContainer();
+        if (c instanceof Container) {
+            return "type=NamingResources" +
+                    MBeanUtils.getContainerKeyProperties((Container) c);
+        }
+        // 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=1068416&r1=1068415&r2=1068416&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java (original)
+++ tomcat/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java Tue Feb  8 14:30:17 2011
@@ -136,7 +136,7 @@ public class MBeanUtils {
      *
      * @exception Exception if an MBean cannot be created or registered
      */
-    static DynamicMBean createMBean(ContextEnvironment environment)
+    public static DynamicMBean createMBean(ContextEnvironment environment)
         throws Exception {
 
         String mname = createManagedName(environment);
@@ -167,7 +167,7 @@ public class MBeanUtils {
      *
      * @exception Exception if an MBean cannot be created or registered
      */
-    static DynamicMBean createMBean(ContextResource resource)
+    public static DynamicMBean createMBean(ContextResource resource)
         throws Exception {
 
         String mname = createManagedName(resource);
@@ -198,7 +198,7 @@ public class MBeanUtils {
      *
      * @exception Exception if an MBean cannot be created or registered
      */
-    static DynamicMBean createMBean(ContextResourceLink resourceLink)
+    public static DynamicMBean createMBean(ContextResourceLink resourceLink)
         throws Exception {
 
         String mname = createManagedName(resourceLink);
@@ -1026,7 +1026,7 @@ public class MBeanUtils {
 
         if (registry == null) {
             registry = Registry.getRegistry(null, null);
-            ClassLoader cl=ServerLifecycleListener.class.getClassLoader();
+            ClassLoader cl = MBeanUtils.class.getClassLoader();
 
             registry.loadDescriptors("org.apache.catalina.mbeans",  cl);
             registry.loadDescriptors("org.apache.catalina.authenticator", cl);
@@ -1140,7 +1140,7 @@ public class MBeanUtils {
      *
      * @exception Exception if an MBean cannot be deregistered
      */
-    static void destroyMBean(ContextEnvironment environment)
+    public static void destroyMBean(ContextEnvironment environment)
         throws Exception {
 
         String mname = createManagedName(environment);
@@ -1166,7 +1166,7 @@ public class MBeanUtils {
      *
      * @exception Exception if an MBean cannot be deregistered
      */
-    static void destroyMBean(ContextResource resource)
+    public static void destroyMBean(ContextResource resource)
         throws Exception {
 
         // If this is a user database resource need to destroy groups, roles,
@@ -1198,7 +1198,7 @@ public class MBeanUtils {
      *
      * @exception Exception if an MBean cannot be deregistered
      */
-    static void destroyMBean(ContextResourceLink resourceLink)
+    public static void destroyMBean(ContextResourceLink resourceLink)
         throws Exception {
 
         String mname = createManagedName(resourceLink);

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1068416&r1=1068415&r2=1068416&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Tue Feb  8 14:30:17 2011
@@ -60,6 +60,10 @@
         address, remote host, protocol and server port may be used in an access
         log if desired. (markt)
       </add>
+      <fix>
+        Restore access to Environments, Resources and ResourceLinks via JMX
+        which was lost in early 7.0.x re-factoring. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">



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


Mime
View raw message