| Commit in servicemix/base/src on MAIN | |||
| main/java/org/servicemix/jbi/management/ManagementContext.java | +22 | -18 | 1.17 -> 1.18 |
| test/java/org/servicemix/jbi/management/AdminServiceTest.java | +64 | added 1.1 | |
| +86 | -18 | ||
Fix SM-77 : AdminServiceMBean incorrectly declared MBeanInfo (patch provided by George Gastaldi)
servicemix/base/src/main/java/org/servicemix/jbi/management
diff -u -r1.17 -r1.18 --- ManagementContext.java 23 Aug 2005 09:20:53 -0000 1.17 +++ ManagementContext.java 6 Oct 2005 08:30:11 -0000 1.18 @@ -28,6 +28,7 @@
import javax.jbi.JBIException; import javax.management.Attribute; import javax.management.JMException;
+import javax.management.MBeanAttributeInfo;
import javax.management.MBeanOperationInfo; import javax.management.MBeanServer; import javax.management.MBeanServerFactory;
@@ -46,7 +47,7 @@
/** * A Flow provides different dispatch policies within the NMR *
- * @version $Revision: 1.17 $
+ * @version $Revision: 1.18 $
*/
public class ManagementContext extends BaseLifeCycle implements ManagementContextMBean {
/**
@@ -630,23 +631,26 @@
* @return array of OperationInfos
* @throws JMException
*/
- public MBeanOperationInfo[] getOperationInfos() throws JMException {
- OperationInfoHelper helper = new OperationInfoHelper();
- helper.addOperation(getObjectToManage(), "getBindingComponents", "Get list of all binding components");
- helper.addOperation(getObjectToManage(), "getEngineComponents", "Get list of all engine components");
- ParameterHelper ph = helper.addOperation(getObjectToManage(), "getComponentByName", 1,
- "look up Component by name");
- ph.setDescription(0, "name", "Component name");
- helper.addOperation(getObjectToManage(), "getSystemInfo", "return current version");
- helper.addOperation(getObjectToManage(), "getSystemServices", "Get list of system services");
- ph = helper.addOperation(getObjectToManage(), "getSystemService", 1, "look up System service by name");
- ph.setDescription(0, "name", "System name");
- ph = helper.addOperation(getObjectToManage(), "isBinding", 1, "Is Component a binding Component?");
- ph.setDescription(0, "name", "Component name");
- ph = helper.addOperation(getObjectToManage(), "isEngine", 1, "Is Component a service engine?");
- ph.setDescription(0, "name", "Component name");
- return OperationInfoHelper.join(super.getOperationInfos(), helper.getOperationInfos());
+ public MBeanAttributeInfo[] getAttributeInfos() throws JMException {
+ AttributeInfoHelper helper = new AttributeInfoHelper();
+ helper.addAttribute(getObjectToManage(), "bindingComponents", "Get list of all binding components");
+ helper.addAttribute(getObjectToManage(), "engineComponents", "Get list of all engine components");
+ helper.addAttribute(getObjectToManage(), "systemInfo", "Return current version");
+ helper.addAttribute(getObjectToManage(), "systemServices", "Get list of system services");
+ return AttributeInfoHelper.join(super.getAttributeInfos(), helper.getAttributeInfos());
}
-
+ public MBeanOperationInfo[] getOperationInfos() throws JMException {
+ OperationInfoHelper helper = new OperationInfoHelper();
+ ParameterHelper ph = helper.addOperation(getObjectToManage(), "getComponentByName", 1, "look up Component by name");
+ ph.setDescription(0, "name", "Component name");
+ ph = helper.addOperation(getObjectToManage(), "getSystemService", 1, "look up System service by name");
+ ph.setDescription(0, "name", "System name");
+ ph = helper.addOperation(getObjectToManage(), "isBinding", 1, "Is Component a binding Component?");
+ ph.setDescription(0, "name", "Component name");
+ ph = helper.addOperation(getObjectToManage(), "isEngine", 1, "Is Component a service engine?");
+ ph.setDescription(0, "name", "Component name");
+ return OperationInfoHelper.join(super.getOperationInfos(), helper.getOperationInfos());
+ }
+
}
servicemix/base/src/test/java/org/servicemix/jbi/management
AdminServiceTest.java added at 1.1
diff -N AdminServiceTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ AdminServiceTest.java 6 Oct 2005 08:30:13 -0000 1.1 @@ -0,0 +1,64 @@
+/*
+ * Created on Jun 15, 2005
+ *
+ * To change the template for this generated file go to
+ * Window - Preferences - Java - Code Generation - Code and Comments
+ */
+
+package org.servicemix.jbi.management;
+import javax.jbi.management.AdminServiceMBean;
+import javax.jbi.management.LifeCycleMBean;
+import javax.management.MBeanServerConnection;
+import javax.management.MBeanServerDelegateMBean;
+import javax.management.MBeanServerInvocationHandler;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+import junit.framework.TestCase;
+import org.servicemix.jbi.container.JBIContainer;
+import org.servicemix.jbi.nmr.Broker;
+
+/**
+ * ManagementContextTest
+ */
+public class AdminServiceTest extends TestCase {
+ JBIContainer container;
+
+ protected void setUp() throws Exception {
+ container = new JBIContainer();
+ container.setCreateMBeanServer(true);
+ container.init();
+ }
+
+ protected void tearDown() throws Exception {
+ container.shutDown();
+ }
+
+ public void testAdminService() throws Exception {
+ // The host, port and path where the rmiregistry runs.
+ String namingHost = "localhost";
+ int namingPort = 1099;
+ String jndiPath = "/" + JBIContainer.DEFAULT_NAME + "JMX";
+ // The address of the connector server
+ JMXServiceURL url = "" JMXServiceURL("service:jmx:rmi:///jndi/rmi://"
+ + namingHost + ":" + namingPort + jndiPath);
+ // Connect a JSR 160 JMXConnector to the server side
+ JMXConnector connector = JMXConnectorFactory.connect(url);
+ // Retrieve an MBeanServerConnection that represent the MBeanServer the remote
+ // connector server is bound to
+ MBeanServerConnection connection = connector.getMBeanServerConnection();
+ // Call the server side as if it is a local MBeanServer
+ ObjectName asmName = getObjectName(ManagementContext.class);
+ Object proxy = MBeanServerInvocationHandler.newProxyInstance(connection, asmName,
+ AdminServiceMBean.class, true);
+ AdminServiceMBean asm = (AdminServiceMBean) proxy;
+
+ System.out.println(asm.getBindingComponents());
+ System.out.println(asm.getComponentByName("toto"));
+ }
+
+ protected ObjectName getObjectName (Class systemClass){
+ return ManagementContext.getSystemObjectName(ManagementContext.DEFAULT_DOMAIN, JBIContainer.DEFAULT_NAME, systemClass);
+ }
+}
