org.springframework.jmx.export
Class MBeanExporter

java.lang.Object
  extended by org.springframework.jmx.export.MBeanExporter
All Implemented Interfaces:
BeanFactoryAware, DisposableBean, InitializingBean

public class MBeanExporter
extends Object
implements BeanFactoryAware, InitializingBean, DisposableBean

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

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

If the bean does not implement one of the JMX management interfaces then MBeanExporter will create the management information using the supplied MBeanMetadataAssembler implementation.

Since:
1.2
Author:
Rob Harrop, Juergen Hoeller
See Also:
setBeans(java.util.Map), setAutodetect(boolean)

Field Summary
protected  Log logger
          Log instance for this class.
 
Constructor Summary
MBeanExporter()
           
 
Method Summary
 void afterPropertiesSet()
          Start bean registration automatically when deployed in an ApplicationContext.
protected  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.
protected  boolean isBeanDefinitionLazyInit(ListableBeanFactory beanFactory, String beanName)
          Return whether the specified bean definition should be considered as lazy-init.
protected  void registerBeans()
          Registers the defined beans with the MBeanServer.
 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 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(Map beans)
          Supply a Map of beans to be registered with the JMX MBeanServer.
 void setNamingStrategy(ObjectNamingStrategy namingStrategy)
          Set the implementation of the ObjectNamingStrategy interface to use for this exporter.
 void setServer(MBeanServer server)
          Specify an instance MBeanServer with which all beans should be registered.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final Log logger
Log instance for this class.

Constructor Detail

MBeanExporter

public MBeanExporter()
Method Detail

setServer

public void setServer(MBeanServer server)
Specify an instance MBeanServer with which all beans should be registered. The MBeanExporter will attempt to locate an existing MBeanServer if none is supplied.


setBeans

public void setBeans(Map 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 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, JmxUtils.isMBean(java.lang.Class)

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 particiapte 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

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 (may not be null). The bean can immediately call methods on the factory.
See Also:
setBeans(java.util.Map), setAutodetect(boolean), ListableBeanFactory

afterPropertiesSet

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

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

registerBeans

protected void registerBeans()
                      throws JMException
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.

Throws:
JMException

isBeanDefinitionLazyInit

protected boolean isBeanDefinitionLazyInit(ListableBeanFactory beanFactory,
                                           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()

createModelMBean

protected ModelMBean createModelMBean()
                               throws 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:
MBeanException - if creation of the ModelMBean failed

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


Copyright (c) 2002-2005 The Spring Framework Project.