djencks 2003/11/13 10:21:56
Modified: modules/kernel/src/java/org/apache/geronimo/kernel/service
GeronimoMBean.java
Added: modules/kernel/src/test/org/apache/geronimo/kernel/service
BootstrapTestObject.java GeronimoMBeanTest.java
Log:
Added GeronimoMBean bootstrap constructor that takes a class name. The class
needs a static method 'getGeronimoMBeanInfo' supplying the GeronimoMBeanInfo
for the mbean
Revision Changes Path
1.1
incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/service/BootstrapTestObject.java
Index: BootstrapTestObject.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.kernel.service;
/**
*
*
* @version $VERSION$ Nov 13, 2003$
*
* */
public class BootstrapTestObject {
public static GeronimoMBeanInfo getGeronimoMBeanInfo() {
GeronimoMBeanInfo mbeanInfo = new GeronimoMBeanInfo();
mbeanInfo.setTargetClass(BootstrapTestObject.class.getName());
mbeanInfo.addOperationInfo(new GeronimoOperationInfo("testme"));
return mbeanInfo;
}
public String testme() {
return "I respond...";
}
}
1.1
incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/service/GeronimoMBeanTest.java
Index: GeronimoMBeanTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.kernel.service;
import javax.management.ObjectName;
import junit.framework.TestCase;
import org.apache.geronimo.kernel.jmx.JMXKernel;
/**
*
*
* @version $VERSION$ Nov 13, 2003$
*
* */
public class GeronimoMBeanTest extends TestCase {
private JMXKernel kernel;
protected void setUp() throws Exception {
kernel = new JMXKernel("geronimo.test");
kernel.getMBeanServer().createMBean("org.apache.geronimo.kernel.service.DependencyService2",
new ObjectName("geronimo.boot:role=DependencyService2"));
}
protected void tearDown() throws Exception {
kernel.release();
}
public void testBootstrapConstructor() throws Exception {
GeronimoMBean geronimoMBean = new
GeronimoMBean("org.apache.geronimo.kernel.service.BootstrapTestObject");
assertTrue("Expected mbeanInfo to be loaded",
geronimoMBean.getMBeanInfo() != null);
ObjectName objectName =
ObjectName.getInstance("geronimo.test:role=BootstrapTest");
kernel.getMBeanServer().registerMBean(geronimoMBean, objectName);
kernel.getMBeanServer().invoke(objectName, "testme", null, null);
}
}
1.7 +19 -1
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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- GeronimoMBean.java 11 Nov 2003 16:00:59 -0000 1.6
+++ GeronimoMBean.java 13 Nov 2003 18:21:56 -0000 1.7
@@ -56,6 +56,7 @@
package org.apache.geronimo.kernel.service;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -109,6 +110,23 @@
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.
+ * @param className
+ * @throws Exception
+ */
+ public GeronimoMBean(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[] {});
}
public ObjectName preRegister(MBeanServer server, ObjectName name)
throws Exception {