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.mlet;
09:
10: import java.util.Set;
11: import java.util.Iterator;
12: import java.io.File;
13:
14: import javax.management.MBeanServerFactory;
15: import javax.management.MBeanServer;
16: import javax.management.ObjectInstance;
17: import javax.management.ObjectName;
18: import javax.management.loading.MLet;
19:
20: /**
21: *
22: * @author <a href="mailto:young_yy@hotmail.org">Young Yang</a>
23: */
24:
25: public class SimpleMLetAgent {
26:
27: public static void main(String[] args) throws Exception {
28: System.out.println("CREATE the MBeanServer.\n");
29: MBeanServer server = MBeanServerFactory.createMBeanServer();
30:
31: MLet mlet = new MLet();
32:
33: ObjectInstance oi = server.registerMBean(mlet, new ObjectName(
34: ":Service=MLet"));
35: ObjectName on = oi.getObjectName();
36: System.out.println(on.toString());
37: File conf = new File("./conf/mlet.conf");
38: Set set = mlet.getMBeansFromURL(conf.getAbsoluteFile().toURL()
39: .toString());
40: Iterator it = set.iterator();
41: ObjectName mletName = null;
42: while (it.hasNext()) {
43: mletName = ((ObjectInstance) it.next()).getObjectName();
44: System.out.println(mletName.toString());
45: }
46: System.out.println(server.getAttribute(mletName, "State"));
47:
48: }
49: }
|