public class StandardMBean extends Object implements DynamicMBean, MBeanRegistration
一个MBean,其管理界面由Java接口上的反射决定。
该类在使用标准MBean时对管理界面的概念带来更大的灵活性。 在JMX规范中描述的标准MBeans的模式的直接使用意味着MBean的实现类与其管理接口之间存在固定的关系(即,如果实现类是Thing,则管理接口必须是ThingMBean)。 该类可以保持使用Java接口指定管理界面的便利性,而不需要在实现和接口类之间存在任何命名关系。
通过制作一个MBean的DynamicMBean,该类可以选择由MBean实现的任何接口作为其管理界面,只要它符合JMX模式(即由getter / setter等定义的属性)。
该类还提供了可以为DynamicMBean接口返回的MBeanInfo提供自定义描述和名称的钩子。
使用此类,可以使用任何实现类名称Impl创建一个MBean,并通过任何接口Intf定义管理接口(如当前标准MBean),以两种一般方式之一:
StandardMBean(impl,interface) : MBeanServer mbs;
...
Impl impl = new Impl(...);
StandardMBean mbean = new StandardMBean(impl, Intf.class, false);
mbs.registerMBean(mbean, objectName); public class Impl extends StandardMBean implements Intf {
public Impl() {
super(Intf.class, false);
}
// implement methods of Intf
}
[...]
MBeanServer mbs;
....
Impl impl = new Impl();
mbs.registerMBean(impl, objectName); 在任一情况下, Impl类必须实现Intf接口。
基于实现和接口类之间的命名关系的标准MBean当然仍然可用。
此类也可用于构建MXBean。 除了在上面的示例中, false函数或super(...)调用的88490777590363参数是true,所以用法与标准MBean true 。
| Modifier | Constructor and Description |
|---|---|
protected |
StandardMBean(类<?> mbeanInterface)
做一个DynamicMBean的出
这一点 ,使用指定的
mbeanInterface类。
|
protected |
StandardMBean(类<?> mbeanInterface, boolean isMXBean)
做一个DynamicMBean的出
这一点 ,使用指定的
mbeanInterface类,并选择所产生的MBean是一个MXBean。
|
|
StandardMBean(T implementation, 类<T> mbeanInterface)
使用指定的
mbeanInterface类,从对象
实现中创建一个DynamicMBean。
|
|
StandardMBean(T implementation, 类<T> mbeanInterface, boolean isMXBean)
使用指定的
mbeanInterface类,并选择生成的MBean是否为MXBean,从对象
实现中创建一个DynamicMBean。
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
cacheMBeanInfo(MBeanInfo info)
自定义钩子:缓存为此对象构建的MBeanInfo。
|
Object |
getAttribute(String attribute)
获取动态MBean的特定属性的值。
|
AttributeList |
getAttributes(String[] attributes)
获取动态MBean的几个属性的值。
|
protected MBeanInfo |
getCachedMBeanInfo()
自定义钩子:返回为此对象缓存的MBeanInfo。
|
protected String |
getClassName(MBeanInfo info)
自定义钩子:获取将在此MBean返回的MBeanInfo中使用的className。
|
protected MBeanConstructorInfo[] |
getConstructors(MBeanConstructorInfo[] ctors, Object impl)
自定义钩子:获取将在此MBean返回的MBeanInfo中使用的MBeanConstructorInfo []。
|
protected String |
getDescription(MBeanAttributeInfo info)
自定义钩子:获取将在此MBean返回的MBeanAttributeInfo中使用的描述。
|
protected String |
getDescription(MBeanConstructorInfo info)
自定义钩子:获取将在此MBean返回的MBeanConstructorInfo中使用的描述。
|
protected String |
getDescription(MBeanConstructorInfo ctor, MBeanParameterInfo param, int sequence)
自定义钩子:获取将用于MBean返回的MBeanConstructorInfo的
序列 MBeanParameterInfo的描述。
|
protected String |
getDescription(MBeanFeatureInfo info)
自定义钩子:获取将在此MBean返回的MBeanFeatureInfo中使用的描述。
|
protected String |
getDescription(MBeanInfo info)
自定义钩子:获取将在此MBean返回的MBeanInfo中使用的描述。
|
protected String |
getDescription(MBeanOperationInfo info)
自定义钩子:获取将在此MBean返回的MBeanOperationInfo中使用的描述。
|
protected String |
getDescription(MBeanOperationInfo op, MBeanParameterInfo param, int sequence)
自定义钩子:获取将用于MBean返回的MBeanOperationInfo的
序列 MBeanParameterInfo的描述。
|
protected int |
getImpact(MBeanOperationInfo info)
自定义钩子:获取将在此MBean返回的MBeanOperationInfo中使用的操作的
影响标志。
|
Object |
getImplementation()
获取此标准MBean(或MXBean)的实现。
|
类<?> |
getImplementationClass()
获取此标准MBean(或MXBean)的实现类。
|
MBeanInfo |
getMBeanInfo()
获取此MBean的 MBeanInfo 。
|
类<?> |
getMBeanInterface()
获取此标准MBean(或MXBean)的管理界面。
|
protected String |
getParameterName(MBeanConstructorInfo ctor, MBeanParameterInfo param, int sequence)
自定义钩子:获取将用于MBean返回的MBeanConstructorInfo的
序列 MBeanParameterInfo的名称。
|
protected String |
getParameterName(MBeanOperationInfo op, MBeanParameterInfo param, int sequence)
自定义钩子:获取将用于MBean返回的MBeanOperationInfo的
序列 MBeanParameterInfo的名称。
|
Object |
invoke(String actionName, Object[] params, String[] signature)
允许在动态MBean上调用操作。
|
void |
postDeregister()
允许MBean在MBean服务器中取消注册后执行所需的任何操作。
|
void |
postRegister(Boolean registrationDone)
允许MBean在MBean服务器中注册或注册失败后执行所需的操作。
|
void |
preDeregister()
允许MBean在MBean服务器取消注册之前执行所需的任何操作。
|
ObjectName |
preRegister(MBeanServer server, ObjectName name)
允许MBean在MBean服务器注册之前执行所需的任何操作。
|
void |
setAttribute(Attribute attribute)
设置动态MBean的特定属性的值。
|
AttributeList |
setAttributes(AttributeList attributes)
设置动态MBean的几个属性的值。
|
void |
setImplementation(Object implementation)
替换包含在该对象中的实现对象。
|
public StandardMBean(T implementation,
类<T> mbeanInterface)
throws NotCompliantMBeanException
使用指定的mbeanInterface类,从对象实现中创建一个DynamicMBean。
T - 允许编译器检查implementation确实实现了由mbeanInterface描述的类。
编译器只能检查这个,如果mbeanInterface是类文字,如MyMBean.class 。
implementation - 这个MBean的实现。
mbeanInterface - 此MBean的实现导出的管理界面。
如果null ,那么这个对象将使用标准的JMX设计模式来确定与给定实现相关联的管理接口。
IllegalArgumentException - 如果给定的
实现为空。
NotCompliantMBeanException - 如果
mbeanInterface不遵循管理界面的JMX设计模式,或者给定的
实现没有实现指定的接口。
protected StandardMBean(类<?> mbeanInterface) throws NotCompliantMBeanException
做一个DynamicMBean的出这一点 ,使用指定的mbeanInterface类。
致电this(this,mbeanInterface) 。 这个构造函数被保留给子类。
mbeanInterface - 此MBean导出的管理界面。
NotCompliantMBeanException -如果
mbeanInterface不遵守JMX设计模式的管理界面,或者
如果没有实现指定的接口。
public StandardMBean(T implementation,
类<T> mbeanInterface,
boolean isMXBean)
使用指定的mbeanInterface类,并选择生成的MBean是否为MXBean,从对象实现中创建一个DynamicMBean。 此构造函数可用于创建标准MBean或MXBean。 与构造函数StandardMBean(Object, Class)不同,它不会抛出NotCompliantMBeanException。
T - 允许编译器检查implementation确实实现了由mbeanInterface描述的类。
编译器只能检查这个,如果mbeanInterface是一个类文字,如MyMBean.class 。
implementation - 这个MBean的实现。
mbeanInterface - 此MBean的实现导出的管理界面。
如果null ,那么这个对象将使用标准的JMX设计模式来确定与给定实现相关联的管理接口。
isMXBean - 如果为true,那么
mbeanInterface参数命名一个MXBean接口,最终的MBean是一个MXBean。
IllegalArgumentException - 如果给定的
实现为空,或者
mbeanInterface不遵循管理接口的JMX设计模式,或者给定的
实现不实现指定的接口。
protected StandardMBean(类<?> mbeanInterface, boolean isMXBean)
做一个DynamicMBean的出这一点 ,使用指定的mbeanInterface类,并选择所产生的MBean是一个MXBean。 此构造函数可用于创建标准MBean或MXBean。 与构造函数StandardMBean(Object, Class)不同,它不会抛出NotCompliantMBeanException。
致电this(this, mbeanInterface, isMXBean) 。 这个构造函数被保留给子类。
mbeanInterface - 此MBean导出的管理界面。
isMXBean - 如果为true,
mbeanInterface参数命名一个MXBean接口,最终的MBean是MXBean。
IllegalArgumentException -如果
mbeanInterface不遵守JMX设计模式的管理界面,或者
如果没有实现指定的接口。
public void setImplementation(Object implementation) throws NotCompliantMBeanException
替换包含在该对象中的实现对象。
implementation - 本标准MBean(或MXBean)的新实现。
implementation对象必须实现在构建此StandardMBean时提供的标准MBean(或MXBean)接口。
IllegalArgumentException - 如果给定的
实现为空。
NotCompliantMBeanException - 如果给定的
实现不实现在建设中提供的标准MBean(或MXBean)接口。
getImplementation()
public Object getImplementation()
setImplementation(java.lang.Object)
public final 类<?> getMBeanInterface()
public 类<?> getImplementationClass()
public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException
DynamicMBean复制
getAttribute在界面
DynamicMBean
attribute - 要检索的属性的名称
AttributeNotFoundException
MBeanException - 包装MBean的吸气剂抛出的
java.lang.Exception 。
ReflectionException - 包装一个
java.lang.Exception在尝试调用吸气剂时抛出。
DynamicMBean.setAttribute(javax.management.Attribute)
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException
DynamicMBean复制
setAttribute在接口
DynamicMBean
attribute - 要设置的属性的标识和要设置的值。
AttributeNotFoundException
InvalidAttributeValueException
MBeanException - 包装由MBean的设置者抛出的
java.lang.Exception 。
ReflectionException - 在尝试调用MBean的设置器时抛出一个
java.lang.Exception 。
DynamicMBean.getAttribute(java.lang.String)
public AttributeList getAttributes(String[] attributes)
DynamicMBean
getAttributes在界面
DynamicMBean
attributes - 要检索的属性的列表。
DynamicMBean.setAttributes(javax.management.AttributeList)
public AttributeList setAttributes(AttributeList attributes)
DynamicMBean复制
setAttributes在界面
DynamicMBean
attributes - 属性列表:要设置的属性的标识以及要设置的属性值。
DynamicMBean.getAttributes(java.lang.String[])
public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException, ReflectionException
DynamicMBean
invoke在界面
DynamicMBean
actionName - 要调用的操作的名称。
params - 包含在调用操作时要设置的参数的数组。
signature - 包含动作签名的数组。
类对象将通过与用于加载调用操作的MBean相同的类加载器来加载。
MBeanException - 包装一个
java.lang.Exception由MBean调用的方法抛出的。
ReflectionException - 在尝试调用该方法时抛出一个
java.lang.Exception
public MBeanInfo getMBeanInfo()
MBeanInfo 。
该方法实现DynamicMBean.getMBeanInfo() 。
该方法首先调用getCachedMBeanInfo()以检索此MBean的缓存MBeanInfo(如果有)。 如果由getCachedMBeanInfo()返回的MBeanInfo不为空,则返回。
否则,此方法使用为此MBean指定的管理界面为此MBean构建默认MBeanInfo。
在构建MBeanInfo时,此方法调用自定义钩子,使子类可以提供自定义描述,参数名称等...
最后,它调用cacheMBeanInfo()以缓存新的MBeanInfo。
getMBeanInfo在界面
DynamicMBean
protected String getClassName(MBeanInfo info)
info - 通过反射导出的默认MBeanInfo。
protected String getDescription(MBeanInfo info)
info - 通过反射导出的默认MBeanInfo。
protected String getDescription(MBeanFeatureInfo info)
自定义钩子:获取将在此MBean返回的MBeanFeatureInfo中使用的描述。
子类可以重新定义此方法以提供其自定义描述。 默认实现返回info.getDescription() 。
此方法称为getDescription(MBeanAttributeInfo) , getDescription(MBeanOperationInfo) , getDescription(MBeanConstructorInfo) 。
info - 通过反射导出的默认MBeanFeatureInfo。
protected String getDescription(MBeanAttributeInfo info)
子类可以重新定义此方法以提供其自定义描述。 默认实现返回getDescription((MBeanFeatureInfo) info) 。
info - 通过反射导出的默认MBeanAttributeInfo。
protected String getDescription(MBeanConstructorInfo info)
getDescription((MBeanFeatureInfo) info) 。
info - 通过反射导出的默认MBeanConstructorInfo。
protected String getDescription(MBeanConstructorInfo ctor, MBeanParameterInfo param, int sequence)
param.getDescription() 。
ctor - 通过反射导出的默认MBeanConstructorInfo。
param - 通过反射导出的默认MBeanParameterInfo。
sequence - 考虑的参数的序列号(第一个参数为“0”,第二个参数为“1”等)。
protected String getParameterName(MBeanConstructorInfo ctor, MBeanParameterInfo param, int sequence)
param.getName() 。
ctor - 通过反射导出的默认MBeanConstructorInfo。
param - 通过反射导出的默认MBeanParameterInfo。
sequence - 考虑的参数的序列号(第一个参数为“0”,第二个参数为“1”等)。
protected String getDescription(MBeanOperationInfo info)
getDescription((MBeanFeatureInfo) info) 。
info - 通过反射导出的默认MBeanOperationInfo。
protected int getImpact(MBeanOperationInfo info)
info.getImpact() 。
info - 通过反射导出的默认MBeanOperationInfo。
protected String getParameterName(MBeanOperationInfo op, MBeanParameterInfo param, int sequence)
param.getName() 。
op - 通过反射导出的默认MBeanOperationInfo。
param - 通过反射导出的默认MBeanParameterInfo。
sequence - 考虑的参数的序列号(第一个参数为“0”,第二个参数为“1”等)。
protected String getDescription(MBeanOperationInfo op, MBeanParameterInfo param, int sequence)
param.getDescription() 。
op - 通过反射导出的默认MBeanOperationInfo。
param - 通过反射导出的默认MBeanParameterInfo。
sequence - 考虑的参数的序列号(第一个参数为“0”,第二个参数为“1”等)。
protected MBeanConstructorInfo[] getConstructors(MBeanConstructorInfo[] ctors, Object impl)
null 。
实际上,如果包装的实现不是这个对象本身,则不可能通过调用MBeanServer.createMBean(...)的实现MBeanServer.createMBean(...)函数重新创建一个包装的MBeanServer.createMBean(...) 。
ctors - 通过反射派生的默认MBeanConstructorInfo []。
impl - 包装的实现。
如果null传递,包装实现将被忽略,并返回构建函数 。
protected MBeanInfo getCachedMBeanInfo()
子类可能会重新定义此方法,以便实现自己的缓存策略。 默认实现每个实例存储一个MBeanInfo对象。
cacheMBeanInfo(MBeanInfo)
protected void cacheMBeanInfo(MBeanInfo info)
子类可能会重新定义此方法,以便实现自己的缓存策略。 在这种情况下,默认实现存储info 。 一个子类可以定义其他策略,例如不保存info (因此每次调用getMBeanInfo()时都会重构 )或共享一个唯一的MBeanInfo对象,当多个StandardMBean实例具有相等的MBeanInfo值时。
info - 新的MBeanInfo缓存。
任何先前缓存的值都将被丢弃。
此参数可能为null,在这种情况下,不存在新的缓存值。
public ObjectName preRegister(MBeanServer server, ObjectName name) throws 异常
允许MBean在MBean服务器注册之前执行所需的任何操作。 如果未指定MBean的名称,则MBean可以为其注册提供一个名称。 如果引发异常,MBean将不会在MBean服务器中注册。
此方法的默认实现返回name参数。 对于标准MBean它也不做任何事情。 对于MXBeans,它记录了MBeanServer和ObjectName参数,以便它们可用于翻译MXBean引用。
通过super.preRegister(...)来覆盖此方法来调用重写方法是一个很好的做法。 如果此对象是由其他MXBean中的属性或操作引用的MXBean,则这是必需的。
preRegister在接口
MBeanRegistration
server - MBean将在其中
server的MBean服务器。
name - MBean的对象名称。
此名称为null如果名称参数的一个createMBean或registerMBean方法在MBeanServer接口为空。
在这种情况下,此方法必须为新的MBean返回非空的ObjectName。
name参数不为空,则通常不一定是返回值。
IllegalArgumentException - 如果这是MXBean,并且
name为空。
InstanceAlreadyExistsException - 如果这是MXBean,并且已经以其他名称(在此MBean服务器或另一个)中注册。
异常 - 没有其他检查的异常被这个方法抛出,但是
异常被声明,以便子类可以覆盖该方法并抛出自己的异常。
public void postRegister(Boolean registrationDone)
允许MBean在MBean服务器中注册或注册失败后执行所需的操作。
此方法的默认实现对于标准MBean不起作用。 对于MXBeans,如果注册失败,它将撤销preRegister完成的任何工作。
通过super.postRegister(...)重写此方法来调用重写方法是一个很好的做法。 如果此对象是由其他MXBean中的属性或操作引用的MXBean,则这是必需的。
postRegister在接口
MBeanRegistration
registrationDone - 指示MBean服务器中MBean是否已成功注册。
值false表示注册阶段失败。
public void preDeregister()
throws 异常
允许MBean在MBean服务器取消注册之前执行所需的任何操作。
这种方法的默认实现什么都不做。
通过super.preDeregister(...)重写此方法来调用重写方法是一个很好的做法。
preDeregister在接口
MBeanRegistration
异常 - 没有通过此方法抛出检查的异常,但是声明
异常 ,以便子类可以覆盖此方法并抛出自己的异常。
public void postDeregister()
允许MBean在MBean服务器中取消注册后执行所需的任何操作。
此方法的默认实现对于标准MBean不起作用。 对于MXBeans,它会删除preRegister方法记录的任何信息。
通过super.postRegister(...) ,覆盖此方法来调用重写方法是一个很好的做法。 如果此对象是由其他MXBean中的属性或操作引用的MXBean,则这是必需的。
postDeregister在接口
MBeanRegistration
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.