Top Description Fields Constructors Methods
org.springframework.jmx.support

public Class MBeanRegistrationSupport

extends Object
Class Inheritance
Known Direct Subclasses
org.springframework.jmx.export.MBeanExporter, org.springframework.jmx.support.ConnectorServerFactoryBean
Imports
java.util.LinkedHashSet, .Set, javax.management.InstanceAlreadyExistsException, .InstanceNotFoundException, .JMException, .MBeanServer, .ObjectInstance, .ObjectName, org.apache.commons.logging.Log, .LogFactory, org.springframework.lang.Nullable, org.springframework.util.Assert

Provides supporting infrastructure for registering MBeans with an javax.management.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 javax.management.ObjectName that is already used.

By setting the registrationPolicy property to RegistrationPolicy#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 registrationPolicy property to RegistrationPolicy#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.

Authors
Rob Harrop, Juergen Hoeller, Phillip Webb
Since
2.0
See Also
setServer, setRegistrationPolicy, org.springframework.jmx.export.MBeanExporter

Field Summary

Modifier and TypeField and Description
protected final Log
logger

Log instance for this class.

private final Set<ObjectName>
registeredBeans

The beans that have been registered by this exporter.

private RegistrationPolicy
registrationPolicy

The policy used when registering an MBean and finding that it already exists.

protected MBeanServer
server

The MBeanServer instance being used to register beans.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
doRegister(Object
the MBean instance
mbean
,
ObjectName
the suggested ObjectName for the MBean
objectName
)

Actually register the MBean with the server.

protected void
doUnregister(ObjectName
the suggested ObjectName for the MBean
objectName
)

Actually unregister the specified MBean from the server.

protected final ObjectName[]
getRegisteredObjectNames()

Return the ObjectNames of all registered beans.

public final MBeanServer
getServer()

Return the MBeanServer that the beans will be registered with.

protected void
onRegister(ObjectName
the actual ObjectName that the MBean was registered with
objectName
,
Object
the registered MBean instance
mbean
)

Called when an MBean is registered under the given ObjectName.

protected void
onRegister(ObjectName
the actual ObjectName that the MBean was registered with
objectName
)

Called when an MBean is registered under the given ObjectName.

protected void
onUnregister(ObjectName
the ObjectName that the MBean was registered with
objectName
)

Called when an MBean is unregistered under the given ObjectName.

public void
setRegistrationPolicy(RegistrationPolicy
the policy to use
registrationPolicy
)

The policy to use when attempting to register an MBean under an javax.management.ObjectName that already exists.

public 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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

loggerback to summary
protected final Log logger

Log instance for this class.

registeredBeansback to summary
private final Set<ObjectName> registeredBeans

The beans that have been registered by this exporter.

registrationPolicyback to summary
private RegistrationPolicy registrationPolicy

The policy used when registering an MBean and finding that it already exists. By default an exception is raised.

serverback to summary
protected MBeanServer server

The MBeanServer instance being used to register beans.

Annotations
@Nullable

Constructor Detail

MBeanRegistrationSupportback to summary
public MBeanRegistrationSupport()

Method Detail

doRegisterback to summary
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 setRegistrationPolicy.

Parameters
mbean:Object

the MBean instance

objectName:ObjectName

the suggested ObjectName for the MBean

Exceptions
JMException:
if the registration failed
doUnregisterback to summary
protected void doUnregister(ObjectName objectName)

Actually unregister the specified MBean from the server.

Parameters
objectName:ObjectName

the suggested ObjectName for the MBean

getRegisteredObjectNamesback to summary
protected final ObjectName[] getRegisteredObjectNames()

Return the ObjectNames of all registered beans.

getServerback to summary
public final MBeanServer getServer()

Return the MBeanServer that the beans will be registered with.

Annotations
@Nullable
onRegisterback to summary
protected void onRegister(ObjectName objectName, Object mbean)

Called when an MBean is registered under the given ObjectName. Allows subclasses to perform additional processing when an MBean is registered.

The default implementation delegates to onRegister(ObjectName).

Parameters
objectName:ObjectName

the actual ObjectName that the MBean was registered with

mbean:Object

the registered MBean instance

onRegisterback to summary
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.

The default implementation is empty. Can be overridden in subclasses.

Parameters
objectName:ObjectName

the actual ObjectName that the MBean was registered with

onUnregisterback to summary
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.

The default implementation is empty. Can be overridden in subclasses.

Parameters
objectName:ObjectName

the ObjectName that the MBean was registered with

setRegistrationPolicyback to summary
public void setRegistrationPolicy(RegistrationPolicy registrationPolicy)

The policy to use when attempting to register an MBean under an javax.management.ObjectName that already exists.

Parameters
registrationPolicy:RegistrationPolicy

the policy to use

Since
3.2
setServerback to summary
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.

unregisterBeansback to summary
protected void unregisterBeans()

Unregisters all beans that have been registered by an instance of this class.