JMX-rmi之CS结构总结
已有对应的接口类文件时使用代理方式调用
AppInterfaceMBean proxy = (AppInterfaceMBean) MBeanServerInvocationHandler.newProxyInstance(mbsc, mbeanName, AppInterfaceMBean.class, false);
proxy.doAction();
proxy.doActionWithStringParam("string");
//不存在对应的接口类文件,只知道对应的方法名和签名
name - MBean 的对象名,要在该 MBean 上调用方法。
operationName - 要调用的操作名。
params - 一个数组,包含调用操作时要设置的参数
signature - 包含操作签名的数组。用于加载类对象的类加载器与用于加载 MBean(要在其上调用操作)的类加载器相同。
mbsc.invoke(mbeanName, "doAction", null, null);
mbsc.invoke(mbeanName, "doActionWithStringParam", new Object[] { "string" }, new String[] { String.class.getName() });
RMI-Client
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9999/server");
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
RMI-Server
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9999/server");
MBeanServer server = MBeanServerFactory.createMBeanServer();
JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, server);
cs.start();