tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r777611 - in /tomcat/tc6.0.x/trunk: ./ STATUS.txt java/org/apache/catalina/connector/MapperListener.java java/org/apache/catalina/mbeans/MBeanUtils.java java/org/apache/catalina/mbeans/ServerLifecycleListener.java webapps/docs/changelog.xml
Date Fri, 22 May 2009 16:41:15 GMT
Author: markt
Date: Fri May 22 16:41:15 2009
New Revision: 777611

URL: http://svn.apache.org/viewvc?rev=777611&view=rev
Log:
 Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47046
Deregister all MBeans when the server is stopped

Modified:
    tomcat/tc6.0.x/trunk/   (props changed)
    tomcat/tc6.0.x/trunk/STATUS.txt
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/MapperListener.java
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/mbeans/ServerLifecycleListener.java
    tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc6.0.x/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri May 22 16:41:15 2009
@@ -1 +1 @@
-/tomcat/trunk:601180,606992,612607,630314,640888,652744,653247,673796,673820,683982,684001,684081,684234,684269-684270,685177,687503,687645,689402,690781,691392,691805,692748,693378,694992,695053,695311,696780,696782,698012,698227,698236,698613,699427,699634,701355,709294,709811,709816,710063,710066,710125,710205,711126,711600,712461,712467,718360,719119,719124,719602,719626,719628,720046,720069,721040,721286,721708,721886,723404,723738,726052,727303,728032,728768,728947,729057,729567,729569,729571,729681,729809,729815,729934,730250,730590,731651,732859,732863,734734,740675,740684,742677,742697,742714,744160,744238,746321,746384,746425,747834,747863,748344,750258,750291,750921,751286-751287,751289,751295,753039,757335,757774,758365,758596,758616,758664,759074,761601,762868,762929,762936-762937,763166,763183,763193,763228,763298,763302,763325,763599,763611,763654,763681,763706,764985,764997,765662,768335
+/tomcat/trunk:601180,606992,612607,630314,640888,652744,653247,673796,673820,683982,684001,684081,684234,684269-684270,685177,687503,687645,689402,690781,691392,691805,692748,693378,694992,695053,695311,696780,696782,698012,698227,698236,698613,699427,699634,701355,709294,709811,709816,710063,710066,710125,710205,711126,711600,712461,712467,718360,719119,719124,719602,719626,719628,720046,720069,721040,721286,721708,721886,723404,723738,726052,727303,728032,728768,728947,729057,729567,729569,729571,729681,729809,729815,729934,730250,730590,731651,732859,732863,734734,740675,740684,742677,742697,742714,744160,744238,746321,746384,746425,747834,747863,748344,750258,750291,750921,751286-751287,751289,751295,753039,757335,757774,758365,758596,758616,758664,759074,761601,762868,762929,762936-762937,763166,763183,763193,763228,763298,763302,763325,763599,763611,763654,763681,763706,764985,764997,765662,768335,769979

Modified: tomcat/tc6.0.x/trunk/STATUS.txt
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=777611&r1=777610&r2=777611&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/STATUS.txt (original)
+++ tomcat/tc6.0.x/trunk/STATUS.txt Fri May 22 16:41:15 2009
@@ -115,24 +115,6 @@
   +0: kkolinko: should not be needed, as old and new are both correct.
   -1: 
 
-* Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47046
-  Deregister all MBeans when the server is stopped
-  http://svn.apache.org/viewvc?rev=769979&view=rev
-  +1: markt, pero
-  +1: kkolinko (ok, but one question:
-        in MBeanUtils.java:
-
-        @@ -1401,12 +1417,7 @@
-         static void destroyMBean(Context context)
-         ..
-        +        String domain = context.getParent().getParent().getName();
-                 if (domain == null)
-                     domain = mserver.getDefaultDomain();
-
-         Can domain be null here, or one of those getParent().foo() calls result in an NPE
?
-      )
-  -1: 
-
 * Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47080
   Prevent NPE when mapper makes no matches
   http://svn.apache.org/viewvc?rev=770809&view=rev

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/MapperListener.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/MapperListener.java?rev=777611&r1=777610&r2=777611&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/MapperListener.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/MapperListener.java Fri May 22
16:41:15 2009
@@ -353,7 +353,9 @@
                 domain).getContainer().findChild(name);
         
             mapper.removeHost(name);
-            host.removeContainerListener(this);
+            if (host != null) {
+                host.removeContainerListener(this);
+            }
             if(log.isDebugEnabled())
                 log.debug(sm.getString
                         ("mapperListener.unregisterHost", name, domain));

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java?rev=777611&r1=777610&r2=777611&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/mbeans/MBeanUtils.java Fri May 22 16:41:15
2009
@@ -19,6 +19,7 @@
 
 
 import java.util.Hashtable;
+import java.util.Set;
 
 import javax.management.DynamicMBean;
 import javax.management.MBeanException;
@@ -47,6 +48,12 @@
 import org.apache.catalina.deploy.ContextResourceLink;
 import org.apache.catalina.deploy.NamingResources;
 import org.apache.catalina.valves.ValveBase;
+import org.apache.coyote.ProtocolHandler;
+import org.apache.coyote.ajp.AjpAprProtocol;
+import org.apache.coyote.ajp.AjpProtocol;
+import org.apache.coyote.http11.Http11AprProtocol;
+import org.apache.coyote.http11.Http11NioProtocol;
+import org.apache.coyote.http11.Http11Protocol;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.IntrospectionUtils;
@@ -734,33 +741,23 @@
         throws MalformedObjectNameException {
 
         ObjectName name = null;
-        if (connector.getClass().getName().indexOf("CoyoteConnector") >= 0 ) {
-            try {
-                String address = (String)
-                    IntrospectionUtils.getProperty(connector, "address");
-                Integer port = (Integer)
-                    IntrospectionUtils.getProperty(connector, "port");
-                Service service = connector.getService();
-                String serviceName = null;
-                if (service != null)
-                    serviceName = service.getName();
-                StringBuffer sb = new StringBuffer(domain);
-                sb.append(":type=Connector");
-                sb.append(",port=" + port);
-                if ((address != null) && (address.length()>0)) {
-                    sb.append(",address=" + address);
-                }
-                name = new ObjectName(sb.toString());
-                return (name);
-            } catch (Exception e) {
-                throw new MalformedObjectNameException
-                    ("Cannot create object name for " + connector+e);
+        try {
+            String address = (String)
+                IntrospectionUtils.getProperty(connector, "address");
+            Integer port = (Integer)
+                IntrospectionUtils.getProperty(connector, "port");
+            StringBuffer sb = new StringBuffer(domain);
+            sb.append(":type=Connector");
+            sb.append(",port=" + port);
+            if ((address != null) && (address.length()>0)) {
+                sb.append(",address=" + address);
             }
-        } else {
+            name = new ObjectName(sb.toString());
+            return (name);
+        } catch (Exception e) {
             throw new MalformedObjectNameException
-                ("Cannot create object name for " + connector);
+                ("Cannot create object name for " + connector+e);
         }
-
     }
 
 
@@ -1406,13 +1403,8 @@
     static void destroyMBean(Connector connector, Service service)
         throws Exception {
 
-        connector.setService(service);
-        String mname = createManagedName(connector);
-        ManagedBean managed = registry.findManagedBean(mname);
-        if (managed == null) {
-            return;
-        }
-        String domain = managed.getDomain();
+        // domain is engine name
+        String domain = service.getContainer().getName();
         if (domain == null)
             domain = mserver.getDefaultDomain();
         ObjectName oname = createObjectName(domain, connector);
@@ -1420,6 +1412,26 @@
         if( mserver.isRegistered( oname ))  {
             mserver.unregisterMBean(oname);
         }
+        // Unregister associated request processor
+        String worker = null;
+        ProtocolHandler handler = connector.getProtocolHandler();
+        if (handler instanceof Http11Protocol) {
+            worker = ((Http11Protocol)handler).getName();
+        } else if (handler instanceof Http11NioProtocol) {
+            worker = ((Http11NioProtocol)handler).getName();
+        } else if (handler instanceof Http11AprProtocol) {
+            worker = ((Http11AprProtocol)handler).getName();
+        } else if (handler instanceof AjpProtocol) {
+            worker = ((AjpProtocol)handler).getName();
+        } else if (handler instanceof AjpAprProtocol) {
+            worker = ((AjpAprProtocol)handler).getName();
+        }
+        ObjectName query = new ObjectName(
+                domain + ":type=RequestProcessor,worker=" + worker + ",*");
+        Set<ObjectName> results = mserver.queryNames(query, null);
+        for(ObjectName result : results) {
+            mserver.unregisterMBean(result);
+        }
     }
 
 
@@ -1434,12 +1446,7 @@
     static void destroyMBean(Context context)
         throws Exception {
 
-        String mname = createManagedName(context);
-        ManagedBean managed = registry.findManagedBean(mname);
-        if (managed == null) {
-            return;
-        }
-        String domain = managed.getDomain();
+        String domain = context.getParent().getParent().getName();
         if (domain == null)
             domain = mserver.getDefaultDomain();
         ObjectName oname = createObjectName(domain, context);
@@ -1486,6 +1493,12 @@
     static void destroyMBean(ContextResource resource)
         throws Exception {
 
+        // If this is a user database resource need to destroy groups, roles,
+        // users and UserDatabase mbean
+        if ("org.apache.catalina.UserDatabase".equals(resource.getType())) {
+            destroyMBeanUserDatabase(resource.getName());
+        }
+
         String mname = createManagedName(resource);
         ManagedBean managed = registry.findManagedBean(mname);
         if (managed == null) {
@@ -1536,13 +1549,7 @@
      */
     static void destroyMBean(Engine engine)
         throws Exception {
-
-        String mname = createManagedName(engine);
-        ManagedBean managed = registry.findManagedBean(mname);
-        if (managed == null) {
-            return;
-        }
-        String domain = managed.getDomain();
+        String domain = engine.getName();
         if (domain == null)
             domain = mserver.getDefaultDomain();
         ObjectName oname = createObjectName(domain, engine);
@@ -1589,12 +1596,7 @@
     static void destroyMBean(Host host)
         throws Exception {
 
-        String mname = createManagedName(host);
-        ManagedBean managed = registry.findManagedBean(mname);
-        if (managed == null) {
-            return;
-        }
-        String domain = managed.getDomain();
+        String domain = host.getParent().getName();
         if (domain == null)
             domain = mserver.getDefaultDomain();
         ObjectName oname = createObjectName(domain, host);
@@ -1676,7 +1678,7 @@
         if (domain == null)
             domain = mserver.getDefaultDomain();
         ObjectName oname = createObjectName(domain, resources);
-       if( mserver.isRegistered(oname) )
+        if( mserver.isRegistered(oname) )
             mserver.unregisterMBean(oname);
 
     }
@@ -1756,6 +1758,16 @@
         ObjectName oname = createObjectName(domain, server);
         if( mserver.isRegistered(oname) )
             mserver.unregisterMBean(oname);
+        
+        // Global String cache - fixed name
+        oname = new ObjectName("Catalina:type=StringCache");
+        if( mserver.isRegistered(oname) )
+            mserver.unregisterMBean(oname);
+
+        // MBean Factory - fixed name
+        oname = new ObjectName("Catalina:type=MBeanFactory");
+        if( mserver.isRegistered(oname) )
+            mserver.unregisterMBean(oname);
 
     }
 
@@ -1839,6 +1851,51 @@
 
 
     /**
+     * Deregister the MBean for the
+     * <code>UserDatabase</code> object with this name.
+     *
+     * @param userDatabase The UserDatabase to be managed
+     *
+     * @exception Exception if an MBean cannot be deregistered
+     */
+    static void destroyMBeanUserDatabase(String userDatabase)
+        throws Exception {
+
+        ObjectName query = null;
+        Set<ObjectName> results = null;
+        
+        // Groups
+        query = new ObjectName(
+                "Users:type=Group,database=" + userDatabase + ",*");
+        results = mserver.queryNames(query, null);
+        for(ObjectName result : results) {
+            mserver.unregisterMBean(result);
+        }
+        
+        // Roles
+        query = new ObjectName(
+                "Users:type=Role,database=" + userDatabase + ",*");
+        results = mserver.queryNames(query, null);
+        for(ObjectName result : results) {
+            mserver.unregisterMBean(result);
+        }
+        
+        // Users
+        query = new ObjectName(
+                "Users:type=User,database=" + userDatabase + ",*");
+        results = mserver.queryNames(query, null);
+        for(ObjectName result : results) {
+            mserver.unregisterMBean(result);
+        }
+
+        // The database itself
+        ObjectName db = new ObjectName(
+                "Users:type=UserDatabase,database=" + userDatabase);
+        mserver.unregisterMBean(db);
+    }
+
+
+    /**
      * Deregister the MBean for this
      * <code>Valve</code> object.
      *

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/mbeans/ServerLifecycleListener.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/mbeans/ServerLifecycleListener.java?rev=777611&r1=777610&r2=777611&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/mbeans/ServerLifecycleListener.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/mbeans/ServerLifecycleListener.java Fri
May 22 16:41:15 2009
@@ -148,7 +148,7 @@
             createMBeans();
             */
 
-        } else if (Lifecycle.STOP_EVENT.equals(event.getType())) {
+        } else if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType())) {
             try {
                 if (lifecycle instanceof Server) {
                     destroyMBeans((Server)lifecycle);
@@ -640,10 +640,6 @@
      */
     protected void createMBeans(Service service) throws Exception {
 
-        // Create the MBean for the Service itself
-        if (log.isDebugEnabled())
-            log.debug("Creating MBean for Service " + service);
-        //MBeanUtils.createMBean(service);
         if (service instanceof StandardService) {
             ((StandardService) service).addPropertyChangeListener(this);
         }
@@ -676,10 +672,10 @@
     protected void destroyMBeans(Connector connector, Service service)
         throws Exception {
 
-//        // deregister the MBean for the Connector itself
-//        if (log.isDebugEnabled())
-//            log.debug("Destroying MBean for Connector " + connector);
-//        MBeanUtils.destroyMBean(connector, service);
+        // deregister the MBean for the Connector itself
+        if (log.isDebugEnabled())
+            log.debug("Destroying MBean for Connector " + connector);
+        MBeanUtils.destroyMBean(connector, service);
 
     }
 
@@ -727,7 +723,7 @@
         // deregister the MBean for the Context itself
         if (log.isDebugEnabled())
             log.debug("Destroying MBean for Context " + context);
-        //MBeanUtils.destroyMBean(context);
+        MBeanUtils.destroyMBean(context);
         if (context instanceof StandardContext) {
             ((StandardContext) context).
                 removePropertyChangeListener(this);
@@ -865,7 +861,7 @@
         if (log.isDebugEnabled()) {
             log.debug("Destroying MBean for Engine " + engine);
         }
-        //MBeanUtils.destroyMBean(engine);
+        MBeanUtils.destroyMBean(engine);
 
     }
 
@@ -902,7 +898,7 @@
         if (log.isDebugEnabled()) {
             log.debug("Destroying MBean for Host " + host);
         }
-        //MBeanUtils.destroyMBean(host);
+        MBeanUtils.destroyMBean(host);
 
     }
 
@@ -979,7 +975,7 @@
         if (log.isDebugEnabled()) {
             log.debug("Destroying MBean for Server " + server);
         }
-        //MBeanUtils.destroyMBean(server);
+        MBeanUtils.destroyMBean(server);
         if (server instanceof StandardServer) {
             ((StandardServer) server).removePropertyChangeListener(this);
         }
@@ -1000,20 +996,15 @@
         // Deregister the MBeans for the associated Engine
         Engine engine = (Engine) service.getContainer();
         if (engine != null) {
-            //destroyMBeans(engine);
+            destroyMBeans(engine);
         }
 
-//        // Deregister the MBeans for the corresponding Connectors
-//        Connector connectors[] = service.findConnectors();
-//        for (int j = 0; j < connectors.length; j++) {
-//            destroyMBeans(connectors[j], service);
-//        }
-
-        // Deregister the MBean for the Service itself
-        if (log.isDebugEnabled()) {
-            log.debug("Destroying MBean for Service " + service);
+        // Deregister the MBeans for the corresponding Connectors
+        Connector connectors[] = service.findConnectors();
+        for (int j = 0; j < connectors.length; j++) {
+            destroyMBeans(connectors[j], service);
         }
-        //MBeanUtils.destroyMBean(service);
+
         if (service instanceof StandardService) {
             ((StandardService) service).removePropertyChangeListener(this);
         }

Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=777611&r1=777610&r2=777611&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Fri May 22 16:41:15 2009
@@ -47,6 +47,10 @@
         <bug>46967</bug>: Better handling of errors when trying to use
         Manager.randomFile. Based on a patch by Kirk Wolf. (markt)
       </fix>
+      <fix>
+        <bug>47046</bug>: Unregister all MBeans, including when non-default
+        engine names are used. (markt)
+      </fix>
     </changelog>
   </subsection>
 </section>



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


Mime
View raw message