标题: JMX Works as RPC Protocol [打印本页] 作者: key 时间: 19-10-2009 14:34 标题: JMX Works as RPC Protocol JMX is not an RPC protocol, at least, it was not designed for
PRC purpose. However, JMX could work exactly like a RPC protocol,
such as RMI does. I would like to introduce how here.
Please refer to the JMX Tutorial. You can find a simple JMX
program using Standard MBean technology there. Please look at
the classes/interfaces:
HelloMBean
Hello
HelloMain
Note that JMX remote management feature are totally runtime configurable.
That's so attractive.作者: key 时间: 19-10-2009 14:55 标题: 3. A Simple Client I'm going to run the MBean directly using RPC methods, just like what
I did with RMI's clients. So I using MBean Proxies here.
JMXServiceURL url = new ....
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
ObjectName mbeanName = new ObjectName("com.example:type=Hello");
HelloMBean mbeanProxy = JMX.newMBeanProxy(mbsc, mbeanName, HelloMBean.class, true);
mbeanProxy.sayHello();
jmxc.close();作者: key 时间: 19-10-2009 15:01 标题: 4. Sending Custom Data Object Back & Forth public class X implements Serializable {
}
public class X2 extends X {
private String a;
private int b;
public X2(String a, int b) { this.a = a; this.b = b; }
public String toString() { return "a = " + a + ", b = " + b; }
}
public class HelloMBean {
....
public X2 doWithX(X x) { System.out.println("X = " + x); return new X2("Hello", (int)(Math.random() * 100)); }
}
....
Test the above code, you will fine there is no difference between JMX and RMI with respect of
transferring Data Objects.作者: black_zerg 时间: 19-10-2009 15:19
提示: 作者被禁止或删除, 无法发言
这个是用来管理java软件的那个吧。好像tomcat可以用这个控制来着。可以开发一系列产品然后用一个软件console管理这些进程。
唉,现在总觉得对工作来说,似乎没太大意义搞这些比较精巧但是费时间的东西,特别小组里别人都没什么兴趣。
[ 本帖最后由 black_zerg 于 19-10-2009 15:21 编辑 ]作者: key 时间: 19-10-2009 15:53 标题: 5. MXBeans The example using MBean in 4 requires the complex Data Object
implements Serializable. Additionally, you can not use jConsole to
retrieve the value. You can avoid this disadvantage by applying MXBean.
MemoryPoolMXBean proxy =
JMX.newMXBeanProxy(
mbeanServer,
objectName,
MemoryPoolMXBean.class);
String name = proxy.getName();
MemoryUsage usage = proxy.getUsage();
long used = usage.getUsed();
It's nearly the same as what you might do with Standard MBean.
However, you can use jConsole to management the value now.作者: key 时间: 19-10-2009 16:13 标题: 6. MXBean -> MXBean You can retrieve an MXBean via another MXBean, then invoke
the method of the later one. However, make sure you register
the returned MXBean, or you'll get an error of:
java.lang.reflect.UndeclaredThrowableException
Caused by: javax.management.openmbean.OpenDataException: No name for object: .....
Return the MXBean is one of the most important features
regarding RPC's.
public interface RetMXBean {
public void dx();
}
public class Ret implements RetMXBean{
private static Ret instance = new Ret();
public static RetMXBean instance() {
return instance;
}
public void dx() {
System.out.println("Hello RetMXBean");
}
}
public class HelloMain {
public static void main(String [] args) throws Exception{
....
mbs.registerMBean(Ret.instance(), new ObjectName("com.example.mbeans:type=RetMXBean"));
....
}
}