01: /*
02: * JMXAgent.java
03: *
04: * Created on May 11, 2005, 9:28 AM
05: */
06:
07: package com.toy.anagrams.agent;
08:
09: import javax.management.ObjectName;
10: import javax.management.MBeanServer;
11: import java.lang.management.ManagementFactory;
12:
13: import com.toy.anagrams.mbeans.AnagramsStats;
14:
15: /**
16: * JMX agent class.
17: * You may use the New JMX MBean wizard to create a Managed Bean.
18: * @author jfdenise
19: */
20: public class JMXAgent {
21: private AnagramsStats mbean;
22:
23: public AnagramsStats getAnagramsStats() {
24: return mbean;
25: }
26:
27: /**
28: * Instantiate and register your MBeans.
29: */
30: public void init() throws Exception {
31:
32: //TODO Add your MBean registration code here
33:
34: // Instantiate Anagrams MBean
35: mbean = new AnagramsStats();
36: ObjectName mbeanName = new ObjectName(
37: "anagrams.toy.com:type=AnagramsStats");
38: //Register the Anagrams MBean
39: getMBeanServer().registerMBean(mbean, mbeanName);
40: }
41:
42: /**
43: * Returns an agent singleton.
44: */
45: public synchronized static JMXAgent getDefault() throws Exception {
46: if (singleton == null) {
47: singleton = new JMXAgent();
48: singleton.init();
49: }
50: return singleton;
51: }
52:
53: public MBeanServer getMBeanServer() {
54: return mbs;
55: }
56:
57: // Platform MBeanServer used to register your MBeans
58: private final MBeanServer mbs = ManagementFactory
59: .getPlatformMBeanServer();
60:
61: // Singleton instance
62: private static JMXAgent singleton;
63: }
|