01: /* JFox, the OpenSource J2EE Application Server
02: *
03: * Copyright (C) 2002 huihoo.com
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.StandardMBean;
11: import javax.management.NotCompliantMBeanException;
12: import javax.management.MBeanServer;
13: import javax.management.MBeanServerFactory;
14: import javax.management.ObjectName;
15:
16: import org.huihoo.jfox.jmx.adaptor.http.HtmlAdaptorServer;
17:
18: /**
19: *
20: * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
21: */
22:
23: public class Test1_2 extends StandardMBean implements TestMBean {
24: public Test1_2(Class mbeanInterface)
25: throws NotCompliantMBeanException {
26: super (mbeanInterface);
27: }
28:
29: private String state = "Running";
30:
31: public String getState() {
32: return state;
33: }
34:
35: public void reset() {
36: System.out.println("Reset");
37: }
38:
39: public static void main(String[] args) throws Exception {
40: MBeanServer server = MBeanServerFactory.createMBeanServer();
41: ObjectName on = new ObjectName(":class=Test1_2");
42: server.createMBean(Test1_2.class.getName(), on,
43: new Object[] { TestMBean.class },
44: new String[] { "java.lang.Class" });
45:
46: ObjectName on2 = new ObjectName(":class=Test12");
47: server.createMBean(StandardMBean.class.getName(), on2,
48: new Object[] { new Test12(), TestMBean.class },
49: new String[] { "java.lang.Object", "java.lang.Class" });
50:
51: System.out.println(server.getAttribute(on, "State"));
52: server.invoke(on, "reset", null, null);
53:
54: System.out.println(server.getAttribute(on2, "State"));
55: server.invoke(on2, "reset", null, null);
56:
57: ObjectName haName = new ObjectName(
58: "Adaptor:type=HtmlAdaptor,port=8082");
59: HtmlAdaptorServer ha = new HtmlAdaptorServer();
60: server.registerMBean(ha, haName);
61: ha.setPort(8082);
62: ha.start();
63:
64: }
65: }
|