org.springframework.jmx.export
Class MBeanExporter

java.lang.Object
  extended by org.springframework.jmx.support.MBeanRegistrationSupport
      extended by org.springframework.jmx.export.MBeanExporter
All Implemented Interfaces:
BeanClassLoaderAware, BeanFactoryAware, DisposableBean, InitializingBean, MBeanExportOperations
Direct Known Subclasses:
AnnotationMBeanExporter

public class MBeanExporter
extends MBeanRegistrationSupport
implements MBeanExportOperations, BeanClassLoaderAware, BeanFactoryAware, InitializingBean, DisposableBean

JMX exporter that allows for exposing any Spring-managed bean to a JMX MBeanServer, without the need to define any JMX-specific information in the bean classes.

If a bean implements one of the JMX management interfaces, MBeanExporter can simply register the MBean with the server through its autodetection process.

If a bean does not implement one of the JMX management interfaces, MBeanExporter will create the management information using the supplied MBeanInfoAssembler.

A list of MBeanExporterListeners can be registered via the listeners property, allowing application code to be notified of MBean registration and unregistration events.

This exporter is compatible with JMX 1.2 on Java 5 and above. As of Spring 2.5, it also autodetects and exports Java 6 MXBeans.

Since:
1.2
Author:
Rob Harrop, Juergen Hoeller, Rick Evans, Mark Fisher
See Also:
setBeans(java.util.Map), setAutodetect(boolean), setAssembler(org.springframework.jmx.export.assembler.MBeanInfoAssembler), setListeners(org.springframework.jmx.export.MBeanExporterListener[]), MBeanInfoAssembler, MBeanExporterListener

Nested Class Summary
private static interface MBeanExporter.AutodetectCallback
          Internal callback interface for the autodetection process.
private  class MBeanExporter.NotificationPublisherAwareLazyTargetSource
          Extension of LazyInitTargetSource that will inject a NotificationPublisher into the lazy resource as it is created if required.
 
Field Summary
private  boolean allowEagerInit
          Whether to eagerly initialize candidate beans when autodetecting MBeans
private  MBeanInfoAssembler assembler
          Stores the MBeanInfoAssembler to use for this exporter
static int AUTODETECT_ALL
          Autodetection mode indicating that all autodetection mechanisms should be used.
static int AUTODETECT_ASSEMBLER
          Autodetection mode indicating that only the MBeanInfoAssembler should be able to autodetect beans.
static int AUTODETECT_MBEAN
          Autodetection mode indicating that only valid MBeans should be autodetected.
static int AUTODETECT_NONE
          Autodetection mode indicating that no autodetection should be used.
private  java.lang.Integer autodetectMode
          The autodetect mode to use for this MBeanExporter
private  java.lang.ClassLoader beanClassLoader
          Stores the ClassLoader to use for generating lazy-init proxies
private  ListableBeanFactory beanFactory
          Stores the BeanFactory for use in autodetection process
private  java.util.Map<java.lang.String,java.lang.Object> beans
          The beans to be exposed as JMX managed resources, with JMX names as keys
private static java.lang.String CONSTANT_PREFIX_AUTODETECT
          Prefix for the autodetect constants defined in this class
private static Constants constants
          Constants instance for this class
private  boolean ensureUniqueRuntimeObjectNames
          Indicates whether Spring should modify generated ObjectNames
private  java.util.Set<java.lang.String> excludedBeans
          A set of bean names that should be excluded from autodetection
private  boolean exposeManagedResourceClassLoader
          Indicates whether Spring should expose the managed resource ClassLoader in the MBean
private  MBeanExporterListener[] listeners
          The MBeanExporterListeners registered with this exporter.
private static java.lang.String MR_TYPE_OBJECT_REFERENCE
          Constant for the JMX mr_type "ObjectReference"
private  ObjectNamingStrategy namingStrategy
          The strategy to use for creating ObjectNames for an object
private  NotificationListenerBean[] notificationListeners
          The NotificationListeners to register for the MBeans registered by this exporter
private  java.util.Map<NotificationListenerBean,javax.management.ObjectName[]> registeredNotificationListeners
          Map of actually registered NotificationListeners
private static java.lang.String WILDCARD
          Wildcard used to map a NotificationListener to all MBeans registered by the MBeanExporter.
 
Fields inherited from class org.springframework.jmx.support.MBeanRegistrationSupport
logger, registeredBeans, REGISTRATION_FAIL_ON_EXISTING, REGISTRATION_IGNORE_EXISTING, REGISTRATION_REPLACE_EXISTING, server
 
Constructor Summary
MBeanExporter()
           
 
Method Summary
protected  javax.management.DynamicMBean adaptMBeanIfPossible(java.lang.Object bean)
          Build an adapted MBean for the given bean instance, if possible.
 void afterPropertiesSet()
          Start bean registration automatically when deployed in an ApplicationContext.
private  void autodetect(MBeanExporter.AutodetectCallback callback)
          Performs the actual autodetection process, delegating to an AutodetectCallback instance to vote on the inclusion of a given bean.
private  void autodetectBeans(AutodetectCapableMBeanInfoAssembler assembler)
          Invoked when using an AutodetectCapableMBeanInfoAssembler.
private  void autodetectMBeans()
          Attempts to detect any beans defined in the ApplicationContext that are valid MBeans and registers them automatically with the MBeanServer.
protected  javax.management.modelmbean.ModelMBean createAndConfigureMBean(java.lang.Object managedResource, java.lang.String beanKey)
          Creates an MBean that is configured with the appropriate management interface for the supplied managed resource.
protected  javax.management.modelmbean.ModelMBean createModelMBean()
          Create an instance of a class that implements ModelMBean.
 void destroy()
          Unregisters all beans that this exported has exposed via JMX when the enclosing ApplicationContext is destroyed.
private  javax.management.modelmbean.ModelMBeanInfo getMBeanInfo(java.lang.Object managedBean, java.lang.String beanKey)
          Gets the ModelMBeanInfo for the bean with the supplied key and of the supplied type.
protected  javax.management.ObjectName getObjectName(java.lang.Object bean, java.lang.String beanKey)
          Retrieve the ObjectName for a bean.
private  void injectNotificationPublisherIfNecessary(java.lang.Object managedResource, javax.management.modelmbean.ModelMBean modelMBean, javax.management.ObjectName objectName)
          If the supplied managed resource implements the NotificationPublisherAware an instance of NotificationPublisher is injected.
private  boolean isBeanDefinitionAbstract(ListableBeanFactory beanFactory, java.lang.String beanName)
          Return whether the specified bean definition should be considered as abstract.
protected  boolean isBeanDefinitionLazyInit(ListableBeanFactory beanFactory, java.lang.String beanName)
          Return whether the specified bean definition should be considered as lazy-init.
private  boolean isExcluded(java.lang.String beanName)
          Indicates whether or not a particular bean name is present in the excluded beans list.
protected  boolean isMBean(java.lang.Class beanClass)
          Determine whether the given bean class qualifies as an MBean as-is.
private  void notifyListenersOfRegistration(javax.management.ObjectName objectName)
          Notifies all registered MBeanExporterListeners of the registration of the MBean identified by the supplied ObjectName.
private  void notifyListenersOfUnregistration(javax.management.ObjectName objectName)
          Notifies all registered MBeanExporterListeners of the unregistration of the MBean identified by the supplied ObjectName.
protected  void onRegister(javax.management.ObjectName objectName)
          Called when an MBean is registered.
protected  void onUnregister(javax.management.ObjectName objectName)
          Called when an MBean is unregistered.
private  javax.management.ObjectName registerBeanInstance(java.lang.Object bean, java.lang.String beanKey)
          Registers an existing MBean or an MBean adapter for a plain bean with the MBeanServer.
protected  javax.management.ObjectName registerBeanNameOrInstance(java.lang.Object mapValue, java.lang.String beanKey)
          Registers an individual bean with the MBeanServer.
protected  void registerBeans()
          Registers the defined beans with the MBeanServer.
private  javax.management.ObjectName registerLazyInit(java.lang.String beanName, java.lang.String beanKey)
          Registers beans that are configured for lazy initialization with the MBeanServer indirectly through a proxy.
 javax.management.ObjectName registerManagedResource(java.lang.Object managedResource)
          Register the supplied resource with JMX.
 void registerManagedResource(java.lang.Object managedResource, javax.management.ObjectName objectName)
          Register the supplied resource with JMX.
private  void registerNotificationListeners()
          Register the configured NotificationListeners with the MBeanServer.
private  void replaceNotificationListenerBeanNameKeysIfNecessary(java.lang.String beanName, javax.management.ObjectName objectName)
          Replaces any bean names used as keys in the NotificationListener mappings with their corresponding ObjectName values.
 void setAllowEagerInit(boolean allowEagerInit)
          Specify whether to allow eager initialization of candidate beans when autodetecting MBeans in the Spring application context.
 void setAssembler(MBeanInfoAssembler assembler)
          Set the implementation of the MBeanInfoAssembler interface to use for this exporter.
 void setAutodetect(boolean autodetect)
          Set whether to autodetect MBeans in the bean factory that this exporter runs in.
 void setAutodetectMode(int autodetectMode)
          Set the autodetection mode to use.
 void setAutodetectModeName(java.lang.String constantName)
          Set the autodetection mode to use by name.
 void setBeanClassLoader(java.lang.ClassLoader classLoader)
          Callback that supplies the bean class loader to a bean instance.
 void setBeanFactory(BeanFactory beanFactory)
          This callback is only required for resolution of bean names in the "beans" Map and for autodetection of MBeans (in the latter case, a ListableBeanFactory is required).
 void setBeans(java.util.Map<java.lang.String,java.lang.Object> beans)
          Supply a Map of beans to be registered with the JMX MBeanServer.
 void setEnsureUniqueRuntimeObjectNames(boolean ensureUniqueRuntimeObjectNames)
          Indicates whether Spring should ensure that ObjectNames generated by the configured ObjectNamingStrategy for runtime-registered MBeans (registerManagedResource(java.lang.Object)) should get modified: to ensure uniqueness for every instance of a managed Class.
 void setExcludedBeans(java.lang.String[] excludedBeans)
          Set the list of names for beans that should be excluded from autodetection.
 void setExposeManagedResourceClassLoader(boolean exposeManagedResourceClassLoader)
          Indicates whether or not the managed resource should be exposed on the thread context ClassLoader before allowing any invocations on the MBean to occur.
 void setListeners(MBeanExporterListener[] listeners)
          Set the MBeanExporterListeners that should be notified of MBean registration and unregistration events.
 void setNamingStrategy(ObjectNamingStrategy namingStrategy)
          Set the implementation of the ObjectNamingStrategy interface to use for this exporter.
 void setNotificationListenerMappings(java.util.Map<?,? extends javax.management.NotificationListener> listeners)
          Set the NotificationListeners to register with the MBeanServer.
 void setNotificationListeners(NotificationListenerBean[] notificationListeners)
          Set the NotificationListenerBeans containing the NotificationListeners that will be registered with the MBeanServer.
 void unregisterManagedResource(javax.management.ObjectName objectName)
          Remove the specified MBean from the underlying MBeanServer registry.
private  void unregisterNotificationListeners()
          Unregister the configured NotificationListeners from the MBeanServer.
 
Methods inherited from class org.springframework.jmx.support.MBeanRegistrationSupport
doRegister, doUnregister, getRegisteredObjectNames, getServer, onRegister, setRegistrationBehavior, setRegistrationBehaviorName, setServer, unregisterBeans
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AUTODETECT_NONE

public static final int AUTODETECT_NONE
Autodetection mode indicating that no autodetection should be used.

See Also:
Constant Field Values

AUTODETECT_MBEAN

public static final int AUTODETECT_MBEAN
Autodetection mode indicating that only valid MBeans should be autodetected.

See Also:
Constant Field Values

AUTODETECT_ASSEMBLER

public static final int AUTODETECT_ASSEMBLER
Autodetection mode indicating that only the MBeanInfoAssembler should be able to autodetect beans.

See Also:
Constant Field Values

AUTODETECT_ALL

public static final int AUTODETECT_ALL
Autodetection mode indicating that all autodetection mechanisms should be used.

See Also:
Constant Field Values

WILDCARD

private static final java.lang.String WILDCARD
Wildcard used to map a NotificationListener to all MBeans registered by the MBeanExporter.

See Also:
Constant Field Values

MR_TYPE_OBJECT_REFERENCE

private static final java.lang.String MR_TYPE_OBJECT_REFERENCE
Constant for the JMX mr_type "ObjectReference"

See Also:
Constant Field Values

CONSTANT_PREFIX_AUTODETECT

private static final java.lang.String CONSTANT_PREFIX_AUTODETECT
Prefix for the autodetect constants defined in this class

See Also:
Constant Field Values

constants

private static final Constants constants
Constants instance for this class


beans

private java.util.Map<java.lang.String,java.lang.Object> beans
The beans to be exposed as JMX managed resources, with JMX names as keys


autodetectMode

private java.lang.Integer autodetectMode
The autodetect mode to use for this MBeanExporter


allowEagerInit

private boolean allowEagerInit
Whether to eagerly initialize candidate beans when autodetecting MBeans


ensureUniqueRuntimeObjectNames

private boolean ensureUniqueRuntimeObjectNames
Indicates whether Spring should modify generated ObjectNames


exposeManagedResourceClassLoader

private boolean exposeManagedResourceClassLoader
Indicates whether Spring should expose the managed resource ClassLoader in the MBean


excludedBeans

private java.util.Set<java.lang.String> excludedBeans
A set of bean names that should be excluded from autodetection


listeners

private MBeanExporterListener[] listeners
The MBeanExporterListeners registered with this exporter.


notificationListeners

private NotificationListenerBean[] notificationListeners
The NotificationListeners to register for the MBeans registered by this exporter


registeredNotificationListeners

private final java.util.Map<NotificationListenerBean,javax.management.ObjectName[]> registeredNotificationListeners
Map of actually registered NotificationListeners


assembler

private MBeanInfoAssembler assembler
Stores the MBeanInfoAssembler to use for this exporter


namingStrategy

private ObjectNamingStrategy namingStrategy
The strategy to use for creating ObjectNames for an object


beanClassLoader

private java.lang.ClassLoader beanClassLoader
Stores the ClassLoader to use for generating lazy-init proxies


beanFactory

private ListableBeanFactory beanFactory
Stores the BeanFactory for use in autodetection process

Constructor Detail

MBeanExporter

public MBeanExporter()
Method Detail

setBeans

public void setBeans(java.util.Map<java.lang.String,java.lang.Object> beans)
Supply a Map of beans to be registered with the JMX MBeanServer.

The String keys are the basis for the creation of JMX object names. By default, a JMX ObjectName will be created straight from the given key. This can be customized through specifying a custom NamingStrategy.

Both bean instances and bean names are allowed as values. Bean instances are typically linked in through bean references. Bean names will be resolved as beans in the current factory, respecting lazy-init markers (that is, not triggering initialization of such beans).

Parameters:
beans - Map with JMX names as keys and bean instances or bean names as values
See Also:
setNamingStrategy(org.springframework.jmx.export.naming.ObjectNamingStrategy), KeyNamingStrategy, ObjectName.ObjectName(String)

setAutodetect

public void setAutodetect(boolean autodetect)
Set whether to autodetect MBeans in the bean factory that this exporter runs in. Will also ask an AutodetectCapableMBeanInfoAssembler if available.

This feature is turned off by default. Explicitly specify true here to enable autodetection.

See Also:
setAssembler(org.springframework.jmx.export.assembler.MBeanInfoAssembler), AutodetectCapableMBeanInfoAssembler, isMBean(java.lang.Class)

setAutodetectMode

public void setAutodetectMode(int autodetectMode)
Set the autodetection mode to use.

Throws:
java.lang.IllegalArgumentException - if the supplied value is not one of the AUTODETECT_ constants
See Also:
setAutodetectModeName(String), AUTODETECT_ALL, AUTODETECT_ASSEMBLER, AUTODETECT_MBEAN, AUTODETECT_NONE

setAutodetectModeName

public void setAutodetectModeName(java.lang.String constantName)
Set the autodetection mode to use by name.

Throws:
java.lang.IllegalArgumentException - if the supplied value is not resolvable to one of the AUTODETECT_ constants or is null
See Also:
setAutodetectMode(int), AUTODETECT_ALL, AUTODETECT_ASSEMBLER, AUTODETECT_MBEAN, AUTODETECT_NONE

setAllowEagerInit

public void setAllowEagerInit(boolean allowEagerInit)
Specify whether to allow eager initialization of candidate beans when autodetecting MBeans in the Spring application context.

Default is "false", respecting lazy-init flags on bean definitions. Switch this to "true" in order to search lazy-init beans as well, including FactoryBean-produced objects that haven't been initialized yet.


setAssembler

public void setAssembler(MBeanInfoAssembler assembler)
Set the implementation of the MBeanInfoAssembler interface to use for this exporter. Default is a SimpleReflectiveMBeanInfoAssembler.

The passed-in assembler can optionally implement the AutodetectCapableMBeanInfoAssembler interface, which enables it to participate in the exporter's MBean autodetection process.

See Also:
SimpleReflectiveMBeanInfoAssembler, AutodetectCapableMBeanInfoAssembler, MetadataMBeanInfoAssembler, setAutodetect(boolean)

setNamingStrategy

public void setNamingStrategy(ObjectNamingStrategy namingStrategy)
Set the implementation of the ObjectNamingStrategy interface to use for this exporter. Default is a KeyNamingStrategy.

See Also:
KeyNamingStrategy, MetadataNamingStrategy

setListeners

public void setListeners(MBeanExporterListener[] listeners)
Set the MBeanExporterListeners that should be notified of MBean registration and unregistration events.

See Also:
MBeanExporterListener

setExcludedBeans

public void setExcludedBeans(java.lang.String[] excludedBeans)
Set the list of names for beans that should be excluded from autodetection.


setEnsureUniqueRuntimeObjectNames

public void setEnsureUniqueRuntimeObjectNames(boolean ensureUniqueRuntimeObjectNames)
Indicates whether Spring should ensure that ObjectNames generated by the configured ObjectNamingStrategy for runtime-registered MBeans (registerManagedResource(java.lang.Object)) should get modified: to ensure uniqueness for every instance of a managed Class.

The default value is true.

See Also:
registerManagedResource(java.lang.Object), JmxUtils.appendIdentityToObjectName(javax.management.ObjectName, Object)

setExposeManagedResourceClassLoader

public void setExposeManagedResourceClassLoader(boolean exposeManagedResourceClassLoader)
Indicates whether or not the managed resource should be exposed on the thread context ClassLoader before allowing any invocations on the MBean to occur.

The default value is true, exposing a SpringModelMBean which performs thread context ClassLoader management. Switch this flag off to expose a standard JMX RequiredModelMBean.


setNotificationListeners

public void setNotificationListeners(NotificationListenerBean[] notificationListeners)
Set the NotificationListenerBeans containing the NotificationListeners that will be registered with the MBeanServer.

See Also:
setNotificationListenerMappings(java.util.Map), NotificationListenerBean

setNotificationListenerMappings

public void setNotificationListenerMappings(java.util.Map<?,? extends javax.management.NotificationListener> listeners)
Set the NotificationListeners to register with the MBeanServer.

The key of each entry in the Map is a String representation of the ObjectName or the bean name of the MBean the listener should be registered for. Specifying an asterisk (*) for a key will cause the listener to be associated with all MBeans registered by this class at startup time.

The value of each entry is the NotificationListener to register. For more advanced options such as registering NotificationFilters and handback objects see setNotificationListeners(NotificationListenerBean[]).


setBeanClassLoader

public void setBeanClassLoader(java.lang.ClassLoader classLoader)
Description copied from interface: BeanClassLoaderAware
Callback that supplies the bean class loader to a bean instance.

Invoked after the population of normal bean properties but before an initialization callback such as InitializingBean's InitializingBean.afterPropertiesSet() method or a custom init-method.

Specified by:
setBeanClassLoader in interface BeanClassLoaderAware
Parameters:
classLoader - the owning class loader; may be null in which case a default ClassLoader must be used, for example the ClassLoader obtained via ClassUtils.getDefaultClassLoader()

setBeanFactory

public void setBeanFactory(BeanFactory beanFactory)
This callback is only required for resolution of bean names in the "beans" Map and for autodetection of MBeans (in the latter case, a ListableBeanFactory is required).

Specified by:
setBeanFactory in interface BeanFactoryAware
Parameters:
beanFactory - owning BeanFactory (never null). The bean can immediately call methods on the factory.
See Also:
setBeans(java.util.Map), setAutodetect(boolean)

afterPropertiesSet

public void afterPropertiesSet()
Start bean registration automatically when deployed in an ApplicationContext.

Specified by:
afterPropertiesSet in interface InitializingBean
See Also:
registerBeans()

destroy

public void destroy()
Unregisters all beans that this exported has exposed via JMX when the enclosing ApplicationContext is destroyed.

Specified by:
destroy in interface DisposableBean

registerManagedResource

public javax.management.ObjectName registerManagedResource(java.lang.Object managedResource)
                                                    throws MBeanExportException
Description copied from interface: MBeanExportOperations
Register the supplied resource with JMX. If the resource is not a valid MBean already, Spring will generate a management interface for it. The exact interface generated will depend on the implementation and its configuration. This call also generates an ObjectName for the managed resource and returns this to the caller.

Specified by:
registerManagedResource in interface MBeanExportOperations
Parameters:
managedResource - the resource to expose via JMX
Returns:
the ObjectName under which the resource was exposed
Throws:
MBeanExportException - if Spring is unable to generate an ObjectName or register the MBean

registerManagedResource

public void registerManagedResource(java.lang.Object managedResource,
                                    javax.management.ObjectName objectName)
                             throws MBeanExportException
Description copied from interface: MBeanExportOperations
Register the supplied resource with JMX. If the resource is not a valid MBean already, Spring will generate a management interface for it. The exact interface generated will depend on the implementation and its configuration.

Specified by:
registerManagedResource in interface MBeanExportOperations
Parameters:
managedResource - the resource to expose via JMX
objectName - the ObjectName under which to expose the resource
Throws:
MBeanExportException - if Spring is unable to register the MBean

unregisterManagedResource

public void unregisterManagedResource(javax.management.ObjectName objectName)
Description copied from interface: MBeanExportOperations
Remove the specified MBean from the underlying MBeanServer registry.

Specified by:
unregisterManagedResource in interface MBeanExportOperations
Parameters:
objectName - the ObjectName of the resource to remove

registerBeans

protected void registerBeans()
Registers the defined beans with the MBeanServer.

Each bean is exposed to the MBeanServer via a ModelMBean. The actual implemetation of the ModelMBean interface used depends on the implementation of the ModelMBeanProvider interface that is configured. By default the RequiredModelMBean class that is supplied with all JMX implementations is used.

The management interface produced for each bean is dependent on the MBeanInfoAssembler implementation being used. The ObjectName given to each bean is dependent on the implementation of the ObjectNamingStrategy interface being used.


isBeanDefinitionLazyInit

protected boolean isBeanDefinitionLazyInit(ListableBeanFactory beanFactory,
                                           java.lang.String beanName)
Return whether the specified bean definition should be considered as lazy-init.

Parameters:
beanFactory - the bean factory that is supposed to contain the bean definition
beanName - the name of the bean to check
See Also:
ConfigurableListableBeanFactory.getBeanDefinition(java.lang.String), BeanDefinition.isLazyInit()

registerBeanNameOrInstance

protected javax.management.ObjectName registerBeanNameOrInstance(java.lang.Object mapValue,
                                                                 java.lang.String beanKey)
                                                          throws MBeanExportException
Registers an individual bean with the MBeanServer.

This method is responsible for deciding how a bean should be exposed to the MBeanServer. Specifically, if the supplied mapValue is the name of a bean that is configured for lazy initialization, then a proxy to the resource is registered with the MBeanServer so that the the lazy load behavior is honored. If the bean is already an MBean then it will be registered directly with the MBeanServer without any intervention. For all other beans or bean names, the resource itself is registered with the MBeanServer directly.

Parameters:
mapValue - the value configured for this bean in the beans map; may be either the String name of a bean, or the bean itself
beanKey - the key associated with this bean in the beans map
Returns:
the ObjectName under which the resource was registered
Throws:
MBeanExportException - if the export failed
See Also:
setBeans(java.util.Map), registerBeanInstance(java.lang.Object, java.lang.String), registerLazyInit(java.lang.String, java.lang.String)

replaceNotificationListenerBeanNameKeysIfNecessary

private void replaceNotificationListenerBeanNameKeysIfNecessary(java.lang.String beanName,
                                                                javax.management.ObjectName objectName)
Replaces any bean names used as keys in the NotificationListener mappings with their corresponding ObjectName values.

Parameters:
beanName - the name of the bean to be registered
objectName - the ObjectName under which the bean will be registered with the MBeanServer

registerBeanInstance

private javax.management.ObjectName registerBeanInstance(java.lang.Object bean,
                                                         java.lang.String beanKey)
                                                  throws javax.management.JMException
Registers an existing MBean or an MBean adapter for a plain bean with the MBeanServer.

Parameters:
bean - the bean to register, either an MBean or a plain bean
beanKey - the key associated with this bean in the beans map
Returns:
the ObjectName under which the bean was registered with the MBeanServer
Throws:
javax.management.JMException

registerLazyInit

private javax.management.ObjectName registerLazyInit(java.lang.String beanName,
                                                     java.lang.String beanKey)
                                              throws javax.management.JMException
Registers beans that are configured for lazy initialization with the MBeanServer indirectly through a proxy.

Parameters:
beanName - the name of the bean in the BeanFactory
beanKey - the key associated with this bean in the beans map
Returns:
the ObjectName under which the bean was registered with the MBeanServer
Throws:
javax.management.JMException

getObjectName

protected javax.management.ObjectName getObjectName(java.lang.Object bean,
                                                    java.lang.String beanKey)
                                             throws javax.management.MalformedObjectNameException
Retrieve the ObjectName for a bean.

If the bean implements the SelfNaming interface, then the ObjectName will be retrieved using SelfNaming.getObjectName(). Otherwise, the configured ObjectNamingStrategy is used.

Parameters:
bean - the name of the bean in the BeanFactory
beanKey - the key associated with the bean in the beans map
Returns:
the ObjectName for the supplied bean
Throws:
javax.management.MalformedObjectNameException - if the retrieved ObjectName is malformed

isMBean

protected boolean isMBean(java.lang.Class beanClass)
Determine whether the given bean class qualifies as an MBean as-is.

The default implementation delegates to JmxUtils.isMBean(java.lang.Class), which checks for DynamicMBean classes as well as classes with corresponding "*MBean" interface (Standard MBeans) or corresponding "*MXBean" interface (Java 6 MXBeans).

Parameters:
beanClass - the bean class to analyze
Returns:
whether the class qualifies as an MBean
See Also:
JmxUtils.isMBean(Class)

adaptMBeanIfPossible

protected javax.management.DynamicMBean adaptMBeanIfPossible(java.lang.Object bean)
                                                      throws javax.management.JMException
Build an adapted MBean for the given bean instance, if possible.

The default implementation builds a JMX 1.2 StandardMBean for the target's MBean/MXBean interface in case of an AOP proxy, delegating the interface's management operations to the proxy.

Parameters:
bean - the original bean instance
Returns:
the adapted MBean, or null if not possible
Throws:
javax.management.JMException

createAndConfigureMBean

protected javax.management.modelmbean.ModelMBean createAndConfigureMBean(java.lang.Object managedResource,
                                                                         java.lang.String beanKey)
                                                                  throws MBeanExportException
Creates an MBean that is configured with the appropriate management interface for the supplied managed resource.

Parameters:
managedResource - the resource that is to be exported as an MBean
beanKey - the key associated with the managed bean
Throws:
MBeanExportException
See Also:
createModelMBean(), getMBeanInfo(Object, String)

createModelMBean

protected javax.management.modelmbean.ModelMBean createModelMBean()
                                                           throws javax.management.MBeanException
Create an instance of a class that implements ModelMBean.

This method is called to obtain a ModelMBean instance to use when registering a bean. This method is called once per bean during the registration phase and must return a new instance of ModelMBean

Returns:
a new instance of a class that implements ModelMBean
Throws:
javax.management.MBeanException - if creation of the ModelMBean failed

getMBeanInfo

private javax.management.modelmbean.ModelMBeanInfo getMBeanInfo(java.lang.Object managedBean,
                                                                java.lang.String beanKey)
                                                         throws javax.management.JMException
Gets the ModelMBeanInfo for the bean with the supplied key and of the supplied type.

Throws:
javax.management.JMException

autodetectBeans

private void autodetectBeans(AutodetectCapableMBeanInfoAssembler assembler)
Invoked when using an AutodetectCapableMBeanInfoAssembler. Gives the assembler the opportunity to add additional beans from the BeanFactory to the list of beans to be exposed via JMX.

This implementation prevents a bean from being added to the list automatically if it has already been added manually, and it prevents certain internal classes from being registered automatically.


autodetectMBeans

private void autodetectMBeans()
Attempts to detect any beans defined in the ApplicationContext that are valid MBeans and registers them automatically with the MBeanServer.


autodetect

private void autodetect(MBeanExporter.AutodetectCallback callback)
Performs the actual autodetection process, delegating to an AutodetectCallback instance to vote on the inclusion of a given bean.

Parameters:
callback - the AutodetectCallback to use when deciding whether to include a bean or not

isExcluded

private boolean isExcluded(java.lang.String beanName)
Indicates whether or not a particular bean name is present in the excluded beans list.


isBeanDefinitionAbstract

private boolean isBeanDefinitionAbstract(ListableBeanFactory beanFactory,
                                         java.lang.String beanName)
Return whether the specified bean definition should be considered as abstract.


injectNotificationPublisherIfNecessary

private void injectNotificationPublisherIfNecessary(java.lang.Object managedResource,
                                                    javax.management.modelmbean.ModelMBean modelMBean,
                                                    javax.management.ObjectName objectName)
If the supplied managed resource implements the NotificationPublisherAware an instance of NotificationPublisher is injected.


registerNotificationListeners

private void registerNotificationListeners()
                                    throws MBeanExportException
Register the configured NotificationListeners with the MBeanServer.

Throws:
MBeanExportException

unregisterNotificationListeners

private void unregisterNotificationListeners()
Unregister the configured NotificationListeners from the MBeanServer.


onRegister

protected void onRegister(javax.management.ObjectName objectName)
Called when an MBean is registered. Notifies all registered MBeanExporterListeners of the registration event.

Please note that if an MBeanExporterListener throws a (runtime) exception when notified, this will essentially interrupt the notification process and any remaining listeners that have yet to be notified will not (obviously) receive the MBeanExporterListener.mbeanRegistered(javax.management.ObjectName) callback.

Overrides:
onRegister in class MBeanRegistrationSupport
Parameters:
objectName - the ObjectName of the registered MBean

onUnregister

protected void onUnregister(javax.management.ObjectName objectName)
Called when an MBean is unregistered. Notifies all registered MBeanExporterListeners of the unregistration event.

Please note that if an MBeanExporterListener throws a (runtime) exception when notified, this will essentially interrupt the notification process and any remaining listeners that have yet to be notified will not (obviously) receive the MBeanExporterListener.mbeanUnregistered(javax.management.ObjectName) callback.

Overrides:
onUnregister in class MBeanRegistrationSupport
Parameters:
objectName - the ObjectName of the unregistered MBean

notifyListenersOfRegistration

private void notifyListenersOfRegistration(javax.management.ObjectName objectName)
Notifies all registered MBeanExporterListeners of the registration of the MBean identified by the supplied ObjectName.


notifyListenersOfUnregistration

private void notifyListenersOfUnregistration(javax.management.ObjectName objectName)
Notifies all registered MBeanExporterListeners of the unregistration of the MBean identified by the supplied ObjectName.