org.granite.jmx
Class MBeanServerLocator

java.lang.Object
  extended by org.granite.jmx.MBeanServerLocator

public class MBeanServerLocator
extends Object

Utility class for MBean server lookup (with a specific support for the JBoss JMX console) and MBeans registration.

Author:
Franck WOLFF

Method Summary
static MBeanServerLocator getInstance()
          Returns a singleton instance of the MBeanServerLocator class.
 MBeanServer getMBeanServer()
          Returns the MBeanServer wrapped by this MBeanServerLocator instance.
 boolean isRegistered(ObjectName name)
          Returns true if a MBean is registered under the supplied name.
 void register(Object mbean, ObjectName name)
          Register the mbean object with the supplied name.
 void register(Object mbean, ObjectName name, boolean replace)
          Register the mbean object with the supplied name.
 void unregister(ObjectName name)
          Unregister any mbean registered under the supplied name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static MBeanServerLocator getInstance()
Returns a singleton instance of the MBeanServerLocator class. The first call to this method performs an initial lookup of a MBeanServer.

Returns:
a singleton instance of the MBeanServerLocator class.

getMBeanServer

public MBeanServer getMBeanServer()
Returns the MBeanServer wrapped by this MBeanServerLocator instance.

Returns:
the wrapped MBeanServer.

register

public void register(Object mbean,
                     ObjectName name)
              throws MBeanRegistrationException,
                     InstanceNotFoundException,
                     InstanceAlreadyExistsException,
                     NotCompliantMBeanException
Register the mbean object with the supplied name. Calling this method is equivalent to calling register(Object, ObjectName, boolean) with its last parameter set to false.

Parameters:
mbean - the mbean to register.
name - the name used for registration.
Throws:
MBeanRegistrationException - rethrown from the wrapped MBeanServer
InstanceNotFoundException - rethrown from the wrapped MBeanServer
InstanceAlreadyExistsException - rethrown from the wrapped MBeanServer
NotCompliantMBeanException - rethrown from the wrapped MBeanServer

register

public void register(Object mbean,
                     ObjectName name,
                     boolean replace)
              throws MBeanRegistrationException,
                     InstanceNotFoundException,
                     InstanceAlreadyExistsException,
                     NotCompliantMBeanException
Register the mbean object with the supplied name. If the replace parameter is set to true and if a MBean is already registered under the same name, it is first unregistered.

Parameters:
mbean - the mbean to register.
name - the name used for registration.
replace - if true, a mbean registered under the same name will be first unregistered.
Throws:
MBeanRegistrationException - rethrown from the wrapped MBeanServer
InstanceNotFoundException - rethrown from the wrapped MBeanServer
InstanceAlreadyExistsException - rethrown from the wrapped MBeanServer
NotCompliantMBeanException - rethrown from the wrapped MBeanServer

isRegistered

public boolean isRegistered(ObjectName name)
Returns true if a MBean is registered under the supplied name.

Parameters:
name - the name to test for registration.
Returns:
true if a mbean is registered, false otherwise.

unregister

public void unregister(ObjectName name)
                throws InstanceNotFoundException,
                       MBeanRegistrationException
Unregister any mbean registered under the supplied name.

Parameters:
name - the name of mbean to unregister.
Throws:
InstanceNotFoundException - rethrown from the wrapped MBeanServer
MBeanRegistrationException - rethrown from the wrapped MBeanServer