Class MBeanRegistrationSupport
- Direct Known Subclasses:
ConnectorServerFactoryBean
,MBeanExporter
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 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
.
- Since:
- 2.0
- Author:
- Rob Harrop, Juergen Hoeller, Phillip Webb
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected final org.apache.commons.logging.Log
Log
instance for this class.protected @Nullable MBeanServer
TheMBeanServer
instance being used to register beans. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
doRegister
(Object mbean, ObjectName objectName) Actually register the MBean with the server.protected void
doUnregister
(ObjectName objectName) Actually unregister the specified MBean from the server.protected final ObjectName[]
Return theObjectNames
of all registered beans.final @Nullable MBeanServer
Return theMBeanServer
that the beans will be registered with.protected void
onRegister
(ObjectName objectName) Called when an MBean is registered under the givenObjectName
.protected void
onRegister
(ObjectName objectName, Object mbean) Called when an MBean is registered under the givenObjectName
.protected void
onUnregister
(ObjectName objectName) Called when an MBean is unregistered under the givenObjectName
.void
setRegistrationPolicy
(RegistrationPolicy registrationPolicy) The policy to use when attempting to register an MBean under anObjectName
that already exists.void
setServer
(@Nullable MBeanServer server) Specify theMBeanServer
instance with which all beans should be registered.protected void
Unregisters all beans that have been registered by an instance of this class.
-
Field Details
-
logger
protected final org.apache.commons.logging.Log loggerLog
instance for this class. -
server
TheMBeanServer
instance being used to register beans.
-
-
Constructor Details
-
MBeanRegistrationSupport
public MBeanRegistrationSupport()
-
-
Method Details
-
setServer
Specify theMBeanServer
instance with which all beans should be registered. TheMBeanExporter
will attempt to locate an existingMBeanServer
if none is supplied. -
getServer
Return theMBeanServer
that the beans will be registered with. -
setRegistrationPolicy
The policy to use when attempting to register an MBean under anObjectName
that already exists.- Parameters:
registrationPolicy
- the policy to use- Since:
- 3.2
-
doRegister
Actually register the MBean with the server. The behavior when encountering an existing MBean can be configured usingsetRegistrationPolicy(org.springframework.jmx.support.RegistrationPolicy)
.- 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
Actually unregister the specified MBean from the server.- Parameters:
objectName
- the suggested ObjectName for the MBean
-
getRegisteredObjectNames
Return theObjectNames
of all registered beans. -
onRegister
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 actualObjectName
that the MBean was registered withmbean
- the registered MBean instance
-
onRegister
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 actualObjectName
that the MBean was registered with
-
onUnregister
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
- theObjectName
that the MBean was registered with
-