[jboss-cvs] JBossAS SVN: r59168 - branches/JBoss_4_0_4_GA_CP/system/src/main/org/jboss/system/server/jmx

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Dec 19 21:15:24 EST 2006


Author: scott.stark at jboss.org
Date: 2006-12-19 21:15:22 -0500 (Tue, 19 Dec 2006)
New Revision: 59168

Modified:
   branches/JBoss_4_0_4_GA_CP/system/src/main/org/jboss/system/server/jmx/LazyMBeanServer.java
Log:
ASPATCH-136, reload the server domains on InstanceNotFoundException failures in isInstanceOf calls.

Modified: branches/JBoss_4_0_4_GA_CP/system/src/main/org/jboss/system/server/jmx/LazyMBeanServer.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/system/src/main/org/jboss/system/server/jmx/LazyMBeanServer.java	2006-12-20 01:54:57 UTC (rev 59167)
+++ branches/JBoss_4_0_4_GA_CP/system/src/main/org/jboss/system/server/jmx/LazyMBeanServer.java	2006-12-20 02:15:22 UTC (rev 59168)
@@ -1,29 +1,31 @@
 /*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
 package org.jboss.system.server.jmx;
 
 import java.io.ObjectInputStream;
 import java.lang.reflect.Constructor;
 import java.util.Set;
+import java.util.HashSet;
+import java.util.Collections;
 import javax.management.MBeanServer;
 import javax.management.ObjectInstance;
 import javax.management.ObjectName;
@@ -59,11 +61,23 @@
 public class LazyMBeanServer
    implements MBeanServer
 {
+   /** The MBeanServer that was registered */
    private static MBeanServer registeredServer;
+   /** The jboss MBeanServer implementation */
    private static MBeanServer theServer;
+   /** The jdk MBeanServer implementation */
    private static MBeanServer platformServer;
+   /** The default domain to use for mbeans */
    private static String defaultDomain;
    private static MBeanServerDelegate theDelegate;
+   /** A HashSet<String> of the jmx domain prefixes that need to be
+    * handled by the platform server
+    */
+   private static Set platformServerDomains = Collections.synchronizedSet(new HashSet());
+   /** A HashSet<String> of the jmx domain prefixes that need to be
+    * handled by the jboss server
+    */
+   private static Set serverDomains = Collections.synchronizedSet(new HashSet());
 
    /**
     * Called by the ServerImpl to reset theServer implementation to the jboss
@@ -86,6 +100,11 @@
          Constructor ctor = c.getConstructor(sig);
          theServer = (MBeanServer) ctor.newInstance(args);
          coreServer = theServer;
+         String[] domains = theServer.getDomains();
+         for(int n = 0; n < domains.length; n ++)
+         {
+            serverDomains.add(domains[n]);
+         }
       }
       return coreServer;
    }
@@ -104,6 +123,32 @@
       return outerServer;
    }
 
+   /**
+    * Updates the platformServerDomains and serverDomains sets of jmx
+    * domain names.
+    */
+   public static synchronized void reloadDomains()
+   {
+      // Initialize the platform server domains
+      String[] domains = platformServer.getDomains();
+      for(int n = 0; n < domains.length; n ++)
+      {
+         platformServerDomains.add(domains[n]);
+      }
+      domains = theServer.getDomains();
+      for(int n = 0; n < domains.length; n ++)
+      {
+         serverDomains.add(domains[n]);
+      }
+   }
+   /**
+    * 
+    * @param domain - the default domain when an MBean is
+    *        registered with an ObjectName without a domain
+    * @param outer - the wrapping MBeanServer, passed to MBeans
+    *        at registration.
+    * @param delegate the delegate to use for Notifications.
+    */
    LazyMBeanServer(String domain, MBeanServer outer,
       MBeanServerDelegate delegate)
    {
@@ -112,6 +157,12 @@
       theServer = outer;
       registeredServer = this;
       theDelegate = delegate;
+      // Initialize the platform server domains
+      String[] domains = platformServer.getDomains();
+      for(int n = 0; n < domains.length; n ++)
+      {
+         platformServerDomains.add(domains[n]);
+      }
    }
 
    public ObjectInstance createMBean(String className, ObjectName name)
@@ -301,18 +352,47 @@
       getServer(name).removeNotificationListener(name, listener, filter, handback);
    }
 
+   /**
+    * Obtains the MBeanInfo for the given ObjectName. In the event of an
+    * InstanceNotFoundException, the jmx domain to server sets are reloaded
+    * by calling reloadDomains(), and the lookup retried.
+    * @param name
+    * @return
+    * @throws InstanceNotFoundException
+    * @throws IntrospectionException
+    * @throws ReflectionException
+    */
    public MBeanInfo getMBeanInfo(ObjectName name)
       throws InstanceNotFoundException, IntrospectionException,
       ReflectionException
    {
-      MBeanInfo info = getServer(name).getMBeanInfo(name);
+      MBeanInfo info = null;
+      try
+      {
+         info = getServer(name).getMBeanInfo(name);
+      }
+      catch(InstanceNotFoundException e)
+      {
+         reloadDomains();
+         info = getServer(name).getMBeanInfo(name);
+      }
       return info;
    }
 
    public boolean isInstanceOf(ObjectName name, String className)
       throws InstanceNotFoundException
    {
-      return getServer(name).isInstanceOf(name, className);
+      boolean isInstanceOf = false;
+      try
+      {
+         isInstanceOf = getServer(name).isInstanceOf(name, className);
+      }
+      catch(InstanceNotFoundException e)
+      {
+         reloadDomains();
+         isInstanceOf = getServer(name).isInstanceOf(name, className);
+      }
+      return isInstanceOf;
    }
 
    public Object instantiate(String className)
@@ -382,16 +462,20 @@
    }
 
    /**
-    * Choose the MBeanServer based on the ObjectName domain. The current
-    * implementation chooses the platform MBeanServer for any domain starting
-    * with "java".
+    * Choose the MBeanServer based on the ObjectName domain. If the serverDomain
+    * contains the domain of the name, theServer is returned. If the 
+    * platformServerDomains set contains the domain of the name, the
+    * platformServer is returned. For an unknown domain theServer is returned.
     * 
     * @param name
     * @return Either the platform MBeanServer, or the jboss MBeanServer
     */ 
    private MBeanServer getServer(ObjectName name)
    {
-      if( name != null && name.getDomain().startsWith("java") )
+      String domain = name != null ? name.getDomain() : "";
+      if( serverDomains.contains(domain) )
+         return theServer;
+      if( platformServerDomains.contains(domain) )
          return platformServer;
       return theServer;
    }




More information about the jboss-cvs-commits mailing list