public class MBeanRegistrationSupport
extends java.lang.Object
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
.
setServer(javax.management.MBeanServer)
,
setRegistrationPolicy(org.springframework.jmx.support.RegistrationPolicy)
,
MBeanExporter
Modifier and Type | Field and Description |
---|---|
private static Constants |
constants
Constants for this class.
|
protected Log |
logger
Log instance for this class. |
private java.util.Set<javax.management.ObjectName> |
registeredBeans
The beans that have been registered by this exporter.
|
static int |
REGISTRATION_FAIL_ON_EXISTING
Deprecated.
since Spring 3.2, in favor of
RegistrationPolicy.FAIL_ON_EXISTING |
static int |
REGISTRATION_IGNORE_EXISTING
Deprecated.
since Spring 3.2, in favor of
RegistrationPolicy.IGNORE_EXISTING |
static int |
REGISTRATION_REPLACE_EXISTING
Deprecated.
since Spring 3.2, in favor of
RegistrationPolicy.REPLACE_EXISTING |
private RegistrationPolicy |
registrationPolicy
The policy used when registering an MBean and finding that it already exists.
|
protected javax.management.MBeanServer |
server
The
MBeanServer instance being used to register beans. |
Constructor and Description |
---|
MBeanRegistrationSupport() |
Modifier and Type | Method and Description |
---|---|
protected void |
doRegister(java.lang.Object mbean,
javax.management.ObjectName objectName)
Actually register the MBean with the server.
|
protected void |
doUnregister(javax.management.ObjectName objectName)
Actually unregister the specified MBean from the server.
|
protected javax.management.ObjectName[] |
getRegisteredObjectNames()
Return the
ObjectNames of all registered beans. |
javax.management.MBeanServer |
getServer()
Return the
MBeanServer that the beans will be registered with. |
protected void |
onRegister(javax.management.ObjectName objectName)
Called when an MBean is registered under the given
ObjectName . |
protected void |
onRegister(javax.management.ObjectName objectName,
java.lang.Object mbean)
Called when an MBean is registered under the given
ObjectName . |
protected void |
onUnregister(javax.management.ObjectName objectName)
Called when an MBean is unregistered under the given
ObjectName . |
void |
setRegistrationBehavior(int registrationBehavior)
Deprecated.
since Spring 3.2, in favor of
setRegistrationPolicy(RegistrationPolicy) |
void |
setRegistrationBehaviorName(java.lang.String registrationBehavior)
Deprecated.
since Spring 3.2, in favor of
setRegistrationPolicy(RegistrationPolicy) |
void |
setRegistrationPolicy(RegistrationPolicy registrationPolicy)
The policy to use when attempting to register an MBean
under an
ObjectName that already exists. |
void |
setServer(javax.management.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.
|
@Deprecated public static final int REGISTRATION_FAIL_ON_EXISTING
RegistrationPolicy.FAIL_ON_EXISTING
This is the default registration behavior.
@Deprecated public static final int REGISTRATION_IGNORE_EXISTING
RegistrationPolicy.IGNORE_EXISTING
@Deprecated public static final int REGISTRATION_REPLACE_EXISTING
RegistrationPolicy.REPLACE_EXISTING
private static final Constants constants
protected final Log logger
Log
instance for this class.protected javax.management.MBeanServer server
MBeanServer
instance being used to register beans.private final java.util.Set<javax.management.ObjectName> registeredBeans
private RegistrationPolicy registrationPolicy
public void setServer(javax.management.MBeanServer server)
MBeanServer
instance with which all beans should
be registered. The MBeanExporter
will attempt to locate an
existing MBeanServer
if none is supplied.public final javax.management.MBeanServer getServer()
MBeanServer
that the beans will be registered with.@Deprecated public void setRegistrationBehaviorName(java.lang.String registrationBehavior)
setRegistrationPolicy(RegistrationPolicy)
@Deprecated public void setRegistrationBehavior(int registrationBehavior)
setRegistrationPolicy(RegistrationPolicy)
ObjectName
that already exists.
Default is REGISTRATION_FAIL_ON_EXISTING.
public void setRegistrationPolicy(RegistrationPolicy registrationPolicy)
ObjectName
that already exists.registrationPolicy
- the policy to useprotected void doRegister(java.lang.Object mbean, javax.management.ObjectName objectName) throws javax.management.JMException
setRegistrationBehavior(int)
and setRegistrationBehaviorName(String)
methods.mbean
- the MBean instanceobjectName
- the suggested ObjectName for the MBeanjavax.management.JMException
- if the registration failedprotected void unregisterBeans()
protected void doUnregister(javax.management.ObjectName objectName)
objectName
- the suggested ObjectName for the MBeanprotected final javax.management.ObjectName[] getRegisteredObjectNames()
ObjectNames
of all registered beans.protected void onRegister(javax.management.ObjectName objectName, java.lang.Object mbean)
ObjectName
. Allows
subclasses to perform additional processing when an MBean is registered.
The default implementation delegates to onRegister(ObjectName)
.
objectName
- the actual ObjectName
that the MBean was registered withmbean
- the registered MBean instanceprotected void onRegister(javax.management.ObjectName objectName)
ObjectName
. Allows
subclasses to perform additional processing when an MBean is registered.
The default implementation is empty. Can be overridden in subclasses.
objectName
- the actual ObjectName
that the MBean was registered withprotected void onUnregister(javax.management.ObjectName objectName)
ObjectName
. Allows
subclasses to perform additional processing when an MBean is unregistered.
The default implementation is empty. Can be overridden in subclasses.
objectName
- the ObjectName
that the MBean was registered with