KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mx > remoting > JMXUtil


1 package org.jboss.mx.remoting;
2
3 import java.util.ArrayList JavaDoc;
4 import javax.management.MBeanServer JavaDoc;
5 import javax.management.MBeanServerFactory JavaDoc;
6 import javax.management.ObjectName JavaDoc;
7
8 /**
9  * JMXUtil is a set of utility functions for dealing with JMX servers and
10  * MBeans
11  *
12  * @author <a HREF="jhaynie@vocalocity.net">Jeff Haynie</a>
13  * @version $Revision: 30251 $
14  */

15 public class JMXUtil
16 {
17    private static ObjectName JavaDoc mbeanserver;
18
19    /**
20     * return the local MbeanServer by using the system property <tt>jboss.remoting.jmxid</tt>
21     * which is set by the NetworkRegistry MBean when registered in the mbean server
22     *
23     * @return
24     */

25    public static MBeanServer JavaDoc getMBeanServer()
26    {
27       ArrayList JavaDoc list = MBeanServerFactory.findMBeanServer(System.getProperty("jboss.remoting.jmxid"));
28       if(list.isEmpty())
29       {
30          return null;
31       }
32       return (MBeanServer JavaDoc) list.iterator().next();
33    }
34
35    /**
36     * get the ObjectName of the MBeanServer
37     *
38     * @return object name of the mbean server delegate
39     * @throws Exception
40     */

41    public static final ObjectName JavaDoc getMBeanServerObjectName()
42          throws Exception JavaDoc
43    {
44       if(mbeanserver == null)
45       {
46          mbeanserver = new ObjectName JavaDoc("JMImplementation:type=MBeanServerDelegate");
47       }
48       return mbeanserver;
49    }
50
51    /**
52     * get the MBeanServerId attribute from the server
53     *
54     * @param server
55     * @return mbean server id
56     * @throws Exception
57     */

58    public static final String JavaDoc getServerId(MBeanServer JavaDoc server)
59          throws Exception JavaDoc
60    {
61       if(server == null)
62       {
63          throw new NullPointerException JavaDoc("MBeanServer is null");
64       }
65       if(mbeanserver == null)
66       {
67          mbeanserver = new ObjectName JavaDoc("JMImplementation:type=MBeanServerDelegate");
68       }
69       return (String JavaDoc) server.getAttribute(mbeanserver, "MBeanServerId");
70    }
71
72 }
73
Popular Tags