djencks     2003/11/14 08:13:37

  Modified:    modules/kernel/src/java/org/apache/geronimo/kernel/service
                        GeronimoMBean.java
  Log:
  Added static helper method to try to call static getGeronimoMBeanInfo method 
on class loaded from supplied name
  
  Revision  Changes    Path
  1.8       +36 -7     
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service/GeronimoMBean.java
  
  Index: GeronimoMBean.java
  ===================================================================
  RCS file: 
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/service/GeronimoMBean.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- GeronimoMBean.java        13 Nov 2003 18:21:56 -0000      1.7
  +++ GeronimoMBean.java        14 Nov 2003 16:13:37 -0000      1.8
  @@ -111,22 +111,31 @@
       public GeronimoMBean(GeronimoMBeanInfo mbeanInfo) {
           this.mbeanInfo = mbeanInfo;
       }
  -
       /**
  -     * "Bootstrapping" constructor.  The class specified is loaded and the 
static method
  -     * "getGeronimoMBeanInfo" is called to get the mbean info.  Usually one 
will include
  -     * this static method in the class to be wrapped in the GeronimoMBean 
instance.
  +     * Static helper to try to gett the GeronimoMBeanInfo from the class 
supplied.
        * @param className
  +     * @return GeronimoMBeanInfo generated by supplied class
        * @throws Exception
        */
  -    public GeronimoMBean(String className) throws Exception {
  +    public static GeronimoMBeanInfo getGeronimoMBeanInfo(String className) 
throws Exception {
           ClassLoader cl = Thread.currentThread().getContextClassLoader();
           if (cl == null) {
               cl = ClassLoader.getSystemClassLoader();
           }
           Class clazz = cl.loadClass(className);
           Method m = clazz.getDeclaredMethod("getGeronimoMBeanInfo", new 
Class[] {});
  -        mbeanInfo = (GeronimoMBeanInfo)m.invoke(clazz, new Object[] {});
  +        return (GeronimoMBeanInfo)m.invoke(clazz, new Object[] {});
  +    }
  +
  +    /**
  +     * "Bootstrapping" constructor.  The class specified is loaded and the 
static method
  +     * "getGeronimoMBeanInfo" is called to get the mbean info.  Usually one 
will include
  +     * this static method in the class to be wrapped in the GeronimoMBean 
instance.
  +     * @param className
  +     * @throws Exception
  +     */
  +    public GeronimoMBean(String className) throws Exception {
  +        mbeanInfo = getGeronimoMBeanInfo(className);
       }
   
       public ObjectName preRegister(MBeanServer server, ObjectName name) 
throws Exception {
  @@ -205,6 +214,26 @@
               super.postRegister(registrationDone);
           } finally {
               Thread.currentThread().setContextClassLoader(oldClassLoader);
  +        }
  +
  +        //For use primarily in boot mbeans before service deployer is set up
  +        if (mbeanInfo.isAutostart()) {
  +            try {
  +                start();
  +            } catch (Exception e) {
  +                log.info("Exception auto-starting GeronimoMBean " + 
objectName, e);
  +            }
  +        }
  +    }
  +
  +    public void preDeregister() {
  +        //For use primarily in boot mbeans before service deployer is set up
  +        if (mbeanInfo.isAutostart()) {
  +            try {
  +                stop();
  +            } catch (Exception e) {
  +                log.info("Exception auto-starting GeronimoMBean " + 
objectName, e);
  +            }
           }
       }
   
  
  
  

Reply via email to