01: /* JFox, the OpenSource J2EE Application Server
02: *
03: * Copyright (C) 2002 huihoo.org
04: * Distributable under GNU LGPL license
05: * See the GNU Lesser General Public License for more details.
06: */
07:
08: package example.jmx.standard;
09:
10: import javax.management.MBeanServer;
11: import javax.management.MBeanServerFactory;
12: import javax.management.ObjectName;
13: import javax.management.MBeanServerInvocationHandler;
14:
15: /**
16: *
17: * @author <a href="mailto:young_yy@hotmail.org">Young Yang</a>
18: */
19:
20: public class Test implements TestMBean {
21: private String state = "Running";
22:
23: public String getState() {
24: return state;
25: }
26:
27: public void reset() {
28: System.out.println("Reset");
29: }
30:
31: public static void main(String[] args) throws Exception {
32: MBeanServer server = MBeanServerFactory.createMBeanServer();
33: Test test = new Test();
34: ObjectName on = new ObjectName(":class=Test");
35: ObjectName on2 = server.registerMBean(test, on).getObjectName();
36: System.out.println(on2);
37: System.out.println(server.getAttribute(on2, "State"));
38: System.out.println(server.invoke(on2, "getStatus",
39: new Object[] {}, new String[] {}));
40:
41: Object proxy = MBeanServerInvocationHandler.newProxyInstance(
42: server, on, TestMBean.class, false);
43: System.out.println(((TestMBean) proxy).getState());
44:
45: }
46:
47: }
|