cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From giac...@apache.org
Subject svn commit: r359231 - /cocoon/trunk/src/java/org/apache/cocoon/util/JMXUtils.java
Date Tue, 27 Dec 2005 16:25:30 GMT
Author: giacomo
Date: Tue Dec 27 08:25:27 2005
New Revision: 359231

URL: http://svn.apache.org/viewcvs?rev=359231&view=rev
Log:
added additional construcor signature (include ComponentInfo)

Modified:
    cocoon/trunk/src/java/org/apache/cocoon/util/JMXUtils.java

Modified: cocoon/trunk/src/java/org/apache/cocoon/util/JMXUtils.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/util/JMXUtils.java?rev=359231&r1=359230&r2=359231&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/util/JMXUtils.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/util/JMXUtils.java Tue Dec 27 08:25:27 2005
@@ -43,14 +43,14 @@
  * Utility methods for JMX
  *
  * @version $Id$
-  */
+ */
 public class JMXUtils {
-    //~ Static fields/initializers ---------------------------------------------
+    //~ Static fields/initializers ----------------------------------------------------------------------
 
     /** The {@link MBeanServer} first found */
     private static MBeanServer mbeanServer = getInitialMBeanServer();
 
-    //~ Constructors -----------------------------------------------------------
+    //~ Constructors ------------------------------------------------------------------------------------
 
     /**
      * Private c'tor: its a Utility class
@@ -59,7 +59,7 @@
         super();
     }
 
-    //~ Methods ----------------------------------------------------------------
+    //~ Methods -----------------------------------------------------------------------------------------
 
     /**
      * Find a JMX domain name at various places
@@ -76,8 +76,7 @@
 
         if(jmxDomain == null) {
             // next from the CoreServiceManager managing this component
-            if((serviceManager != null) &&
-               serviceManager instanceof CoreServiceManager) {
+            if((serviceManager != null) && serviceManager instanceof CoreServiceManager)
{
                 // next from the CoreServiceManager managing this component
                 jmxDomain = ((CoreServiceManager)serviceManager).getJmxDefaultDomain();
             } else {
@@ -100,8 +99,7 @@
     public static String findJmxName(final String pJmxName,
                                      final String pClassName) {
         String jmxName = pJmxName;
-        final String className =
-            ((pClassName == null) ? "unknown" : pClassName);
+        final String className = ((pClassName == null) ? "unknown" : pClassName);
 
         if(jmxName == null) {
             // otherwise construct one from the service class name
@@ -205,8 +203,7 @@
      */
     public static ObjectInstance setupJmxFor(final Object bean,
                                              final ComponentInfo info) {
-        return setupJmxFor(bean, info,
-                           new ConsoleLogger(ConsoleLogger.LEVEL_INFO));
+        return setupJmxFor(bean, info, new ConsoleLogger(ConsoleLogger.LEVEL_INFO));
     }
 
     /**
@@ -230,17 +227,25 @@
 
             try {
                 // try to find a MBean for bean
-                final Class mbeanClass =
-                    beanClass.getClassLoader().loadClass(mbeanClassName);
-                final Constructor ctor =
-                    mbeanClass.getConstructor(new Class[] {beanClass});
-                final Object mbean = ctor.newInstance(new Object[] {bean});
+                final Class mbeanClass = beanClass.getClassLoader().loadClass(mbeanClassName);
+                Constructor ctor = null;
+                Object mbean = null;
+
+                try {
+                    ctor = mbeanClass.getConstructor(new Class[] {beanClass, ComponentInfo.class});
+                    mbean = ctor.newInstance(new Object[] {bean, info});
+                } catch(final Exception e) {
+                    // ignore this
+                }
+
+                if(ctor == null) {
+                    ctor = mbeanClass.getConstructor(new Class[] {beanClass});
+                    mbean = ctor.newInstance(new Object[] {bean});
+                }
 
                 // see if MBean supplies some JMX ObjectName parts
-                final String mBeanSuppliedJmxDomain =
-                    callGetter(mbean, "getJmxDomain", logger);
-                final String mBeanSuppliedJmxName =
-                    callGetter(mbean, "getJmxName", logger);
+                final String mBeanSuppliedJmxDomain = callGetter(mbean, "getJmxDomain", logger);
+                final String mBeanSuppliedJmxName = callGetter(mbean, "getJmxName", logger);
                 final String mBeanSuppliedJmxNameAdditions =
                     callGetter(mbean, "getJmxNameAddition", logger);
 
@@ -258,11 +263,9 @@
                 if(mBeanSuppliedJmxName != null) {
                     objectNameBuf.append(mBeanSuppliedJmxName);
                 } else if(info.getConfiguration()
-                              .getAttribute(CoreServiceManager.JMX_NAME_ATTR_NAME,
-                                            null) != null) {
+                              .getAttribute(CoreServiceManager.JMX_NAME_ATTR_NAME, null)
!= null) {
                     objectNameBuf.append(info.getConfiguration()
-                                             .getAttribute(CoreServiceManager.JMX_NAME_ATTR_NAME,
-                                                           null));
+                                             .getAttribute(CoreServiceManager.JMX_NAME_ATTR_NAME,
null));
                 } else {
                     // if we do not have the name parts we'll construct one from the bean
class name           
                     objectNameBuf.append(genDefaultJmxName(beanClass));
@@ -279,15 +282,7 @@
 
                 while(mbeanServer.isRegistered(on)) {
                     instance++;
-                    on = new ObjectName(objectNameBuf.toString() +
-                                        ",instance=" + instance);
-                }
-
-                if(logger.isDebugEnabled()) {
-                    logger.debug("Establishing JMX support for bean " +
-                                 bean.getClass().getName() +
-                                 ",info.serviceClassName=" +
-                                 info.getServiceClassName());
+                    on = new ObjectName(objectNameBuf.toString() + ",instance=" + instance);
                 }
 
                 return mbeanServer.registerMBean(mbean, on);
@@ -295,26 +290,22 @@
                 // happens if a component doesn't have a MBean to support it for management
                 if(logger.isDebugEnabled()) {
                     logger.debug("Class " + beanClass.getName() +
-                                 " doesn't have a supporting MBean called " +
-                                 mbeanClassName);
+                                 " doesn't have a supporting MBean called " + mbeanClassName);
                 }
             } catch(final NoSuchMethodException nsme) {
                 logger.warn("MBean " + mbeanClassName +
                             " doesn't have a constructor that accepts an instance of " +
                             info.getServiceClassName(), nsme);
             } catch(final InvocationTargetException ite) {
-                logger.warn("Cannot invoke constructor on class " +
-                            mbeanClassName, ite);
+                logger.warn("Cannot invoke constructor on class " + mbeanClassName, ite);
             } catch(final InstantiationException ie) {
                 logger.warn("Cannot instantiate class " + mbeanClassName, ie);
             } catch(final IllegalAccessException iae) {
                 logger.warn("Cannot access class " + mbeanClassName, iae);
             } catch(final MalformedObjectNameException mone) {
-                logger.warn("Invalid ObjectName '" + on + "' for MBean " +
-                            mbeanClassName, mone);
+                logger.warn("Invalid ObjectName '" + on + "' for MBean " + mbeanClassName,
mone);
             } catch(final InstanceAlreadyExistsException iaee) {
-                logger.warn("Instance for MBean " + mbeanClassName +
-                            "already exists", iaee);
+                logger.warn("Instance for MBean " + mbeanClassName + "already exists", iaee);
             } catch(final NotCompliantMBeanException ncme) {
                 logger.warn("Not compliant MBean " + mbeanClassName, ncme);
             } catch(final MBeanRegistrationException mre) {
@@ -347,8 +338,7 @@
                 try {
                     return methods[i].invoke(mbean, null).toString();
                 } catch(final Exception e) {
-                    logger.warn("Method '" + name +
-                                "' cannot be accessed on MBean " +
+                    logger.warn("Method '" + name + "' cannot be accessed on MBean " +
                                 mbean.getClass().getName());
 
                     return null;



Mime
View raw message