注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

和申的个人主页

专注于java开发,1985wanggang

 
 
 

日志

 
 

org.springframework.jmx.export.MBeanExporter  

2012-06-05 11:51:40|  分类: Spring |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
Overview Package Class Use Tree Deprecated Index Help
The Spring Framework
PREV CLASS NEXT CLASS FRAMES NO FRAMES All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD

http://static.springsource.org/spring/docs/2.0.1/api/org/springframework/jmx/export/MBeanExporter.html

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:
BeanFactoryAware, DisposableBean, InitializingBean, MBeanExportOperations

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

Effects the exporting of any Spring-managed bean 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 MBeanInfoAssembler implementation.

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

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

Field Summary
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.
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
void afterPropertiesSet()
Start bean registration automatically when deployed in an ApplicationContext.
protected ModelMBean createAndConfigureMBean(Object managedResource, String beanKey)
Creates an MBean that is configured with the appropriate management interface for the supplied managed resource.
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 ObjectName getObjectName(Object bean, String beanKey)
Retrieve the ObjectName for a bean.
protected boolean isBeanDefinitionLazyInit(ListableBeanFactory beanFactory, String beanName)
Return whether the specified bean definition should be considered as lazy-init.
protected void onRegister(ObjectName objectName)
Called when an MBean is registered.
protected void onUnregister(ObjectName objectName)
Called when an MBean is unregistered.
protected ObjectName registerBeanNameOrInstance(Object mapValue, String beanKey)
Registers an individual bean with the MBeanServer.
protected void registerBeans()
Registers the defined beans with the MBeanServer.
ObjectName registerManagedResource(Object managedResource)
Register the supplied resource with JMX.
void registerManagedResource(Object managedResource, ObjectName objectName)
Register the supplied resource with JMX.
void setAssembler(MBeanInfoAssembler assembler)
Set the implementation of the MBeanInfoAssembler interface to use for this exporter.
void setAutodetect(boolean autodetect)
Deprecated. in favor of setAutodetectModeName(String)
void setAutodetectMode(int autodetectMode)
Sets the autodetection mode to use.
void setAutodetectModeName(String constantName)
Sets the autodetection mode to use by name.
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 setEnsureUniqueRuntimeObjectNames(boolean ensureUniqueRuntimeObjectNames)
Indicates whether Spring should ensure that ObjectNames generated by the configured ObjectNamingStrategy for runtime-registered MBeans should be modified to ensure uniqueness for every instance of managed Class.
void setExcludedBeans(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 as 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(Map 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.
Methods inherited from class org.springframework.jmx.support.MBeanRegistrationSupport
doRegister, 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
Constructor Detail

MBeanExporter

public MBeanExporter()
Method Detail

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 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)
Deprecated. in favor of setAutodetectModeName(String)

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)

setAutodetectMode

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

Throws:
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(String constantName)
Sets 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:
setAutodetectMode(int), AUTODETECT_ALL, AUTODETECT_ASSEMBLER, AUTODETECT_MBEAN, AUTODETECT_NONE

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

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(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 should be modified to ensure uniqueness for every instance of managed Class. Default value is true.

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

setExposeManagedResourceClassLoader

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


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(Map listeners)
Set the NotificationListeners to register with the MBeanServer. The key of each entry in the Map is a String representation of the ObjectName of the MBean the listener should be registered for. Specifying an asterisk (*) 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[]).


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 ObjectName registerManagedResource(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(Object managedResource,                                      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

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,                                             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 ObjectName registerBeanNameOrInstance(Object mapValue,                                                  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 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:
beanKey - the key associated with this bean in the beans map
mapValue - the value configured for this bean in the beans map. May be either the String name of a bean, or the bean itself.
Returns:
the ObjectName under which the resource was registered
Throws:
MBeanExportException - if the export failed
See Also:
setBeans(java.util.Map), registerLazyInit(java.lang.String, java.lang.String), registerMBean(java.lang.Object, java.lang.String), registerSimpleBean(java.lang.Object, java.lang.String)

getObjectName

protected ObjectName getObjectName(Object bean,                                     String beanKey)                              throws 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:
MalformedObjectNameException - if the retrieved ObjectName is malformed

createAndConfigureMBean

protected 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)

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

onRegister

protected void onRegister(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(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

Overview Package Class Use Tree Deprecated Index Help
The Spring Framework
PREV CLASS NEXT CLASS FRAMES NO FRAMES All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD
统计信息唧唧歪歪唧唧网ggyygg.net
  评论这张
 
阅读(1922)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016