dain 2004/06/04 15:31:56
Modified: modules/j2ee/src/java/org/apache/geronimo/j2ee/management/impl
J2EEApplicationImpl.java J2EEDomainImpl.java
J2EEServerImpl.java Util.java
modules/j2ee/src/test/org/apache/geronimo/j2ee/management
JVMTest.java
modules/jmx-remoting/src/java/org/apache/geronimo/jmxremoting
JMXConnector.java
modules/kernel/src/java/org/apache/geronimo/gbean
GBeanContext.java
modules/kernel/src/java/org/apache/geronimo/gbean/jmx
AbstractManagedObject.java GBeanMBean.java
GBeanMBeanAttribute.java GBeanMBeanContext.java
RawInvoker.java
modules/kernel/src/test/org/apache/geronimo/gbean/jmx
GBeanMBeanAttributeTest.java
modules/kernel/src/test/org/apache/geronimo/kernel
GBeanTest.java MockEndpoint.java MockGBean.java
modules/remoting/src/java/org/apache/geronimo/remoting/jmx
MBeanServerStub.java
modules/remoting/src/java/org/apache/geronimo/remoting/router
JMXRouter.java
modules/security/src/java/org/apache/geronimo/security/jaas
ConfigurationEntry.java
ConfigurationEntryLocal.java
ConfigurationEntryRealmLocal.java
ConfigurationEntryRealmRemote.java
modules/security/src/java/org/apache/geronimo/security/remoting/jmx
LoginServiceStub.java
Log:
Added special atributes objectName, classLoader, kernel, and gbeanContext.
Special attributes are automacitally reconized and injected by the gbean
container
Revision Changes Path
1.3 +28 -39
incubator-geronimo/modules/j2ee/src/java/org/apache/geronimo/j2ee/management/impl/J2EEApplicationImpl.java
Index: J2EEApplicationImpl.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/j2ee/src/java/org/apache/geronimo/j2ee/management/impl/J2EEApplicationImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- J2EEApplicationImpl.java 2 Jun 2004 05:33:02 -0000 1.2
+++ J2EEApplicationImpl.java 4 Jun 2004 22:31:56 -0000 1.3
@@ -20,44 +20,36 @@
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
-import org.apache.geronimo.gbean.GBean;
-import org.apache.geronimo.gbean.GBeanContext;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoFactory;
-import org.apache.geronimo.gbean.WaitingException;
-import org.apache.geronimo.gbean.jmx.GBeanMBeanContext;
import org.apache.geronimo.j2ee.management.J2EEServer;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.jmx.JMXUtil;
/**
* @version $Revision$ $Date$
*/
-public class J2EEApplicationImpl implements GBean {
- private String deploymentDescriptor;
- private String baseName;
- private GBeanContext context;
- private J2EEServer server;
+public class J2EEApplicationImpl {
+ private final String deploymentDescriptor;
+ private final String baseName;
+ private final Kernel kernel;
+ private final J2EEServer server;
+
+ public J2EEApplicationImpl(Kernel kernel, String objectName, J2EEServer
server, String deploymentDescriptor) {
+ ObjectName myObjectName = JMXUtil.getObjectName(objectName);
+ verifyObjectName(myObjectName);
+
+ // build the base name used to query the server for child modules
+ Hashtable keyPropertyList = myObjectName.getKeyPropertyList();
+ String name = (String) keyPropertyList.get("name");
+ String j2eeServerName = (String) keyPropertyList.get("J2EEServer");
+ baseName = myObjectName.getDomain() + ":J2EEServer=" +
j2eeServerName + ",J2EEApplication=" + name + ",";
- public J2EEApplicationImpl(J2EEServer server, String
deploymentDescriptor) {
+ this.kernel = kernel;
this.server = server;
this.deploymentDescriptor = deploymentDescriptor;
}
- public void setGBeanContext(GBeanContext context) {
- this.context = context;
- if (context != null) {
- ObjectName objectName = context.getObjectName();
- verifyObjectName(objectName);
-
- // build the base name used to query the server for child modules
- Hashtable keyPropertyList = objectName.getKeyPropertyList();
- String name = (String) keyPropertyList.get("name");
- String j2eeServerName = (String)
keyPropertyList.get("J2EEServer");
- baseName = objectName.getDomain() + ":J2EEServer=" +
j2eeServerName + ",J2EEApplication=" + name + ",";
- } else {
- baseName = null;
- }
- }
-
/**
* ObjectName must match this pattern:
* <p/>
@@ -82,17 +74,8 @@
}
}
- public void doStart() throws WaitingException, Exception {
- }
-
- public void doStop() throws WaitingException, Exception {
- }
-
- public void doFail() {
- }
-
public String[] getmodules() throws MalformedObjectNameException {
- return Util.getObjectNames(((GBeanMBeanContext) context).getServer(),
+ return Util.getObjectNames(kernel,
baseName,
new String[]{"AppClientModule", "EJBModule", "WebModule",
"ResourceAdapterModule"});
}
@@ -109,12 +92,18 @@
static {
GBeanInfoFactory infoFactory = new
GBeanInfoFactory(J2EEApplicationImpl.class);
+ infoFactory.addAttribute("kernel", Kernel.class, false);
+ infoFactory.addAttribute("objectName", String.class, false);
infoFactory.addReference("j2eeServer", J2EEServer.class);
infoFactory.addAttribute("deploymentDescriptor", String.class, true);
infoFactory.addAttribute("modules", String[].class, false);
- infoFactory.setConstructor(new String[]{"j2eeServer",
"deploymentDescriptor"});
-
+ infoFactory.setConstructor(new String[]{
+ "kernel",
+ "objectName",
+ "j2eeServer",
+ "deploymentDescriptor"});
+
GBEAN_INFO = infoFactory.getBeanInfo();
}
1.3 +18 -29
incubator-geronimo/modules/j2ee/src/java/org/apache/geronimo/j2ee/management/impl/J2EEDomainImpl.java
Index: J2EEDomainImpl.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/j2ee/src/java/org/apache/geronimo/j2ee/management/impl/J2EEDomainImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- J2EEDomainImpl.java 2 Jun 2004 05:33:02 -0000 1.2
+++ J2EEDomainImpl.java 4 Jun 2004 22:31:56 -0000 1.3
@@ -21,28 +21,24 @@
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
-import org.apache.geronimo.gbean.GBean;
-import org.apache.geronimo.gbean.GBeanContext;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoFactory;
-import org.apache.geronimo.gbean.jmx.GBeanMBeanContext;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.jmx.JMXUtil;
/**
* @version $Revision$ $Date$
*/
-public class J2EEDomainImpl implements GBean {
- private GBeanContext context;
- private String baseName;
-
- public void setGBeanContext(GBeanContext context) {
- this.context = context;
- if (context != null) {
- ObjectName objectName = context.getObjectName();
- verifyObjectName(objectName);
- baseName = objectName.getDomain() + ":";
- } else {
- baseName = null;
- }
+public class J2EEDomainImpl {
+ private final Kernel kernel;
+ private final String baseName;
+
+ public J2EEDomainImpl(Kernel kernel, String objectName) {
+ ObjectName myObjectName = JMXUtil.getObjectName(objectName);
+ verifyObjectName(myObjectName);
+ baseName = myObjectName.getDomain() + ":";
+
+ this.kernel = kernel;
}
/**
@@ -66,18 +62,7 @@
public String[] getservers() throws MalformedObjectNameException {
- return Util.getObjectNames(((GBeanMBeanContext) context).getServer(),
- baseName,
- new String[]{"J2EEServer"});
- }
-
- public void doStart() {
- }
-
- public void doStop() {
- }
-
- public void doFail() {
+ return Util.getObjectNames(kernel, baseName, new
String[]{"J2EEServer"});
}
public static final GBeanInfo GBEAN_INFO;
@@ -85,7 +70,11 @@
static {
GBeanInfoFactory infoFactory = new
GBeanInfoFactory(J2EEDomainImpl.class);
+ infoFactory.addAttribute("kernel", Kernel.class, false);
+ infoFactory.addAttribute("objectName", String.class, false);
infoFactory.addAttribute("servers", String[].class, false);
+
+ infoFactory.setConstructor(new String[]{"kernel", "objectName"});
GBEAN_INFO = infoFactory.getBeanInfo();
}
1.3 +22 -38
incubator-geronimo/modules/j2ee/src/java/org/apache/geronimo/j2ee/management/impl/J2EEServerImpl.java
Index: J2EEServerImpl.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/j2ee/src/java/org/apache/geronimo/j2ee/management/impl/J2EEServerImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- J2EEServerImpl.java 2 Jun 2004 05:33:02 -0000 1.2
+++ J2EEServerImpl.java 4 Jun 2004 22:31:56 -0000 1.3
@@ -21,39 +21,32 @@
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
-import org.apache.geronimo.gbean.GBean;
-import org.apache.geronimo.gbean.GBeanContext;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoFactory;
-import org.apache.geronimo.gbean.jmx.GBeanMBeanContext;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.jmx.JMXUtil;
import org.apache.geronimo.system.serverinfo.ServerInfo;
/**
* @version $Revision$ $Date$
*/
-public class J2EEServerImpl implements GBean {
+public class J2EEServerImpl {
private static final String SERVER_VENDOR = "The Apache Software
Foundation";
+ private final Kernel kernel;
+ private final String baseName;
private final ServerInfo serverInfo;
- private GBeanContext context;
- private String baseName;
- public J2EEServerImpl(ServerInfo serverInfo) {
- this.serverInfo = serverInfo;
- }
+ public J2EEServerImpl(Kernel kernel, String objectName, ServerInfo
serverInfo) {
+ ObjectName myObjectName = JMXUtil.getObjectName(objectName);
+ verifyObjectName(myObjectName);
+
+ // build the base name used to query the server for child modules
+ Hashtable keyPropertyList = myObjectName.getKeyPropertyList();
+ String name = (String) keyPropertyList.get("name");
+ baseName = myObjectName.getDomain() + ":J2EEServer=" + name + ",";
- public void setGBeanContext(GBeanContext context) {
- this.context = context;
- if (context != null) {
- ObjectName objectName = context.getObjectName();
- verifyObjectName(objectName);
-
- // build the base name used to query the server for child modules
- Hashtable keyPropertyList = objectName.getKeyPropertyList();
- String name = (String) keyPropertyList.get("name");
- baseName = objectName.getDomain() + ":J2EEServer=" + name + ",";
- } else {
- baseName = null;
- }
+ this.kernel = kernel;
+ this.serverInfo = serverInfo;
}
/**
@@ -78,31 +71,20 @@
}
- public void doStart() {
- }
-
- public void doStop() {
- }
-
- public void doFail() {
- }
-
public String[] getdeployedObjects() throws MalformedObjectNameException
{
- return Util.getObjectNames(((GBeanMBeanContext) context).getServer(),
+ return Util.getObjectNames(kernel,
baseName,
new String[]{"J2EEApplication", "AppClientModule",
"EJBModule", "WebModule", "ResourceAdapterModule"});
}
public String[] getresources() throws MalformedObjectNameException {
- return Util.getObjectNames(((GBeanMBeanContext) context).getServer(),
+ return Util.getObjectNames(kernel,
baseName,
new String[]{"JavaMailResource", "JCAConnectionFactory",
"JDBCResource", "JDBCDriver", "JMSResource", "JNDIResource", "JTAResource",
"RMI_IIOPResource", "URLResource"});
}
public String[] getjavaVMs() throws MalformedObjectNameException {
- return Util.getObjectNames(((GBeanMBeanContext) context).getServer(),
- baseName,
- new String[]{"JVM"});
+ return Util.getObjectNames(kernel, baseName, new String[]{"JVM"});
}
public String getserverVendor() {
@@ -118,6 +100,8 @@
static {
GBeanInfoFactory infoFactory = new
GBeanInfoFactory(J2EEServerImpl.class);
+ infoFactory.addAttribute("kernel", Kernel.class, false);
+ infoFactory.addAttribute("objectName", String.class, false);
infoFactory.addAttribute("deployedObjects", String[].class, false);
infoFactory.addAttribute("resources", String[].class, false);
infoFactory.addAttribute("javaVMs", String[].class, false);
@@ -126,7 +110,7 @@
infoFactory.addReference("ServerInfo", ServerInfo.class);
- infoFactory.setConstructor(new String[]{"ServerInfo"});
+ infoFactory.setConstructor(new String[]{"kernel", "objectName",
"ServerInfo"});
GBEAN_INFO = infoFactory.getBeanInfo();
}
1.5 +5 -5
incubator-geronimo/modules/j2ee/src/java/org/apache/geronimo/j2ee/management/impl/Util.java
Index: Util.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/j2ee/src/java/org/apache/geronimo/j2ee/management/impl/Util.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Util.java 19 May 2004 20:53:59 -0000 1.4
+++ Util.java 4 Jun 2004 22:31:56 -0000 1.5
@@ -20,20 +20,20 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
-import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
+import org.apache.geronimo.kernel.Kernel;
+
/**
* @version $Revision$ $Date$
*/
public class Util {
- // todo: kernel should be expanded to support name queries like the
mbean server does
- public static String[] getObjectNames(MBeanServer server, Object
parentName, String[] j2eeTypes) throws MalformedObjectNameException {
+ public static String[] getObjectNames(Kernel kernel, Object parentName,
String[] j2eeTypes) throws MalformedObjectNameException {
List objectNames = new LinkedList();
for (int i = 0; i < j2eeTypes.length; i++) {
String j2eeType = j2eeTypes[i];
- objectNames.addAll(server.queryNames(new ObjectName(parentName +
"j2eeType=" + j2eeType + ",*"), null));
+ objectNames.addAll(kernel.listGBeans(new ObjectName(parentName +
"j2eeType=" + j2eeType + ",*")));
}
String[] names = new String[objectNames.size()];
Iterator iterator = objectNames.iterator();
1.4 +3 -13
incubator-geronimo/modules/j2ee/src/test/org/apache/geronimo/j2ee/management/JVMTest.java
Index: JVMTest.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/j2ee/src/test/org/apache/geronimo/j2ee/management/JVMTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JVMTest.java 10 Mar 2004 09:58:52 -0000 1.3
+++ JVMTest.java 4 Jun 2004 22:31:56 -0000 1.4
@@ -18,20 +18,10 @@
package org.apache.geronimo.j2ee.management;
import java.net.InetAddress;
-import javax.management.ObjectName;
-import javax.management.MBeanServer;
-import org.apache.geronimo.kernel.Kernel;
-import org.apache.geronimo.kernel.jmx.JMXUtil;
import org.apache.geronimo.kernel.jmx.MBeanProxyFactory;
-import org.apache.geronimo.gbean.jmx.GBeanMBean;
-import org.apache.geronimo.j2ee.management.impl.JVMImpl;
-
-import junit.framework.TestCase;
/**
- *
- *
* @version $Revision$ $Date$
*/
public class JVMTest extends Abstract77Test {
@@ -41,14 +31,14 @@
private Runtime runtime;
public void testStandardInterface() {
- assertEquals(JVM_NAME.toString(), jvm.getobjectName());
+ assertEquals(JVM_NAME.getCanonicalName(), jvm.getobjectName());
assertEquals(System.getProperty("java.version"),
jvm.getjavaVersion());
assertEquals(System.getProperty("java.vendor"), jvm.getjavaVendor());
assertEquals(node, jvm.getnode());
}
public void testStandardAttributes() throws Exception {
- assertEquals(JVM_NAME.toString(), mbServer.getAttribute(JVM_NAME,
"objectName"));
+ assertEquals(JVM_NAME.getCanonicalName(),
mbServer.getAttribute(JVM_NAME, "objectName"));
assertEquals(System.getProperty("java.version"),
mbServer.getAttribute(JVM_NAME, "javaVersion"));
assertEquals(System.getProperty("java.vendor"),
mbServer.getAttribute(JVM_NAME, "javaVendor"));
assertEquals(node, mbServer.getAttribute(JVM_NAME, "node"));
1.3 +12 -11
incubator-geronimo/modules/jmx-remoting/src/java/org/apache/geronimo/jmxremoting/JMXConnector.java
Index: JMXConnector.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/jmx-remoting/src/java/org/apache/geronimo/jmxremoting/JMXConnector.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JMXConnector.java 2 Jun 2004 05:33:03 -0000 1.2
+++ JMXConnector.java 4 Jun 2004 22:31:56 -0000 1.3
@@ -38,7 +38,7 @@
*/
public class JMXConnector implements GBean {
private final Kernel kernel;
- private Log log;
+ private final Log log;
private String url;
private String applicationConfigName;
@@ -46,16 +46,19 @@
/**
* Constructor for creating the connector
+ *
* @param kernel a reference to the kernel
*/
- public JMXConnector(Kernel kernel) {
+ public JMXConnector(Kernel kernel, String objectName) {
this.kernel = kernel;
+ log = LogFactory.getLog(objectName);
}
/**
* Return the name of the JAAS Application Configuration Entry this
* connector uses to authenticate users. If null, users are not
* be authenticated (not recommended).
+ *
* @return the authentication configuration name
*/
public String getApplicationConfigName() {
@@ -66,6 +69,7 @@
* Set the name of the JAAS Application Configuration Entry this
* connector should use to authenticate users. If null, users will not
* be authenticated (not recommended).
+ *
* @param applicationConfigName the authentication configuration name
*/
public void setApplicationConfigName(String applicationConfigName) {
@@ -74,6 +78,7 @@
/**
* Return the JMX URL for this connector.
+ *
* @return the JMX URL for this connector
*/
public String getURL() {
@@ -82,6 +87,7 @@
/**
* Set the JMX URL for this connector
+ *
* @param url the JMX URL for this connector
*/
public void setURL(String url) {
@@ -89,13 +95,6 @@
}
public void setGBeanContext(GBeanContext context) {
- if (context != null) {
- // register
- log = LogFactory.getLog(context.getObjectName().toString());
- } else {
- // deregister
- log = null;
- }
}
public void doStart() throws WaitingException, Exception {
@@ -127,12 +126,14 @@
}
public static final GBeanInfo GBEAN_INFO;
+
static {
GBeanInfoFactory infoFactory = new
GBeanInfoFactory(JMXConnector.class);
+ infoFactory.addAttribute("objectName", String.class, false);
infoFactory.addAttribute("URL", String.class, true);
infoFactory.addAttribute("ApplicationConfigName", String.class,
true);
infoFactory.addReference("Kernel", Kernel.class);
- infoFactory.setConstructor(new String[]{"Kernel"});
+ infoFactory.setConstructor(new String[]{"Kernel", "objectName"});
GBEAN_INFO = infoFactory.getBeanInfo();
}
1.6 +11 -5
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanContext.java
Index: GBeanContext.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanContext.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- GBeanContext.java 27 May 2004 01:05:58 -0000 1.5
+++ GBeanContext.java 4 Jun 2004 22:31:56 -0000 1.6
@@ -33,7 +33,7 @@
*
* @return the current state of this component
*/
- public int getState();
+ int getState();
/**
* Attempts to bring the component into the fully running state. If an
Exception occurs while
@@ -43,7 +43,7 @@
*
* @throws Exception if a problem occurs while starting the component
*/
- public void start() throws Exception;
+ void start() throws Exception;
/**
* Attempt to bring the component into the fully stopped state. If an
exception occurs while
@@ -53,14 +53,20 @@
*
* @throws Exception if a problem occurs while stopping the component
*/
- public void stop() throws Exception;
+ void stop() throws Exception;
/**
* Moves this component to the FAILED state.
* <p/>
* The component is guaranteed to be in the failed state when the method
returns.
*/
- public void fail();
+ void fail();
+ /**
+ * Gets the object name of the gbean
+ *
+ * @return the objec name of the gbean
+ * @deprecated use an objectName GBeanAttribute instead
+ */
ObjectName getObjectName();
}
1.11 +2 -2
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/AbstractManagedObject.java
Index: AbstractManagedObject.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/AbstractManagedObject.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- AbstractManagedObject.java 27 May 2004 01:05:59 -0000 1.10
+++ AbstractManagedObject.java 4 Jun 2004 22:31:56 -0000 1.11
@@ -168,7 +168,7 @@
}
public final String getObjectName() {
- return objectName.toString();
+ return objectName.getCanonicalName();
}
public final ObjectName getObjectNameObject() {
1.21 +161 -83
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java
Index: GBeanMBean.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- GBeanMBean.java 3 Jun 2004 15:27:28 -0000 1.20
+++ GBeanMBean.java 4 Jun 2004 22:31:56 -0000 1.21
@@ -46,12 +46,14 @@
import org.apache.commons.logging.LogFactory;
import org.apache.geronimo.gbean.GAttributeInfo;
import org.apache.geronimo.gbean.GBean;
+import org.apache.geronimo.gbean.GBeanContext;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GConstructorInfo;
import org.apache.geronimo.gbean.GOperationInfo;
import org.apache.geronimo.gbean.GOperationSignature;
import org.apache.geronimo.gbean.GReferenceInfo;
import org.apache.geronimo.gbean.InvalidConfigurationException;
+import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.management.NotificationType;
/**
@@ -70,6 +72,7 @@
private static final Log log = LogFactory.getLog(GBeanMBean.class);
private final Constructor constructor;
+ private GBeanMBeanContext gbeanContext;
/**
* Gets the context class loader from the thread or the system class
loader if there is no context class loader.
@@ -161,10 +164,11 @@
/**
* Constructa a GBeanMBean using the supplied gbeanInfo and class loader
+ *
* @param gbeanInfo the metadata describing the attributes, operations,
constructor and references of the gbean
* @param classLoader the class loader used to load the gbean instance
and attribute/reference types
* @throws InvalidConfigurationException if the gbeanInfo is
inconsistent with the actual java classes, such as
- * mismatched attribute types
+ * mismatched attribute types
*/
public GBeanMBean(GBeanInfo gbeanInfo, ClassLoader classLoader) throws
InvalidConfigurationException {
this.gbeanInfo = gbeanInfo;
@@ -191,13 +195,13 @@
}
// attributes
- Set attributesSet = new HashSet();
+ Map attributesMap = new HashMap();
for (Iterator iterator = gbeanInfo.getAttributes().iterator();
iterator.hasNext();) {
GAttributeInfo attributeInfo = (GAttributeInfo) iterator.next();
- attributesSet.add(new GBeanMBeanAttribute(this, attributeInfo,
constructorTypes.containsKey(attributeInfo.getName())));
+ attributesMap.put(attributeInfo.getName(), new
GBeanMBeanAttribute(this, attributeInfo,
constructorTypes.containsKey(attributeInfo.getName())));
}
- addManagedObjectAttributes(attributesSet);
- attributes = (GBeanMBeanAttribute[]) attributesSet.toArray(new
GBeanMBeanAttribute[attributesSet.size()]);
+ addManagedObjectAttributes(attributesMap);
+ attributes = (GBeanMBeanAttribute[])
attributesMap.values().toArray(new GBeanMBeanAttribute[attributesMap.size()]);
for (int i = 0; i < attributes.length; i++) {
attributeIndex.put(attributes[i].getName(), new Integer(i));
}
@@ -323,6 +327,7 @@
* Is this a valid constructor for the GBean. This is determined based
on the argument types and
* if an argument is a reference, as determined by the boolean array,
the argument may also be
* java.util.Collection or java.util.Set.
+ *
* @param constructor the class constructor
* @param argumentTypes types of the attributes and references
* @param isReference if the argument is a gbean reference
@@ -346,12 +351,12 @@
if (!parameterType.equals(argumentTypes[i]) &&
!parameterType.equals(Collection.class.getName()) &&
!parameterType.equals(Set.class.getName())) {
- return false;
+ return false;
}
} else {
// attribute: does type match?
if (!parameterType.equals(argumentTypes[i])) {
- return false;
+ return false;
}
}
}
@@ -389,6 +394,7 @@
/**
* Gets the name of the GBean as defined in the gbean info.
+ *
* @return the gbean name
*/
public String getName() {
@@ -398,6 +404,7 @@
/**
* The class loader used to build this gbean. This class loader is set
into the thread context
* class loader before callint the target instace.
+ *
* @return the class loader used to build this gbean
*/
public ClassLoader getClassLoader() {
@@ -407,6 +414,7 @@
/**
* Is this gbean offline. An offline gbean is not registered with jmx
and effectivly invisible
* to external users.
+ *
* @return true if the gbean is offline
*/
public boolean isOffline() {
@@ -415,6 +423,7 @@
/**
* The java type of the wrapped gbean instance
+ *
* @return the java type of the gbean
*/
public Class getType() {
@@ -429,6 +438,7 @@
/**
* Gets an unmodifiable map from attribute names to index number
(Integer). This index number
* can be used to efficiently set or retrieve an attribute value.
+ *
* @return an unmodifiable map of attribute indexes by name
*/
public Map getAttributeIndex() {
@@ -438,6 +448,7 @@
/**
* Gets an unmodifiable map from operation signature
(GOperationSignature) to index number (Integer).
* This index number can be used to efficciently invoke the operation.
+ *
* @return an unmodifiable map of operation indexec by signature
*/
public Map getOperationIndex() {
@@ -446,6 +457,7 @@
/**
* Gets the GBeanInfo used to build this gbean.
+ *
* @return the GBeanInfo used to build this gbean
*/
public GBeanInfo getGBeanInfo() {
@@ -454,6 +466,7 @@
/**
* Gets the MBeanInfo equivilent of the GBeanInfo used to construct this
gbean.
+ *
* @return the MBeanInfo for this gbean
*/
public MBeanInfo getMBeanInfo() {
@@ -463,6 +476,18 @@
public synchronized ObjectName preRegister(MBeanServer server,
ObjectName objectName) throws Exception {
ObjectName returnValue = super.preRegister(server, objectName);
+ gbeanContext = new GBeanMBeanContext(server, this, objectName);
+ setAttribute("objectName", getObjectName());
+ setAttribute("gbeanContext", gbeanContext);
+ setAttribute("classLoader", classLoader);
+ try {
+ String kernelName = (String) server.getAttribute(Kernel.KERNEL,
"KernelName");
+ Kernel kernel = Kernel.getKernel(kernelName);
+ setAttribute("kernel", kernel);
+ } catch (Exception e) {
+ setAttribute("kernel", null);
+ }
+
GConstructorInfo constructorInfo = gbeanInfo.getConstructor();
Class[] parameterTypes = constructor.getParameterTypes();
@@ -517,6 +542,12 @@
}
}
+ // set the gbean context
+ if (target instanceof GBean) {
+ GBean gbean = (GBean) target;
+ gbean.setGBeanContext(gbeanContext);
+ }
+
return returnValue;
}
@@ -525,10 +556,6 @@
if (registrationDone.booleanValue()) {
// we're now offically on line
- if (target instanceof GBean) {
- GBean gbean = (GBean) target;
- gbean.setGBeanContext(new GBeanMBeanContext(server, this,
objectName));
- }
offline = false;
} else {
// we need to bring the reference back off line
@@ -536,6 +563,12 @@
references[i].offline();
}
+ gbeanContext = null;
+ if (target instanceof GBean) {
+ GBean gbean = (GBean) target;
+ gbean.setGBeanContext(null);
+ }
+
// well that didn't work, ditch the instance
target = null;
}
@@ -552,6 +585,7 @@
references[i].offline();
}
+ gbeanContext = null;
if (target instanceof GBean) {
GBean gbean = (GBean) target;
gbean.setGBeanContext(null);
@@ -599,6 +633,7 @@
/**
* Gets the attribute value using the attribute index. This is the most
efficient way to get
* an attribute as it avoids a HashMap lookup.
+ *
* @param index the index of the attribute
* @return the attribute value
* @throws ReflectionException if a problem occurs while getting the
value
@@ -612,6 +647,7 @@
/**
* Gets an attirubte's value by name. This get style is less efficient
becuse the attribute must
* first be looked up in a HashMap.
+ *
* @param attributeName the name of the attribute to retrieve
* @return the attribute value
* @throws ReflectionException if a problem occurs while getting the
value
@@ -628,6 +664,7 @@
/**
* Sets the attribute value using the attribute index. This is the most
efficient way to set
* an attribute as it avoids a HashMap lookup.
+ *
* @param index the index of the attribute
* @param value the new value of attribute value
* @throws ReflectionException if a problem occurs while setting the
value
@@ -641,6 +678,7 @@
/**
* Sets an attirubte's value by name. This set style is less efficient
becuse the attribute must
* first be looked up in a HashMap.
+ *
* @param attributeName the name of the attribute to retrieve
* @param value the new attribute value
* @throws ReflectionException if a problem occurs while getting the
value
@@ -654,6 +692,7 @@
/**
* Sets an attirubte's value by name. This set style is generally very
inefficient becuse the attribute object
* is usually constructed first and the target attribute must be looked
up in a HashMap.
+ *
* @param attributeValue the attribute object, which contains a name and
value
* @throws ReflectionException if a problem occurs while getting the
value
* @throws AttributeNotFoundException if the attribute name is not found
in the map
@@ -667,6 +706,7 @@
* Gets several attirubte values by name. This set style is very
inefficient becuse each attribute implementation
* must be looked up in a HashMap by name and each value must be wrapped
in an Attribute object and that requires
* lots of object creation. Further, any exceptions are not seen by the
caller.
+ *
* @param attributes the attribute objects, which contains a name and
value
*/
public AttributeList getAttributes(String[] attributes) {
@@ -687,6 +727,7 @@
* Sets several attirubte values by name. This set style is generally
very inefficient becuse each attribute object
* is usually constructed first and the target attribute must be looked
up in a HashMap. Further
* any exception are not seen by the caller.
+ *
* @param attributes the attribute objects, which contains a name and
value
*/
public AttributeList setAttributes(AttributeList attributes) {
@@ -721,6 +762,7 @@
* Invokes an operation on the target gbean by method signature. This
style if invocation is
* inefficient, because the target method must be looked up in a hashmap
using a freshly constructed
* GOperationSignature object.
+ *
* @param operationName the name of the operation to invoke
* @param arguments arguments to the operation
* @param types types of the operation arguemtns
@@ -739,6 +781,7 @@
/**
* Gets the object name patters for a reference.
+ *
* @param name the reference name
* @return the object name patterns for the reference
*/
@@ -748,6 +791,7 @@
/**
* Sets the object name patterns for a reference.
+ *
* @param name the reference name
* @param patterns the new object name patterns for the reference
*/
@@ -768,77 +812,111 @@
return mbeanInfo.getNotifications();
}
- private void addManagedObjectAttributes(Set attributesSet) {
- attributesSet.add(new GBeanMBeanAttribute(this,
- RAW_INVOKER,
- RawInvoker.class,
- new MethodInvoker() {
- public Object invoke(Object target, Object[] arguments)
throws Exception {
- return rawInvoker;
- }
- },
- null));
-
- attributesSet.add(new GBeanMBeanAttribute(this,
- "state",
- Integer.TYPE,
- new MethodInvoker() {
- public Object invoke(Object target, Object[] arguments)
throws Exception {
- return new Integer(getState());
- }
- },
- null));
-
- attributesSet.add(new GBeanMBeanAttribute(this,
- "objectName",
- String.class,
- new MethodInvoker() {
- public Object invoke(Object target, Object[] arguments)
throws Exception {
- return getObjectName();
- }
- },
- null));
-
- attributesSet.add(new GBeanMBeanAttribute(this,
- "startTime",
- Long.TYPE,
- new MethodInvoker() {
- public Object invoke(Object target, Object[] arguments)
throws Exception {
- return new Long(getStartTime());
- }
- },
- null));
-
- attributesSet.add(new GBeanMBeanAttribute(this,
- "stateManageable",
- Boolean.TYPE,
- new MethodInvoker() {
- public Object invoke(Object target, Object[] arguments)
throws Exception {
- return new Boolean(isStateManageable());
- }
- },
- null));
-
- attributesSet.add(new GBeanMBeanAttribute(this,
- "statisticsProvider",
- Boolean.TYPE,
- new MethodInvoker() {
- public Object invoke(Object target, Object[] arguments)
throws Exception {
- return new Boolean(isStatisticsProvider());
- }
- },
- null));
-
-
- attributesSet.add(new GBeanMBeanAttribute(this,
- "eventProvider",
- Boolean.TYPE,
- new MethodInvoker() {
- public Object invoke(Object target, Object[] arguments)
throws Exception {
- return new Boolean(isEventProvider());
- }
- },
- null));
+ private void addManagedObjectAttributes(Map attributesMap) {
+ //
+ // Special attributes
+ //
+ attributesMap.put("objectName",
+ new GBeanMBeanAttribute((GBeanMBeanAttribute)
attributesMap.get("objectName"),
+ this,
+ "objectName",
+ String.class,
+ new MethodInvoker() {
+ public Object invoke(Object target, Object[]
arguments) throws Exception {
+ return getObjectName();
+ }
+ }));
+
+ attributesMap.put("classLoader",
+ new GBeanMBeanAttribute((GBeanMBeanAttribute)
attributesMap.get("classLoader"),
+ this,
+ "classLoader",
+ ClassLoader.class,
+ null));
+
+ attributesMap.put("gbeanContext",
+ new GBeanMBeanAttribute((GBeanMBeanAttribute)
attributesMap.get("gbeanContext"),
+ this,
+ "gbeanContext",
+ GBeanContext.class,
+ null));
+
+ attributesMap.put("kernel",
+ new GBeanMBeanAttribute((GBeanMBeanAttribute)
attributesMap.get("kernel"),
+ this,
+ "kernel",
+ Kernel.class,
+ null));
+
+ attributesMap.put(RAW_INVOKER,
+ new GBeanMBeanAttribute(this,
+ RAW_INVOKER,
+ RawInvoker.class,
+ new MethodInvoker() {
+ public Object invoke(Object target, Object[]
arguments) throws Exception {
+ return rawInvoker;
+ }
+ },
+ null));
+
+ //
+ // Normal attributes
+ //
+ attributesMap.put("state",
+ new GBeanMBeanAttribute(this,
+ "state",
+ Integer.TYPE,
+ new MethodInvoker() {
+ public Object invoke(Object target, Object[]
arguments) throws Exception {
+ return new Integer(getState());
+ }
+ },
+ null));
+
+ attributesMap.put("startTime",
+ new GBeanMBeanAttribute(this,
+ "startTime",
+ Long.TYPE,
+ new MethodInvoker() {
+ public Object invoke(Object target, Object[]
arguments) throws Exception {
+ return new Long(getStartTime());
+ }
+ },
+ null));
+
+ attributesMap.put("stateManageable",
+ new GBeanMBeanAttribute(this,
+ "stateManageable",
+ Boolean.TYPE,
+ new MethodInvoker() {
+ public Object invoke(Object target, Object[]
arguments) throws Exception {
+ return new Boolean(isStateManageable());
+ }
+ },
+ null));
+
+ attributesMap.put("statisticsProvider",
+ new GBeanMBeanAttribute(this,
+ "statisticsProvider",
+ Boolean.TYPE,
+ new MethodInvoker() {
+ public Object invoke(Object target, Object[]
arguments) throws Exception {
+ return new Boolean(isStatisticsProvider());
+ }
+ },
+ null));
+
+
+ attributesMap.put("eventProvider",
+ new GBeanMBeanAttribute(this,
+ "eventProvider",
+ Boolean.TYPE,
+ new MethodInvoker() {
+ public Object invoke(Object target, Object[]
arguments) throws Exception {
+ return new Boolean(isEventProvider());
+ }
+ },
+ null));
}
private void addManagedObjectOperations(Set operationsSet) {
1.15 +65 -7
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanAttribute.java
Index: GBeanMBeanAttribute.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanAttribute.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- GBeanMBeanAttribute.java 3 Jun 2004 15:27:28 -0000 1.14
+++ GBeanMBeanAttribute.java 4 Jun 2004 22:31:56 -0000 1.15
@@ -58,13 +58,69 @@
private Object persistentValue;
- public GBeanMBeanAttribute(GBeanMBean gmbean, String name, Class type,
MethodInvoker getInvoker, MethodInvoker setInvoker) {
+ /**
+ * Is this a special attribute like objectName, classLoader or
gbeanContext?
+ * Special attributes are injected at startup just like persistent
attrubutes, but are
+ * otherwise unmodifiable.
+ */
+ private final boolean special;
+
+ GBeanMBeanAttribute(GBeanMBeanAttribute attribute, GBeanMBean gmbean,
String name, Class type, MethodInvoker getInvoker) {
+ if (gmbean == null || name == null || type == null) {
+ throw new IllegalArgumentException("null param(s) supplied");
+ }
+
+ // if we have an attribute verify the gmbean, namd and types match
+ if (attribute != null) {
+ assert (gmbean == attribute.gmbean);
+ assert (name.equals(attribute.name));
+ if (type != attribute.type) {
+ throw new InvalidConfigurationException("Special attribute "
+ name +
+ " must have the type " + type.getName() + ", but is
" +
+ attribute.type.getName() + ": targetClass=" +
gmbean.getType().getName());
+ }
+ if (attribute.isPersistent()) {
+ throw new InvalidConfigurationException("Special attributes
must not be persistent:" +
+ " name=" + name + ", targetClass=" +
gmbean.getType().getName());
+ }
+ }
+
+ this.gmbean = gmbean;
+ this.name = name;
+ this.type = type;
+ if (getInvoker != null) {
+ this.getInvoker = getInvoker;
+ } else if (attribute != null) {
+ this.getInvoker = attribute.getInvoker;
+ } else {
+ this.getInvoker = null;
+ }
+ this.readable = (this.getInvoker != null);
+ this.writable = false;
+ if (attribute != null) {
+ this.setInvoker = attribute.setInvoker;
+ this.isConstructorArg = attribute.isConstructorArg;
+ } else {
+ this.setInvoker = null;
+ this.isConstructorArg = false;
+ }
+ this.persistent = false;
+ this.special = true;
+ if (this.getInvoker == null) {
+ this.mbeanAttributeInfo = null;
+ } else {
+ this.mbeanAttributeInfo = new MBeanAttributeInfo(name,
type.getName(), null, readable, writable, type == Boolean.TYPE);
+ }
+ }
+
+
+ GBeanMBeanAttribute(GBeanMBean gmbean, String name, Class type,
MethodInvoker getInvoker, MethodInvoker setInvoker) {
if (gmbean == null || name == null || type == null) {
throw new IllegalArgumentException("null param(s) supplied");
}
if (getInvoker == null && setInvoker == null) {
throw new InvalidConfigurationException("An attribute must be
readable, writable, or persistent: +"
- + " name=" + name + " targetClass=" +
gmbean.getType().getName());
+ + " name=" + name + ", targetClass=" +
gmbean.getType().getName());
}
this.gmbean = gmbean;
this.name = name;
@@ -80,6 +136,7 @@
} else {
this.mbeanAttributeInfo = new MBeanAttributeInfo(name,
type.getName(), null, readable, writable, type == Boolean.TYPE);
}
+ special = false;
}
public GBeanMBeanAttribute(GBeanMBean gmbean, GAttributeInfo
attributeInfo) throws InvalidConfigurationException {
@@ -179,6 +236,7 @@
persistentValue = new Double(0);
}
}
+ special = false;
}
public String getName() {
@@ -208,7 +266,7 @@
public void online() throws Exception {
// if this is a persistent attirubte and was not set via a
constructor
// set the value into the gbean
- if (persistent && !isConstructorArg && setInvoker != null) {
+ if ((persistent || special) && !isConstructorArg && setInvoker !=
null) {
try {
assert gmbean.getTarget() != null : "online() invoked,
however the corresponding GBeanMBean is " +
"not fully initialized (perhaps online() has been
called directly instead by a Kernel)";
@@ -238,7 +296,7 @@
public Object getValue() throws ReflectionException {
if (gmbean.isOffline()) {
- if (persistent) {
+ if (persistent || special) {
return persistentValue;
} else {
throw new IllegalStateException("Only persistent attributes
can be accessed while offline");
@@ -262,7 +320,7 @@
public void setValue(Object value) throws ReflectionException {
if (gmbean.isOffline()) {
- if (persistent) {
+ if (persistent || special) {
if (value == null && type.isPrimitive()) {
throw new IllegalArgumentException("Cannot assign null
to a primitive attribute:" +
" name=" + name +
@@ -370,7 +428,7 @@
} else {
// we have an explicit name, so no searching is necessary
try {
- Method method =
gMBean.getType().getMethod(attributeInfo.getSetterName(), new Class[] {type});
+ Method method =
gMBean.getType().getMethod(attributeInfo.getSetterName(), new Class[]{type});
if (method.getReturnType() != Void.TYPE) {
throw new InvalidConfigurationException("Setter method
must return VOID:" +
" name=" + attributeInfo.getName() +
1.5 +5 -5
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanContext.java
Index: GBeanMBeanContext.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanContext.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- GBeanMBeanContext.java 27 May 2004 01:05:59 -0000 1.4
+++ GBeanMBeanContext.java 4 Jun 2004 22:31:56 -0000 1.5
@@ -26,21 +26,21 @@
/**
* @version $Revision$ $Date$
*/
-public class GBeanMBeanContext implements GBeanContext {
+public final class GBeanMBeanContext implements GBeanContext {
/**
* The MBean server in which the Geronimo MBean is registered.
*/
- private MBeanServer server;
+ private final MBeanServer server;
/**
* The GeronimoMBean which owns the target.
*/
- private GBeanMBean gmbean;
+ private final GBeanMBean gmbean;
/**
* The object name of the Geronimo MBean.
*/
- private ObjectName objectName;
+ private final ObjectName objectName;
/**
* Creates a new context for a target.
1.4 +6 -1
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/RawInvoker.java
Index: RawInvoker.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/RawInvoker.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- RawInvoker.java 2 Jun 2004 20:51:51 -0000 1.3
+++ RawInvoker.java 4 Jun 2004 22:31:56 -0000 1.4
@@ -22,6 +22,11 @@
import javax.management.ReflectionException;
/**
+ * The raw invoker provides a raw (fast) access invoke operations, get
attribute values, and set
+ * attribute values on a GBean. This class should only be use by GBean
proxy generators or carefully
+ * crafted container code, because this class maintains a hard reference to
a gbean which has a huge
+ * potential for memory leaks. USE WITH CAUTION
+ *
* @version $Revision$ $Date$
*/
public final class RawInvoker {
1.5 +5 -5
incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/gbean/jmx/GBeanMBeanAttributeTest.java
Index: GBeanMBeanAttributeTest.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/gbean/jmx/GBeanMBeanAttributeTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- GBeanMBeanAttributeTest.java 2 Jun 2004 05:33:03 -0000 1.4
+++ GBeanMBeanAttributeTest.java 4 Jun 2004 22:31:56 -0000 1.5
@@ -37,6 +37,7 @@
private static final String persistentPrimitiveAttributeName =
"MutableInt";
private static ObjectName name;
+
static {
try {
name = new ObjectName("test:name=MyMockGBean");
@@ -59,11 +60,11 @@
private MethodInvoker setInvoker = null;
private GAttributeInfo persistentPrimitiveAttributeInfo = null,
attributeInfo = null,
- throwingExceptionAttributeInfo = null;
+ throwingExceptionAttributeInfo = null;
public final void
testGBeanMBeanAttributeGBeanMBeanStringClassMethodInvokerMethodInvoker() {
try {
- new GBeanMBeanAttribute(null, null, null, null, null);
+ new GBeanMBeanAttribute((GBeanMBean) null, null, null, null,
null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
}
@@ -396,8 +397,7 @@
}
{
- final DynamicGAttributeInfo dynamicAttributeInfo = new
DynamicGAttributeInfo(
- MockDynamicGBean.MUTABLE_INT_ATTRIBUTE_NAME, true, true,
true);
+ final DynamicGAttributeInfo dynamicAttributeInfo = new
DynamicGAttributeInfo(MockDynamicGBean.MUTABLE_INT_ATTRIBUTE_NAME, true, true,
true);
GBeanMBeanAttribute attribute = new
GBeanMBeanAttribute(dynamicGmbean, dynamicAttributeInfo);
final ObjectName name = new
ObjectName("test:name=MyMockDynamicGBean");
1.9 +25 -5
incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java
Index: GBeanTest.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- GBeanTest.java 2 Jun 2004 05:33:03 -0000 1.8
+++ GBeanTest.java 4 Jun 2004 22:31:56 -0000 1.9
@@ -17,16 +17,17 @@
package org.apache.geronimo.kernel;
+import java.net.URL;
+import java.net.URLClassLoader;
import java.util.Collections;
import javax.management.ObjectName;
import junit.framework.TestCase;
+import org.apache.geronimo.gbean.GBeanContext;
import org.apache.geronimo.gbean.jmx.GBeanMBean;
import org.apache.geronimo.kernel.management.State;
/**
- *
- *
* @version $Revision$ $Date$
*/
public class GBeanTest extends TestCase {
@@ -35,13 +36,32 @@
private Kernel kernel;
public void testLoad() throws Exception {
- GBeanMBean gbean = new GBeanMBean(MockGBean.getGBeanInfo());
+ ClassLoader cl = getClass().getClassLoader();
+ ClassLoader myCl = new URLClassLoader(new URL[0], cl);
+ GBeanMBean gbean = new GBeanMBean(MockGBean.getGBeanInfo(), myCl);
gbean.setAttribute("Name", "Test");
gbean.setAttribute("FinalInt", new Integer(123));
kernel.loadGBean(name, gbean);
kernel.startGBean(name);
assertEquals(new Integer(State.RUNNING_INDEX),
kernel.getMBeanServer().getAttribute(name, "state"));
- assertEquals("Hello", kernel.getMBeanServer().invoke(name,
"doSomething", new Object[]{"Hello"}, new String[] {String.class.getName()}));
+ assertEquals("Hello", kernel.getMBeanServer().invoke(name,
"doSomething", new Object[]{"Hello"}, new String[]{String.class.getName()}));
+
+ assertEquals(name.getCanonicalName(), kernel.getAttribute(name,
"objectName"));
+ assertEquals(name.getCanonicalName(), kernel.getAttribute(name,
"actualObjectName"));
+
+ assertSame(myCl, kernel.getAttribute(name, "actualClassLoader"));
+
+ // the normal classLoader attribute has been changed in the
MockGBean implementation to
+ // return ClassLoader.getSystemClassLoader()
+ assertSame(ClassLoader.getSystemClassLoader(),
kernel.getAttribute(name, "classLoader"));
+
+ GBeanContext gbeanContext = (GBeanContext) kernel.getAttribute(name,
"gbeanContext");
+ assertNotNull(gbeanContext);
+ assertEquals(State.RUNNING_INDEX, gbeanContext.getState());
+
+ assertNotSame(kernel, kernel.getAttribute(name, "kernel"));
+ assertSame(kernel, kernel.getAttribute(name, "actualKernel"));
+
kernel.stopGBean(name);
kernel.unloadGBean(name);
}
1.7 +5 -5
incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/MockEndpoint.java
Index: MockEndpoint.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/MockEndpoint.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- MockEndpoint.java 2 Jun 2004 20:10:08 -0000 1.6
+++ MockEndpoint.java 4 Jun 2004 22:31:56 -0000 1.7
@@ -17,12 +17,11 @@
package org.apache.geronimo.kernel;
+import org.apache.geronimo.gbean.GBeanContext;
+
/**
- *
- *
* @version $Revision$ $Date$
- *
- * */
+ */
public interface MockEndpoint {
String endpointDoSomething(String name);
@@ -37,4 +36,5 @@
String echo(String message);
+ GBeanContext getGBeanContext();
}
1.19 +64 -15
incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/MockGBean.java
Index: MockGBean.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/MockGBean.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- MockGBean.java 3 Jun 2004 23:12:54 -0000 1.18
+++ MockGBean.java 4 Jun 2004 22:31:56 -0000 1.19
@@ -22,6 +22,7 @@
import java.util.Collections;
import java.util.Iterator;
+import org.apache.geronimo.gbean.GBeanContext;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoFactory;
@@ -32,6 +33,12 @@
private static final GBeanInfo GBEAN_INFO;
+ private String objectName;
+
+ private ClassLoader classLoader;
+
+ private Kernel kernel;
+
private final String name;
private final int finalInt;
@@ -45,6 +52,7 @@
private MockEndpoint endpoint;
private Collection endpointCollection = Collections.EMPTY_SET;
+ private GBeanContext gbeanContext;
public static GBeanInfo getGBeanInfo() {
return GBEAN_INFO;
@@ -53,23 +61,30 @@
static {
GBeanInfoFactory infoFactory = new GBeanInfoFactory("MockGBean",
MockGBean.class);
infoFactory.addAttribute("Name", String.class, true);
+ infoFactory.addAttribute("actualObjectName", String.class, false);
+ infoFactory.addAttribute("objectName", String.class, false);
+ infoFactory.addAttribute("gbeanContext", GBeanContext.class, false);
+ infoFactory.addAttribute("actualClassLoader", ClassLoader.class,
false);
+ infoFactory.addAttribute("classLoader", ClassLoader.class, false);
+ infoFactory.addAttribute("actualKernel", Kernel.class, false);
+ infoFactory.addAttribute("kernel", Kernel.class, false);
infoFactory.addAttribute("Value", String.class, true);
infoFactory.addAttribute("FinalInt", Integer.TYPE, true);
infoFactory.addAttribute("MutableInt", Integer.TYPE, false);
infoFactory.addAttribute("ExceptionMutableInt", Integer.TYPE, true);
infoFactory.addAttribute("EndpointMutableInt", Integer.TYPE, false);
- infoFactory.addOperation("echo", new Class[] {String.class});
+ infoFactory.addOperation("echo", new Class[]{String.class});
infoFactory.addOperation("checkEndpoint");
infoFactory.addOperation("checkEndpointCollection");
- infoFactory.addOperation("doSomething", new Class[] { String.class});
+ infoFactory.addOperation("doSomething", new Class[]{String.class});
- infoFactory.addInterface(MockEndpoint.class, new String[] {
"MutableInt"});
+ infoFactory.addInterface(MockEndpoint.class, new
String[]{"MutableInt"});
infoFactory.addReference("MockEndpoint", MockEndpoint.class);
infoFactory.addReference("EndpointCollection", MockEndpoint.class);
- infoFactory.setConstructor(new String[] { "Name", "FinalInt"});
+ infoFactory.setConstructor(new String[]{"Name", "FinalInt",
"objectName", "classLoader", "gbeanContext", "kernel"});
GBEAN_INFO = infoFactory.getBeanInfo();
}
@@ -79,6 +94,47 @@
this.finalInt = finalInt;
}
+ public MockGBean(String name, int finalInt, String objectName,
ClassLoader classLoader, GBeanContext gbeanContext, Kernel kernel) {
+ this.name = name;
+ this.finalInt = finalInt;
+ this.objectName = objectName;
+ this.classLoader = classLoader;
+ this.gbeanContext = gbeanContext;
+ this.kernel = kernel;
+ }
+
+ public String getActualObjectName() {
+ return objectName;
+ }
+
+ public String getObjectName() {
+ return "FakePhonyName";
+ }
+
+ public ClassLoader getActualClassLoader() {
+ return classLoader;
+ }
+
+ public ClassLoader getClassLoader() {
+ return ClassLoader.getSystemClassLoader();
+ }
+
+ public GBeanContext getGBeanContext() {
+ return gbeanContext;
+ }
+
+ public Kernel getActualKernel() {
+ return kernel;
+ }
+
+ public Kernel getKernel() {
+ return new Kernel("blah424242");
+ }
+
+ public void setKernel(Kernel kernel) {
+ this.kernel = kernel;
+ }
+
public String getName() {
return name;
}
@@ -96,8 +152,6 @@
/**
* Note the wrong return type, instead of int type.
- *
- * @return
*/
public String getAnotherFinalInt() {
return null;
@@ -105,16 +159,12 @@
/**
* Parameter ignored
- *
- * @param ignored
*/
public void setAnotherFinalInt(int ignored) {
}
/**
* Only setter for YetAnotherFinalInt
- *
- * @param ignored
*/
public void setYetAnotherFinalInt(int ignored) {
}
@@ -151,26 +201,25 @@
* @see #setYetAnotherFinalInt(int)
*/
public void setLongAsYetAnotherFinalInt(long yetAnotherFinalInt) {
- setYetAnotherFinalInt((int)yetAnotherFinalInt);
+ setYetAnotherFinalInt((int) yetAnotherFinalInt);
}
/**
* @see #setYetAnotherFinalInt(int)
*/
public void setFloatAsYetAnotherFinalInt(float yetAnotherFinalInt) {
- setYetAnotherFinalInt((int)yetAnotherFinalInt);
+ setYetAnotherFinalInt((int) yetAnotherFinalInt);
}
/**
* @see #setYetAnotherFinalInt(int)
*/
public void setDoubleAsYetAnotherFinalInt(double yetAnotherFinalInt) {
- setYetAnotherFinalInt((int)yetAnotherFinalInt);
+ setYetAnotherFinalInt((int) yetAnotherFinalInt);
}
/**
* Getter that returns nothing
- *
*/
public void getVoidGetterOfFinalInt() {
}
1.14 +17 -7
incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/jmx/MBeanServerStub.java
Index: MBeanServerStub.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/jmx/MBeanServerStub.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- MBeanServerStub.java 2 Jun 2004 05:33:04 -0000 1.13
+++ MBeanServerStub.java 4 Jun 2004 22:31:56 -0000 1.14
@@ -17,12 +17,15 @@
package org.apache.geronimo.remoting.jmx;
+import javax.management.ObjectName;
+
import org.apache.geronimo.core.service.Interceptor;
import org.apache.geronimo.gbean.GBean;
import org.apache.geronimo.gbean.GBeanContext;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoFactory;
-import org.apache.geronimo.gbean.jmx.GBeanMBeanContext;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.jmx.JMXUtil;
import org.apache.geronimo.proxy.ProxyContainer;
import org.apache.geronimo.proxy.ReflexiveInterceptor;
import org.apache.geronimo.remoting.DeMarshalingInterceptor;
@@ -34,11 +37,16 @@
* @version $Revision$ $Date$
*/
public class MBeanServerStub implements GBean, JMXTarget {
+ private final Kernel kernel;
+ private final ObjectName objectName;
private ProxyContainer serverContainer;
private DeMarshalingInterceptor demarshaller;
- private GBeanMBeanContext context;
private JMXRouter router;
+ public MBeanServerStub(Kernel kernel, String objectName) {
+ this.kernel = kernel;
+ this.objectName = JMXUtil.getObjectName(objectName);
+ }
public Interceptor getRemotingEndpointInterceptor() {
return demarshaller;
@@ -53,20 +61,19 @@
}
public void setGBeanContext(GBeanContext context) {
- this.context = (GBeanMBeanContext) context;
}
public void doStart() {
- router.register(context.getObjectName(), this);
+ router.register(objectName, this);
// Setup the server side contianer..
- Interceptor firstInterceptor = new
ReflexiveInterceptor(context.getServer());
+ Interceptor firstInterceptor = new
ReflexiveInterceptor(kernel.getMBeanServer());
demarshaller = new DeMarshalingInterceptor(firstInterceptor,
getClass().getClassLoader());
serverContainer = new ProxyContainer(firstInterceptor);
}
public void doStop() {
- router.unRegister(context.getObjectName());
+ router.unregister(objectName);
serverContainer = null;
demarshaller = null;
}
@@ -80,8 +87,11 @@
static {
GBeanInfoFactory infoFactory = new
GBeanInfoFactory(MBeanServerStub.class);
+ infoFactory.addAttribute("kernel", Kernel.class, false);
+ infoFactory.addAttribute("objectName", String.class, false);
infoFactory.addOperation("getRemotingEndpointInterceptor");
infoFactory.addReference("Router", JMXRouter.class);
+ infoFactory.setConstructor(new String[]{"kernel", "objectName"});
GBEAN_INFO = infoFactory.getBeanInfo();
}
1.12 +3 -3
incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/router/JMXRouter.java
Index: JMXRouter.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/remoting/src/java/org/apache/geronimo/remoting/router/JMXRouter.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- JMXRouter.java 2 Jun 2004 05:33:04 -0000 1.11
+++ JMXRouter.java 4 Jun 2004 22:31:56 -0000 1.12
@@ -53,7 +53,7 @@
registered.put(objectName, target);
}
- public void unRegister(ObjectName objectName) {
+ public void unregister(ObjectName objectName) {
registered.remove(objectName);
}
@@ -82,7 +82,7 @@
GBeanInfoFactory infoFactory = new GBeanInfoFactory(JMXRouter.class,
AbstractInterceptorRouter.GBEAN_INFO);
infoFactory.addReference("SubsystemRouter", SubsystemRouter.class);
infoFactory.addOperation("register", new Class[]{ObjectName.class,
JMXTarget.class});
- infoFactory.addOperation("unRegister", new
Class[]{ObjectName.class});
+ infoFactory.addOperation("unregister", new
Class[]{ObjectName.class});
GBEAN_INFO = infoFactory.getBeanInfo();
}
1.8 +9 -8
incubator-geronimo/modules/security/src/java/org/apache/geronimo/security/jaas/ConfigurationEntry.java
Index: ConfigurationEntry.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/security/src/java/org/apache/geronimo/security/jaas/ConfigurationEntry.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ConfigurationEntry.java 2 Jun 2004 05:33:04 -0000 1.7
+++ ConfigurationEntry.java 4 Jun 2004 22:31:56 -0000 1.8
@@ -18,7 +18,6 @@
package org.apache.geronimo.security.jaas;
import java.util.Properties;
-import javax.management.MBeanServer;
import javax.security.auth.login.AppConfigurationEntry;
import org.apache.geronimo.gbean.GBean;
@@ -27,6 +26,7 @@
import org.apache.geronimo.gbean.GBeanInfoFactory;
import org.apache.geronimo.gbean.WaitingException;
import org.apache.geronimo.gbean.jmx.GBeanMBeanContext;
+import org.apache.geronimo.kernel.Kernel;
/**
@@ -45,11 +45,16 @@
* @see javax.security.auth.login.Configuration
*/
public abstract class ConfigurationEntry implements GBean {
+ protected final Kernel kernel;
protected GBeanMBeanContext context;
protected String applicationConfigName;
protected LoginModuleControlFlag controlFlag;
protected Properties options = new Properties();
+ protected ConfigurationEntry(Kernel kernel) {
+ this.kernel = kernel;
+ }
+
/**
* Get the JAAS config id for this configuration entry.
*
@@ -85,11 +90,6 @@
}
public void setGBeanContext(GBeanContext context) {
- this.context = (GBeanMBeanContext) context;
- }
-
- public MBeanServer getMBeanServer() {
- return context.getServer();
}
public abstract AppConfigurationEntry[] getAppConfigurationEntry();
@@ -109,10 +109,11 @@
static {
GBeanInfoFactory infoFactory = new
GBeanInfoFactory(ConfigurationEntry.class);
+ infoFactory.addAttribute("kernel", Kernel.class, false);
infoFactory.addAttribute("ApplicationConfigName", String.class,
true);
infoFactory.addAttribute("ControlFlag",
LoginModuleControlFlag.class, true);
infoFactory.addAttribute("Options", Properties.class, true);
-
+ infoFactory.setConstructor(new String[]{"kernel"});
GBEAN_INFO = infoFactory.getBeanInfo();
}
1.5 +6 -1
incubator-geronimo/modules/security/src/java/org/apache/geronimo/security/jaas/ConfigurationEntryLocal.java
Index: ConfigurationEntryLocal.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/security/src/java/org/apache/geronimo/security/jaas/ConfigurationEntryLocal.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ConfigurationEntryLocal.java 2 Jun 2004 05:33:04 -0000 1.4
+++ ConfigurationEntryLocal.java 4 Jun 2004 22:31:56 -0000 1.5
@@ -21,6 +21,7 @@
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoFactory;
+import org.apache.geronimo.kernel.Kernel;
/**
@@ -40,6 +41,10 @@
*/
public class ConfigurationEntryLocal extends ConfigurationEntry {
private String loginModuleName;
+
+ public ConfigurationEntryLocal(Kernel kernel) {
+ super(kernel);
+ }
public String getLoginModuleName() {
return loginModuleName;
1.5 +6 -11
incubator-geronimo/modules/security/src/java/org/apache/geronimo/security/jaas/ConfigurationEntryRealmLocal.java
Index: ConfigurationEntryRealmLocal.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/security/src/java/org/apache/geronimo/security/jaas/ConfigurationEntryRealmLocal.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ConfigurationEntryRealmLocal.java 2 Jun 2004 05:33:04 -0000 1.4
+++ ConfigurationEntryRealmLocal.java 4 Jun 2004 22:31:56 -0000 1.5
@@ -43,12 +43,8 @@
public class ConfigurationEntryRealmLocal extends ConfigurationEntry {
private String realmName;
- public String getKernelName() {
- try {
- return (String) context.getServer().getAttribute(Kernel.KERNEL,
"KernelName");
- } catch (Exception e) {
- return null;
- }
+ public ConfigurationEntryRealmLocal(Kernel kernel) {
+ super(kernel);
}
public String getRealmName() {
@@ -63,8 +59,8 @@
try {
return new AppConfigurationEntry[]{
new
AppConfigurationEntry("org.apache.geronimo.security.jaas.LocalLoginModule",
- getControlFlag().getFlag(),
- getOptions())};
+ getControlFlag().getFlag(),
+ getOptions())};
} catch (Exception e) {
}
return null;
@@ -74,7 +70,7 @@
super.doStart();
options.put("realm", realmName);
- options.put("kernel", getKernelName());
+ options.put("kernel", kernel.getKernelName());
}
public void doStop() throws WaitingException, Exception {
@@ -86,7 +82,6 @@
static {
GBeanInfoFactory infoFactory = new
GBeanInfoFactory(ConfigurationEntryRealmLocal.class,
ConfigurationEntry.GBEAN_INFO);
infoFactory.addAttribute("RealmName", String.class, true);
- infoFactory.addOperation("getKernelName");
GBEAN_INFO = infoFactory.getBeanInfo();
}
1.5 +8 -4
incubator-geronimo/modules/security/src/java/org/apache/geronimo/security/jaas/ConfigurationEntryRealmRemote.java
Index: ConfigurationEntryRealmRemote.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/security/src/java/org/apache/geronimo/security/jaas/ConfigurationEntryRealmRemote.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ConfigurationEntryRealmRemote.java 2 Jun 2004 05:33:04 -0000
1.4
+++ ConfigurationEntryRealmRemote.java 4 Jun 2004 22:31:56 -0000
1.5
@@ -19,10 +19,10 @@
import javax.security.auth.login.AppConfigurationEntry;
-import org.apache.geronimo.gbean.GAttributeInfo;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoFactory;
import org.apache.geronimo.gbean.WaitingException;
+import org.apache.geronimo.kernel.Kernel;
/**
@@ -43,6 +43,10 @@
public class ConfigurationEntryRealmRemote extends
ConfigurationEntryRealmLocal {
private String URI;
+ public ConfigurationEntryRealmRemote(Kernel kernel) {
+ super(kernel);
+ }
+
public String getURI() {
return URI;
}
@@ -55,8 +59,8 @@
try {
return new AppConfigurationEntry[]{
new
AppConfigurationEntry("org.apache.geronimo.security.jaas.LocalLoginModule",
- getControlFlag().getFlag(),
- getOptions())};
+ getControlFlag().getFlag(),
+ getOptions())};
} catch (Exception e) {
}
return null;
1.4 +17 -8
incubator-geronimo/modules/security/src/java/org/apache/geronimo/security/remoting/jmx/LoginServiceStub.java
Index: LoginServiceStub.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/security/src/java/org/apache/geronimo/security/remoting/jmx/LoginServiceStub.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- LoginServiceStub.java 2 Jun 2004 05:33:04 -0000 1.3
+++ LoginServiceStub.java 4 Jun 2004 22:31:56 -0000 1.4
@@ -17,12 +17,14 @@
package org.apache.geronimo.security.remoting.jmx;
+import javax.management.ObjectName;
+
import org.apache.geronimo.core.service.Interceptor;
import org.apache.geronimo.gbean.GBean;
import org.apache.geronimo.gbean.GBeanContext;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoFactory;
-import org.apache.geronimo.gbean.jmx.GBeanMBeanContext;
+import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.jmx.JMXUtil;
import org.apache.geronimo.kernel.jmx.MBeanProxyFactory;
import org.apache.geronimo.proxy.ProxyContainer;
@@ -37,11 +39,16 @@
* @version $Revision$ $Date$
*/
public class LoginServiceStub implements GBean, JMXTarget {
+ private final Kernel kernel;
+ private final ObjectName objectName;
private ProxyContainer serverContainer;
private DeMarshalingInterceptor demarshaller;
- private GBeanMBeanContext context;
private JMXRouter router;
+ public LoginServiceStub(Kernel kernel, String objectName) {
+ this.kernel = kernel;
+ this.objectName = JMXUtil.getObjectName(objectName);
+ }
public Interceptor getRemotingEndpointInterceptor() {
return demarshaller;
@@ -56,23 +63,22 @@
}
public void setGBeanContext(GBeanContext context) {
- this.context = (GBeanMBeanContext) context;
}
public void doStart() throws Exception {
- router.register(context.getObjectName(), this);
+ router.register(objectName, this);
// Setup the server side contianer..
LoginServiceMBean loginService = (LoginServiceMBean)
MBeanProxyFactory.getProxy(LoginServiceMBean.class,
-
context.getServer(),
-
JMXUtil.getObjectName("geronimo.security:type=LoginService"));
+ kernel.getMBeanServer(),
+
JMXUtil.getObjectName("geronimo.security:type=LoginService"));
Interceptor firstInterceptor = new
ReflexiveInterceptor(loginService);
demarshaller = new DeMarshalingInterceptor(firstInterceptor,
getClass().getClassLoader());
serverContainer = new ProxyContainer(firstInterceptor);
}
public void doStop() {
- router.unRegister(context.getObjectName());
+ router.unregister(objectName);
serverContainer = null;
demarshaller = null;
@@ -87,8 +93,11 @@
static {
GBeanInfoFactory infoFactory = new
GBeanInfoFactory(LoginServiceStub.class);
+ infoFactory.addAttribute("kernel", Kernel.class, false);
+ infoFactory.addAttribute("objectName", String.class, false);
infoFactory.addReference("Router", JMXRouter.class);
infoFactory.addOperation("getRemotingEndpointInterceptor");
+ infoFactory.setConstructor(new String[]{"kernel", "objectName"});
GBEAN_INFO = infoFactory.getBeanInfo();
}