Top Description Inners Fields Constructors Methods
org.springframework.jmx.export

public Class MBeanExporter

extends MBeanRegistrationSupport
implements MBeanExportOperations, BeanClassLoaderAware, BeanFactoryAware, InitializingBean, SmartInitializingSingleton, DisposableBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.SmartInitializingSingleton, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.jmx.export.MBeanExportOperations
Known Direct Subclasses
org.springframework.jmx.export.annotation.AnnotationMBeanExporter
Imports
java.util.ArrayList, .Collections, .HashMap, .HashSet, .LinkedHashMap, .LinkedHashSet, .List, .Map, .Set, javax.management.DynamicMBean, .JMException, .MBeanException, .MBeanServer, .MalformedObjectNameException, .NotCompliantMBeanException, .NotificationListener, .ObjectName, .StandardMBean, javax.management.modelmbean.ModelMBean, .ModelMBeanInfo, .RequiredModelMBean, org.springframework.aop.framework.ProxyFactory, org.springframework.aop.scope.ScopedProxyUtils, org.springframework.aop.support.AopUtils, org.springframework.aop.target.LazyInitTargetSource, org.springframework.beans.factory.BeanClassLoaderAware, .BeanFactory, .BeanFactoryAware, .CannotLoadBeanClassException, .DisposableBean, .InitializingBean, .ListableBeanFactory, .SmartInitializingSingleton, org.springframework.beans.factory.config.ConfigurableBeanFactory, .ConfigurableListableBeanFactory, org.springframework.jmx.export.assembler.AutodetectCapableMBeanInfoAssembler, .MBeanInfoAssembler, .SimpleReflectiveMBeanInfoAssembler, org.springframework.jmx.export.naming.KeyNamingStrategy, .ObjectNamingStrategy, .SelfNaming, org.springframework.jmx.export.notification.ModelMBeanNotificationPublisher, .NotificationPublisherAware, org.springframework.jmx.support.JmxUtils, .MBeanRegistrationSupport, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .CollectionUtils, .ObjectUtils

JMX exporter that allows for exposing any Spring-managed bean to a JMX javax.management.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 auto-detection 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.

Authors
Rob Harrop, Juergen Hoeller, Rick Evans, Mark Fisher, Stephane Nicoll, Sam Brannen
Since
1.2
See Also
setBeans, setAutodetect, setAssembler, setListeners, org.springframework.jmx.export.assembler.MBeanInfoAssembler, MBeanExporterListener

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static interface
MBeanExporter.AutodetectCallback

Internal callback interface for the auto-detection process.

private class

Field Summary

Modifier and TypeField and Description
private boolean
allowEagerInit

Whether to eagerly initialize candidate beans when auto-detecting MBeans.

private MBeanInfoAssembler
assembler

Stores the MBeanInfoAssembler to use for this exporter.

public static final int
AUTODETECT_ALL

Deprecated since 6.1. as of 6.1, in favor of the "autodetect" flag
Auto-detection mode indicating that all auto-detection mechanisms should be used.
public static final int
AUTODETECT_ASSEMBLER

Deprecated since 6.1. as of 6.1, in favor of the "autodetect" flag
Auto-detection mode indicating that only the MBeanInfoAssembler should be able to autodetect beans.
public static final int
AUTODETECT_MBEAN

Deprecated since 6.1. as of 6.1, in favor of the "autodetect" flag
Auto-detection mode indicating that only valid MBeans should be autodetected.
public static final int
AUTODETECT_NONE

Deprecated since 6.1. as of 6.1, in favor of the "autodetect" flag
Auto-detection mode indicating that no auto-detection should be used.
pack-priv Integer
autodetectMode

The autodetect mode to use for this MBeanExporter.

private ClassLoader
beanClassLoader

Stores the ClassLoader to use for generating lazy-init proxies.

private ListableBeanFactory
beanFactory

Stores the BeanFactory for use in auto-detection process.

private Map<String, Object>
beans

The beans to be exposed as JMX managed resources, with JMX names as keys.

private static final Map<String, Integer>
constants

Map of constant names to constant values for the autodetect constants defined in this class.

private boolean
ensureUniqueRuntimeObjectNames

Indicates whether Spring should modify generated ObjectNames.

private final Set<String>
excludedBeans

A set of bean names that should be excluded from auto-detection.

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 final 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 final Map<NotificationListenerBean, ObjectName[]>
registeredNotificationListeners

Map of actually registered NotificationListeners.

private static final String
WILDCARD

Wildcard used to map a javax.management.NotificationListener to all MBeans registered by the MBeanExporter.

Inherited from org.springframework.jmx.support.MBeanRegistrationSupport:
loggerserver

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected DynamicMBean

Returns:

the adapted MBean, or null if not possible
adaptMBeanIfPossible
(Object
the original bean instance
bean
)

Build an adapted MBean for the given bean instance, if possible.

public void
addExcludedBean(String excludedBean)

Add the name of bean that should be excluded from auto-detection.

public void
afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

public void
afterSingletonsInstantiated()

Implements org.springframework.beans.factory.SmartInitializingSingleton.afterSingletonsInstantiated.

Kick off bean registration automatically after the regular singleton instantiation phase.

private void
autodetect(Map<String, Object> beans, MBeanExporter.AutodetectCallback
the AutodetectCallback to use when deciding whether to include a bean or not
callback
)

Performs the actual auto-detection process, delegating to an AutodetectCallback instance to vote on the inclusion of a given bean.

protected ModelMBean
createAndConfigureMBean(Object
the resource that is to be exported as an MBean
managedResource
,
String
the key associated with the managed bean
beanKey
)

Creates an MBean that is configured with the appropriate management interface for the supplied managed resource.

protected ModelMBean

Returns:

a new instance of a class that implements ModelMBean
createModelMBean
()

Create an instance of a class that implements ModelMBean.

public void
destroy()

Implements org.springframework.beans.factory.DisposableBean.destroy.

Unregisters all beans that this exported has exposed via JMX when the enclosing ApplicationContext is destroyed.

private ModelMBeanInfo
getMBeanInfo(Object managedBean, String beanKey)

Gets the ModelMBeanInfo for the bean with the supplied key and of the supplied type.

protected ObjectName

Returns:

the ObjectName for the supplied bean
getObjectName
(Object
the name of the bean in the BeanFactory
bean
,
String
the key associated with the bean in the beans map
beanKey
)

Retrieve the ObjectName for a bean.

private void
injectNotificationPublisherIfNecessary(Object managedResource, ModelMBean modelMBean, ObjectName objectName)

If the supplied managed resource implements the NotificationPublisherAware an instance of org.springframework.jmx.export.notification.NotificationPublisher is injected.

private boolean
isBeanDefinitionAbstract(ListableBeanFactory beanFactory, String beanName)

Return whether the specified bean definition should be considered as abstract.

protected boolean
isBeanDefinitionLazyInit(ListableBeanFactory
the bean factory that is supposed to contain the bean definition
beanFactory
,
String
the name of the bean to check
beanName
)

Return whether the specified bean definition should be considered as lazy-init.

private boolean
isExcluded(String beanName)

Indicates whether a particular bean name is present in the excluded beans list.

protected boolean

Returns:

whether the class qualifies as an MBean
isMBean
(Class<?>
the bean class to analyze
beanClass
)

Determine whether the given bean class qualifies as an MBean as-is.

private void
notifyListenersOfRegistration(ObjectName objectName)

Notifies all registered MBeanExporterListeners of the registration of the MBean identified by the supplied ObjectName.

private void
notifyListenersOfUnregistration(ObjectName objectName)

Notifies all registered MBeanExporterListeners of the unregistration of the MBean identified by the supplied ObjectName.

protected void
onRegister(ObjectName
the ObjectName of the registered MBean
objectName
)

Overrides org.springframework.jmx.support.MBeanRegistrationSupport.onRegister.

Called when an MBean is registered.

protected void
onUnregister(ObjectName
the ObjectName of the unregistered MBean
objectName
)

Overrides org.springframework.jmx.support.MBeanRegistrationSupport.onUnregister.

Called when an MBean is unregistered.

private ObjectName

Returns:

the ObjectName under which the bean was registered with the MBeanServer
registerBeanInstance
(Object
the bean to register, either an MBean or a plain bean
bean
,
String
the key associated with this bean in the beans map
beanKey
)

Registers an existing MBean or an MBean adapter for a plain bean with the MBeanServer.

protected ObjectName

Returns:

the ObjectName under which the resource was registered
registerBeanNameOrInstance
(Object
the value configured for this bean in the beans map; may be either the String name of a bean, or the bean itself
mapValue
,
String
the key associated with this bean in the beans map
beanKey
)

Register an individual bean with the MBeanServer.

protected void
registerBeans()

Register the defined beans with the MBeanServer.

private ObjectName

Returns:

the ObjectName under which the bean was registered with the MBeanServer
registerLazyInit
(String
the name of the bean in the BeanFactory
beanName
,
String
the key associated with this bean in the beans map
beanKey
)

Register beans that are configured for lazy initialization with the MBeanServer indirectly through a proxy.

public ObjectName
registerManagedResource(Object
the resource to expose via JMX
managedResource
)

Implements org.springframework.jmx.export.MBeanExportOperations.registerManagedResource.

Register the supplied resource with JMX.

public void
registerManagedResource(Object
the resource to expose via JMX
managedResource
,
ObjectName
the ObjectName under which to expose the resource
objectName
)

Implements org.springframework.jmx.export.MBeanExportOperations.registerManagedResource.

Register the supplied resource with JMX.

private void
private void
replaceNotificationListenerBeanNameKeysIfNecessary(String
the name of the bean to be registered
beanName
,
ObjectName
the ObjectName under which the bean will be registered with the MBeanServer
objectName
)

Replace any bean names used as keys in the NotificationListener mappings with their corresponding ObjectName values.

public void
setAllowEagerInit(boolean allowEagerInit)

Specify whether to allow eager initialization of candidate beans when auto-detecting MBeans in the Spring application context.

public void
setAssembler(MBeanInfoAssembler assembler)

Set the implementation of the MBeanInfoAssembler interface to use for this exporter.

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.

public void
setAutodetectMode(int autodetectMode)
Deprecated since 6.1. as of 6.1, in favor of the "autodetect" flag

Set the auto-detection mode to use.

public void
setAutodetectModeName(String constantName)
Deprecated since 6.1. as of 6.1, in favor of the "autodetect" flag

Set the auto-detection mode to use by name.

public void
setBeanClassLoader(ClassLoader
the owning class loader
classLoader
)

Implements org.springframework.beans.factory.BeanClassLoaderAware.setBeanClassLoader.

Callback that supplies the bean class loader to a bean instance.

public void
setBeanFactory(BeanFactory
owning BeanFactory (never null). The bean can immediately call methods on the factory.
beanFactory
)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

This callback is only required for resolution of bean names in the "beans" Map and for auto-detection of MBeans (in the latter case, a ListableBeanFactory is required).

public void
setBeans(Map<String, Object>
a Map with JMX names as keys and bean instances or bean names as values
beans
)

Supply a Map of beans to be registered with the JMX MBeanServer.

public void
setEnsureUniqueRuntimeObjectNames(boolean ensureUniqueRuntimeObjectNames)

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

public void
setExcludedBeans(String... excludedBeans)

Set the list of names for beans that should be excluded from auto-detection.

public void
setExposeManagedResourceClassLoader(boolean exposeManagedResourceClassLoader)

Indicates whether the managed resource should be exposed on the thread context ClassLoader before allowing any invocations on the MBean to occur.

public void
setListeners(MBeanExporterListener... listeners)

Set the MBeanExporterListeners that should be notified of MBean registration and unregistration events.

public void
setNamingStrategy(ObjectNamingStrategy namingStrategy)

Set the implementation of the ObjectNamingStrategy interface to use for this exporter.

public void
public void
setNotificationListeners(NotificationListenerBean... notificationListeners)

Set the NotificationListenerBeans containing the NotificationListeners that will be registered with the MBeanServer.

public void
unregisterManagedResource(ObjectName
the ObjectName of the resource to remove
objectName
)

Implements org.springframework.jmx.export.MBeanExportOperations.unregisterManagedResource.

Remove the specified MBean from the underlying MBeanServer registry.

private void
Inherited from org.springframework.jmx.support.MBeanRegistrationSupport:
doRegisterdoUnregistergetRegisteredObjectNamesgetServeronRegistersetRegistrationPolicysetServerunregisterBeans