Class MBeanRegistrationSupport
- java.lang.Object
- org.springframework.jmx.support.MBeanRegistrationSupport
- Direct Known Subclasses:
ConnectorServerFactoryBean,MBeanExporter
public class MBeanRegistrationSupport extends Object
Provides supporting infrastructure for registering MBeans with anMBeanServer. The behavior when encountering an existing MBean at a givenObjectNameis 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)andonUnregister(ObjectName)methods respectively.By default, the registration process will fail if attempting to register an MBean using a
ObjectNamethat is already used.By setting the
registrationPolicyproperty toRegistrationPolicy.IGNORE_EXISTINGthe 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 sharedMBeanServer.Setting
registrationPolicyproperty toRegistrationPolicy.REPLACE_EXISTINGwill cause existing MBeans to be replaced during registration if necessary. This is useful in situations where you can't guarantee the state of yourMBeanServer.- Since:
- 2.0
- Author:
- Rob Harrop, Juergen Hoeller, Phillip Webb
- See Also:
setServer(javax.management.MBeanServer),setRegistrationPolicy(org.springframework.jmx.support.RegistrationPolicy),MBeanExporter
Field Summary
Fields Modifier and Type Field Description protected LogloggerLoginstance for this class.static intREGISTRATION_FAIL_ON_EXISTINGDeprecated.since Spring 3.2, in favor ofRegistrationPolicy.FAIL_ON_EXISTINGstatic intREGISTRATION_IGNORE_EXISTINGDeprecated.since Spring 3.2, in favor ofRegistrationPolicy.IGNORE_EXISTINGstatic intREGISTRATION_REPLACE_EXISTINGDeprecated.since Spring 3.2, in favor ofRegistrationPolicy.REPLACE_EXISTINGprotected MBeanServerserverTheMBeanServerinstance being used to register beans.
Constructor Summary
Constructors Constructor Description MBeanRegistrationSupport()
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voiddoRegister(Object mbean, ObjectName objectName)Actually register the MBean with the server.protected voiddoUnregister(ObjectName objectName)Actually unregister the specified MBean from the server.protected ObjectName[]getRegisteredObjectNames()Return theObjectNamesof all registered beans.MBeanServergetServer()Return theMBeanServerthat the beans will be registered with.protected voidonRegister(ObjectName objectName)Called when an MBean is registered under the givenObjectName.protected voidonRegister(ObjectName objectName, Object mbean)Called when an MBean is registered under the givenObjectName.protected voidonUnregister(ObjectName objectName)Called when an MBean is unregistered under the givenObjectName.voidsetRegistrationBehavior(int registrationBehavior)Deprecated.since Spring 3.2, in favor ofsetRegistrationPolicy(RegistrationPolicy)voidsetRegistrationBehaviorName(String registrationBehavior)Deprecated.since Spring 3.2, in favor ofsetRegistrationPolicy(RegistrationPolicy)voidsetRegistrationPolicy(RegistrationPolicy registrationPolicy)The policy to use when attempting to register an MBean under anObjectNamethat already exists.voidsetServer(MBeanServer server)Specify theMBeanServerinstance with which all beans should be registered.protected voidunregisterBeans()Unregisters all beans that have been registered by an instance of this class.
Field Detail
REGISTRATION_FAIL_ON_EXISTING
@Deprecated public static final int REGISTRATION_FAIL_ON_EXISTING
Deprecated.since Spring 3.2, in favor ofRegistrationPolicy.FAIL_ON_EXISTINGConstant 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
@Deprecated public static final int REGISTRATION_IGNORE_EXISTING
Deprecated.since Spring 3.2, in favor ofRegistrationPolicy.IGNORE_EXISTINGConstant 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
@Deprecated public static final int REGISTRATION_REPLACE_EXISTING
Deprecated.since Spring 3.2, in favor ofRegistrationPolicy.REPLACE_EXISTINGConstant 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
server
protected MBeanServer server
TheMBeanServerinstance being used to register beans.
Constructor Detail
MBeanRegistrationSupport
public MBeanRegistrationSupport()
Method Detail
setServer
public void setServer(MBeanServer server)
Specify theMBeanServerinstance with which all beans should be registered. TheMBeanExporterwill attempt to locate an existingMBeanServerif none is supplied.
getServer
public final MBeanServer getServer()
Return theMBeanServerthat the beans will be registered with.
setRegistrationBehaviorName
@Deprecated public void setRegistrationBehaviorName(String registrationBehavior)
Deprecated.since Spring 3.2, in favor ofsetRegistrationPolicy(RegistrationPolicy)Set the registration behavior by the name of the corresponding constant, e.g. "REGISTRATION_IGNORE_EXISTING".
setRegistrationBehavior
@Deprecated public void setRegistrationBehavior(int registrationBehavior)
Deprecated.since Spring 3.2, in favor ofsetRegistrationPolicy(RegistrationPolicy)Specify what action should be taken when attempting to register an MBean under anObjectNamethat already exists.Default is REGISTRATION_FAIL_ON_EXISTING.
setRegistrationPolicy
public void setRegistrationPolicy(RegistrationPolicy registrationPolicy)
The policy to use when attempting to register an MBean under anObjectNamethat already exists.- Parameters:
registrationPolicy- the policy to use- Since:
- 3.2
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 thesetRegistrationBehavior(int)andsetRegistrationBehaviorName(String)methods.- Parameters:
mbean- the MBean instanceobjectName- the suggested ObjectName for the MBean- Throws:
JMException- if the registration failed
unregisterBeans
protected void unregisterBeans()
Unregisters all beans that have been registered by an instance of this class.
doUnregister
protected void doUnregister(ObjectName objectName)
Actually unregister the specified MBean from the server.- Parameters:
objectName- the suggested ObjectName for the MBean
getRegisteredObjectNames
protected final ObjectName[] getRegisteredObjectNames()
Return theObjectNamesof all registered beans.
onRegister
protected void onRegister(ObjectName objectName, Object mbean)
Called when an MBean is registered under the givenObjectName. Allows subclasses to perform additional processing when an MBean is registered.The default implementation delegates to
onRegister(ObjectName).- Parameters:
objectName- the actualObjectNamethat the MBean was registered withmbean- the registered MBean instance
onRegister
protected void onRegister(ObjectName objectName)
Called when an MBean is registered under the givenObjectName. Allows subclasses to perform additional processing when an MBean is registered.The default implementation is empty. Can be overridden in subclasses.
- Parameters:
objectName- the actualObjectNamethat the MBean was registered with
onUnregister
protected void onUnregister(ObjectName objectName)
Called when an MBean is unregistered under the givenObjectName. Allows subclasses to perform additional processing when an MBean is unregistered.The default implementation is empty. Can be overridden in subclasses.
- Parameters:
objectName- theObjectNamethat the MBean was registered with