Class MBeanExporter
- All Implemented Interfaces:
- Aware,- BeanClassLoaderAware,- BeanFactoryAware,- DisposableBean,- InitializingBean,- SmartInitializingSingleton,- MBeanExportOperations
- Direct Known Subclasses:
- AnnotationMBeanExporter
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 MBeans as well as MXBeans.
- Since:
- 1.2
- Author:
- Rob Harrop, Juergen Hoeller, Rick Evans, Mark Fisher, Stephane Nicoll
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intAutodetection mode indicating that all autodetection mechanisms should be used.static final intAutodetection mode indicating that only theMBeanInfoAssemblershould be able to autodetect beans.static final intAutodetection mode indicating that only valid MBeans should be autodetected.static final intAutodetection mode indicating that no autodetection should be used.Fields inherited from class org.springframework.jmx.support.MBeanRegistrationSupportlogger, server
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected DynamicMBeanadaptMBeanIfPossible(Object bean) Build an adapted MBean for the given bean instance, if possible.voidaddExcludedBean(String excludedBean) Add the name of bean that should be excluded from autodetection.voidInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.voidKick off bean registration automatically after the regular singleton instantiation phase.protected ModelMBeancreateAndConfigureMBean(Object managedResource, String beanKey) Creates an MBean that is configured with the appropriate management interface for the supplied managed resource.protected ModelMBeanCreate an instance of a class that implementsModelMBean.voiddestroy()Unregisters all beans that this exported has exposed via JMX when the enclosingApplicationContextis destroyed.protected ObjectNamegetObjectName(Object bean, String beanKey) Retrieve theObjectNamefor a bean.protected booleanisBeanDefinitionLazyInit(ListableBeanFactory beanFactory, String beanName) Return whether the specified bean definition should be considered as lazy-init.protected booleanDetermine whether the given bean class qualifies as an MBean as-is.protected voidonRegister(ObjectName objectName) Called when an MBean is registered.protected voidonUnregister(ObjectName objectName) Called when an MBean is unregistered.protected ObjectNameregisterBeanNameOrInstance(Object mapValue, String beanKey) Register an individual bean with theMBeanServer.protected voidRegister the defined beans with theMBeanServer.registerManagedResource(Object managedResource) Register the supplied resource with JMX.voidregisterManagedResource(Object managedResource, ObjectName objectName) Register the supplied resource with JMX.voidsetAllowEagerInit(boolean allowEagerInit) Specify whether to allow eager initialization of candidate beans when autodetecting MBeans in the Spring application context.voidsetAssembler(MBeanInfoAssembler assembler) Set the implementation of theMBeanInfoAssemblerinterface to use for this exporter.voidsetAutodetect(boolean autodetect) Set whether to autodetect MBeans in the bean factory that this exporter runs in.voidsetAutodetectMode(int autodetectMode) Set the autodetection mode to use.voidsetAutodetectModeName(String constantName) Set the autodetection mode to use by name.voidsetBeanClassLoader(ClassLoader classLoader) Callback that supplies the beanclass loaderto a bean instance.voidsetBeanFactory(BeanFactory beanFactory) voidSupply aMapof beans to be registered with the JMXMBeanServer.voidsetEnsureUniqueRuntimeObjectNames(boolean ensureUniqueRuntimeObjectNames) Indicates whether Spring should ensure thatObjectNamesgenerated by the configuredObjectNamingStrategyfor runtime-registered MBeans (registerManagedResource(java.lang.Object)) should get modified: to ensure uniqueness for every instance of a managedClass.voidsetExcludedBeans(String... excludedBeans) Set the list of names for beans that should be excluded from autodetection.voidsetExposeManagedResourceClassLoader(boolean exposeManagedResourceClassLoader) Indicates whether the managed resource should be exposed on thethread context ClassLoaderbefore allowing any invocations on the MBean to occur.voidsetListeners(MBeanExporterListener... listeners) Set theMBeanExporterListeners that should be notified of MBean registration and unregistration events.voidsetNamingStrategy(ObjectNamingStrategy namingStrategy) Set the implementation of theObjectNamingStrategyinterface to use for this exporter.voidsetNotificationListenerMappings(Map<?, ? extends NotificationListener> listeners) Set theNotificationListenersto register with theMBeanServer.voidsetNotificationListeners(NotificationListenerBean... notificationListeners) Set theNotificationListenerBeanscontaining theNotificationListenersthat will be registered with theMBeanServer.voidunregisterManagedResource(ObjectName objectName) Remove the specified MBean from the underlying MBeanServer registry.Methods inherited from class org.springframework.jmx.support.MBeanRegistrationSupportdoRegister, doUnregister, getRegisteredObjectNames, getServer, onRegister, setRegistrationPolicy, setServer, unregisterBeans
- 
Field Details- 
AUTODETECT_NONEpublic static final int AUTODETECT_NONEAutodetection mode indicating that no autodetection should be used.- See Also:
 
- 
AUTODETECT_MBEANpublic static final int AUTODETECT_MBEANAutodetection mode indicating that only valid MBeans should be autodetected.- See Also:
 
- 
AUTODETECT_ASSEMBLERpublic static final int AUTODETECT_ASSEMBLERAutodetection mode indicating that only theMBeanInfoAssemblershould be able to autodetect beans.- See Also:
 
- 
AUTODETECT_ALLpublic static final int AUTODETECT_ALLAutodetection mode indicating that all autodetection mechanisms should be used.- See Also:
 
 
- 
- 
Constructor Details- 
MBeanExporterpublic MBeanExporter()
 
- 
- 
Method Details- 
setBeansSupply aMapof beans to be registered with the JMXMBeanServer.The String keys are the basis for the creation of JMX object names. By default, a JMX ObjectNamewill be created straight from the given key. This can be customized through specifying a customNamingStrategy.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- a Map with JMX names as keys and bean instances or bean names as values
- See Also:
 
- 
setAutodetectpublic void setAutodetect(boolean autodetect) Set whether to autodetect MBeans in the bean factory that this exporter runs in. Will also ask anAutodetectCapableMBeanInfoAssemblerif available.This feature is turned off by default. Explicitly specify truehere to enable autodetection.
- 
setAutodetectModepublic void setAutodetectMode(int autodetectMode) Set the autodetection mode to use.- Throws:
- IllegalArgumentException- if the supplied value is not one of the- AUTODETECT_constants
- See Also:
 
- 
setAutodetectModeNameSet the autodetection mode to use by name.- Throws:
- IllegalArgumentException- if the supplied value is not resolvable to one of the- AUTODETECT_constants or is- null
- See Also:
 
- 
setAllowEagerInitpublic 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. 
- 
setAssemblerSet the implementation of theMBeanInfoAssemblerinterface to use for this exporter. Default is aSimpleReflectiveMBeanInfoAssembler.The passed-in assembler can optionally implement the AutodetectCapableMBeanInfoAssemblerinterface, which enables it to participate in the exporter's MBean autodetection process.
- 
setNamingStrategySet the implementation of theObjectNamingStrategyinterface to use for this exporter. Default is aKeyNamingStrategy.- See Also:
 
- 
setEnsureUniqueRuntimeObjectNamespublic void setEnsureUniqueRuntimeObjectNames(boolean ensureUniqueRuntimeObjectNames) Indicates whether Spring should ensure thatObjectNamesgenerated by the configuredObjectNamingStrategyfor runtime-registered MBeans (registerManagedResource(java.lang.Object)) should get modified: to ensure uniqueness for every instance of a managedClass.The default value is true.
- 
setExposeManagedResourceClassLoaderpublic void setExposeManagedResourceClassLoader(boolean exposeManagedResourceClassLoader) Indicates whether the managed resource should be exposed on thethread context ClassLoaderbefore allowing any invocations on the MBean to occur.The default value is true, exposing aSpringModelMBeanwhich performs thread context ClassLoader management. Switch this flag off to expose a standard JMXRequiredModelMBean.
- 
setExcludedBeansSet the list of names for beans that should be excluded from autodetection.
- 
addExcludedBeanAdd the name of bean that should be excluded from autodetection.
- 
setListenersSet theMBeanExporterListeners that should be notified of MBean registration and unregistration events.- See Also:
 
- 
setNotificationListenersSet theNotificationListenerBeanscontaining theNotificationListenersthat will be registered with theMBeanServer.
- 
setNotificationListenerMappingsSet theNotificationListenersto register with theMBeanServer.The key of each entry in the Mapis aStringrepresentation of theObjectNameor 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 NotificationListenerto register. For more advanced options such as registeringNotificationFiltersand handback objects seesetNotificationListeners(NotificationListenerBean[]).
- 
setBeanClassLoaderDescription copied from interface:BeanClassLoaderAwareCallback that supplies the beanclass loaderto a bean instance.Invoked after the population of normal bean properties but before an initialization callback such as InitializingBean'sInitializingBean.afterPropertiesSet()method or a custom init-method.- Specified by:
- setBeanClassLoaderin interface- BeanClassLoaderAware
- Parameters:
- classLoader- the owning class loader
 
- 
setBeanFactoryThis callback is only required for resolution of bean names in the"beans"Mapand for autodetection of MBeans (in the latter case, aListableBeanFactoryis required).- Specified by:
- setBeanFactoryin interface- BeanFactoryAware
- Parameters:
- beanFactory- owning BeanFactory (never- null). The bean can immediately call methods on the factory.
- See Also:
 
- 
afterPropertiesSetpublic void afterPropertiesSet()Description copied from interface:InitializingBeanInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set. - Specified by:
- afterPropertiesSetin interface- InitializingBean
 
- 
afterSingletonsInstantiatedpublic void afterSingletonsInstantiated()Kick off bean registration automatically after the regular singleton instantiation phase.- Specified by:
- afterSingletonsInstantiatedin interface- SmartInitializingSingleton
- See Also:
 
- 
destroypublic void destroy()Unregisters all beans that this exported has exposed via JMX when the enclosingApplicationContextis destroyed.- Specified by:
- destroyin interface- DisposableBean
 
- 
registerManagedResourceDescription copied from interface:MBeanExportOperationsRegister 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 anObjectNamefor the managed resource and returns this to the caller.- Specified by:
- registerManagedResourcein interface- MBeanExportOperations
- Parameters:
- managedResource- the resource to expose via JMX
- Returns:
- the ObjectNameunder which the resource was exposed
- Throws:
- MBeanExportException- if Spring is unable to generate an- ObjectNameor register the MBean
 
- 
registerManagedResourcepublic void registerManagedResource(Object managedResource, ObjectName objectName) throws MBeanExportException Description copied from interface:MBeanExportOperationsRegister 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:
- registerManagedResourcein interface- MBeanExportOperations
- Parameters:
- managedResource- the resource to expose via JMX
- objectName- the- ObjectNameunder which to expose the resource
- Throws:
- MBeanExportException- if Spring is unable to register the MBean
 
- 
unregisterManagedResourceDescription copied from interface:MBeanExportOperationsRemove the specified MBean from the underlying MBeanServer registry.- Specified by:
- unregisterManagedResourcein interface- MBeanExportOperations
- Parameters:
- objectName- the- ObjectNameof the resource to remove
 
- 
registerBeansprotected void registerBeans()Register the defined beans with theMBeanServer.Each bean is exposed to the MBeanServervia aModelMBean. The actual implementation of theModelMBeaninterface used depends on the implementation of theModelMBeanProviderinterface that is configured. By default, theRequiredModelMBeanclass that is supplied with all JMX implementations is used.The management interface produced for each bean is dependent on the MBeanInfoAssemblerimplementation being used. TheObjectNamegiven to each bean is dependent on the implementation of theObjectNamingStrategyinterface being used.
- 
isBeanDefinitionLazyInitReturn 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:
 
- 
registerBeanNameOrInstanceprotected ObjectName registerBeanNameOrInstance(Object mapValue, String beanKey) throws MBeanExportException Register an individual bean with theMBeanServer.This method is responsible for deciding how a bean should be exposed to the MBeanServer. Specifically, if the suppliedmapValueis the name of a bean that is configured for lazy initialization, then a proxy to the resource is registered with theMBeanServerso that the lazy load behavior is honored. If the bean is already an MBean then it will be registered directly with theMBeanServerwithout any intervention. For all other beans or bean names, the resource itself is registered with theMBeanServerdirectly.- Parameters:
- mapValue- the value configured for this bean in the beans map; may be either the- Stringname of a bean, or the bean itself
- beanKey- the key associated with this bean in the beans map
- Returns:
- the ObjectNameunder which the resource was registered
- Throws:
- MBeanExportException- if the export failed
- See Also:
- 
- setBeans(java.util.Map<java.lang.String, java.lang.Object>)
- registerBeanInstance(java.lang.Object, java.lang.String)
- registerLazyInit(java.lang.String, java.lang.String)
 
 
- 
getObjectNameprotected ObjectName getObjectName(Object bean, @Nullable String beanKey) throws MalformedObjectNameException Retrieve theObjectNamefor a bean.If the bean implements the SelfNaminginterface, then theObjectNamewill be retrieved usingSelfNaming.getObjectName(). Otherwise, the configuredObjectNamingStrategyis used.- Parameters:
- bean- the name of the bean in the- BeanFactory
- beanKey- the key associated with the bean in the beans map
- Returns:
- the ObjectNamefor the supplied bean
- Throws:
- MalformedObjectNameException- if the retrieved- ObjectNameis malformed
 
- 
isMBeanDetermine whether the given bean class qualifies as an MBean as-is.The default implementation delegates to JmxUtils.isMBean(java.lang.Class<?>), which checks forDynamicMBeanclasses as well as classes with corresponding "*MBean" interface (Standard MBeans) or corresponding "*MXBean" interface (Java MXBeans).- Parameters:
- beanClass- the bean class to analyze
- Returns:
- whether the class qualifies as an MBean
- See Also:
 
- 
adaptMBeanIfPossibleBuild 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 nullif not possible
- Throws:
- JMException
 
- 
createAndConfigureMBeanprotected ModelMBean createAndConfigureMBean(Object managedResource, 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)
 
 
- 
createModelMBeanCreate an instance of a class that implementsModelMBean.This method is called to obtain a ModelMBeaninstance to use when registering a bean. This method is called once per bean during the registration phase and must return a new instance ofModelMBean- Returns:
- a new instance of a class that implements ModelMBean
- Throws:
- MBeanException- if creation of the ModelMBean failed
 
- 
onRegisterCalled when an MBean is registered. Notifies all registeredMBeanExporterListenersof the registration event.Please note that if an MBeanExporterListenerthrows 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 theMBeanExporterListener.mbeanRegistered(javax.management.ObjectName)callback.- Overrides:
- onRegisterin class- MBeanRegistrationSupport
- Parameters:
- objectName- the- ObjectNameof the registered MBean
 
- 
onUnregisterCalled when an MBean is unregistered. Notifies all registeredMBeanExporterListenersof the unregistration event.Please note that if an MBeanExporterListenerthrows 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 theMBeanExporterListener.mbeanUnregistered(javax.management.ObjectName)callback.- Overrides:
- onUnregisterin class- MBeanRegistrationSupport
- Parameters:
- objectName- the- ObjectNameof the unregistered MBean
 
 
-