The Spring Framework

org.springframework.jmx.support
Class MBeanRegistrationSupport

java.lang.Object
  extended by org.springframework.jmx.support.MBeanRegistrationSupport
Direct Known Subclasses:
ConnectorServerFactoryBean, MBeanExporter

public class MBeanRegistrationSupport
extends Object

Provides supporting infrastructure for registering MBeans with an MBeanServer. The behavior when encountering an existing MBean at a given ObjectName is fully configurable allowing for flexible registration settings.

All registered MBeans are tracked and can be unregistered by calling the #unregisterBeans() method.

Sub-classes can receive notifications when an MBean is registered or unregistered by overriding the onRegister(ObjectName) and onUnregister(ObjectName) methods respectively.

By default, the registration process will fail if attempting to register an MBean using a ObjectName that is already used.

By setting the registrationBehaviorName property to REGISTRATION_IGNORE_EXISTING the registration process will simply ignore existing MBeans leaving them registered. This is useful in settings where multiple applications want to share a common MBean in a shared MBeanServer.

Setting registrationBehaviorName property to REGISTRATION_REPLACE_EXISTING will cause existing MBeans to be replaced during registration if necessary. This is useful in situations where you can't guarantee the state of your MBeanServer.

Since:
2.0
Author:
Rob Harrop, Juergen Hoeller
See Also:
setServer(javax.management.MBeanServer), setRegistrationBehaviorName(java.lang.String), MBeanExporter

Field Summary
protected  Log logger
          Log instance for this class.
protected  Set registeredBeans
          The beans that have been registered by this exporter.
static int REGISTRATION_FAIL_ON_EXISTING
          Constant indicating that registration should fail when attempting to register an MBean under a name that already exists.
static int REGISTRATION_IGNORE_EXISTING
          Constant indicating that registration should ignore the affected MBean when attempting to register an MBean under a name that already exists.
static int REGISTRATION_REPLACE_EXISTING
          Constant indicating that registration should replace the affected MBean when attempting to register an MBean under a name that already exists.
protected  MBeanServer server
          The MBeanServer instance being used to register beans.
 
Constructor Summary
MBeanRegistrationSupport()
           
 
Method Summary
protected  void doRegister(Object mbean, ObjectName objectName)
          Actually register the MBean with the server.
protected  void onRegister(ObjectName objectName)
          Called when an MBean is registered under the given ObjectName.
protected  void onUnregister(ObjectName objectName)
          Called when an MBean is unregistered under the given ObjectName.
 void setRegistrationBehavior(int registrationBehavior)
          Specify what action should be taken when attempting to register an MBean under an ObjectName that already exists.
 void setRegistrationBehaviorName(String registrationBehavior)
          Set the registration behavior by the name of the corresponding constant, e.g.
 void setServer(MBeanServer server)
          Specify the MBeanServer instance with which all beans should be registered.
protected  void unregisterBeans()
          Unregisters all beans that have been registered by an instance of this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REGISTRATION_FAIL_ON_EXISTING

public static final int REGISTRATION_FAIL_ON_EXISTING
Constant indicating that registration should fail when attempting to register an MBean under a name that already exists.

This is the default registration behavior.

See Also:
Constant Field Values

REGISTRATION_IGNORE_EXISTING

public static final int REGISTRATION_IGNORE_EXISTING
Constant indicating that registration should ignore the affected MBean when attempting to register an MBean under a name that already exists.

See Also:
Constant Field Values

REGISTRATION_REPLACE_EXISTING

public static final int REGISTRATION_REPLACE_EXISTING
Constant indicating that registration should replace the affected MBean when attempting to register an MBean under a name that already exists.

See Also:
Constant Field Values

logger

protected final Log logger
Log instance for this class.


server

protected MBeanServer server
The MBeanServer instance being used to register beans.


registeredBeans

protected Set registeredBeans
The beans that have been registered by this exporter.

Constructor Detail

MBeanRegistrationSupport

public MBeanRegistrationSupport()
Method Detail

setServer

public void setServer(MBeanServer server)
Specify the MBeanServer instance with which all beans should be registered. The MBeanExporter will attempt to locate an existing MBeanServer if none is supplied.


setRegistrationBehaviorName

public void setRegistrationBehaviorName(String registrationBehavior)
Set the registration behavior by the name of the corresponding constant, e.g. "REGISTRATION_IGNORE_EXISTING".

See Also:
setRegistrationBehavior(int), REGISTRATION_FAIL_ON_EXISTING, REGISTRATION_IGNORE_EXISTING, REGISTRATION_REPLACE_EXISTING

setRegistrationBehavior

public void setRegistrationBehavior(int registrationBehavior)
Specify what action should be taken when attempting to register an MBean under an ObjectName that already exists.

Default is REGISTRATION_FAIL_ON_EXISTING.

See Also:
setRegistrationBehaviorName(String), REGISTRATION_FAIL_ON_EXISTING, REGISTRATION_IGNORE_EXISTING, REGISTRATION_REPLACE_EXISTING

doRegister

protected void doRegister(Object mbean,
                          ObjectName objectName)
                   throws JMException
Actually register the MBean with the server. The behavior when encountering an existing MBean can be configured using the setRegistrationBehavior(int) and setRegistrationBehaviorName(String) methods.

Throws:
JMException - if the registration failed

unregisterBeans

protected void unregisterBeans()
Unregisters all beans that have been registered by an instance of this class.


onRegister

protected void onRegister(ObjectName objectName)
Called when an MBean is registered under the given ObjectName. Allows subclasses to perform additional processing when an MBean is registered.

Parameters:
objectName - the ObjectName of the MBean that was registered.

onUnregister

protected void onUnregister(ObjectName objectName)
Called when an MBean is unregistered under the given ObjectName. Allows subclasses to perform additional processing when an MBean is unregistered.

Parameters:
objectName - the ObjectName of the MBean that was unregistered.

The Spring Framework

Copyright © 2002-2007 The Spring Framework.