java.applet

java.awt

java.awt.color

java.awt.datatransfer

java.awt.dnd

java.awt.event

java.awt.font

java.awt.geom

java.awt.im

java.awt.im.spi

java.awt.image

java.awt.image.renderable

java.awt.print

java.beans

java.beans.beancontext

java.io

java.lang

java.lang.annotation

java.lang.instrument

java.lang.management

java.lang.ref

java.lang.reflect

java.math

java.net

java.nio

java.nio.channels

java.nio.channels.spi

java.nio.charset

java.nio.charset.spi

java.rmi

java.rmi.activation

java.rmi.dgc

java.rmi.registry

java.rmi.server

java.security

java.security.acl

java.security.cert

java.security.interfaces

java.security.spec

java.sql

java.text

java.util

java.util.concurrent

java.util.concurrent.atomic

java.util.concurrent.locks

java.util.jar

java.util.logging

java.util.prefs

java.util.regex

java.util.zip

javax.accessibility

javax.activity

javax.crypto

javax.crypto.interfaces

javax.crypto.spec

javax.imageio

javax.imageio.event

javax.imageio.metadata

javax.imageio.plugins.bmp

javax.imageio.plugins.jpeg

javax.imageio.spi

javax.imageio.stream

javax.management

javax.management.loading

javax.management.modelmbean

javax.management.monitor

javax.management.openmbean

javax.management.relation

javax.management.remote

javax.management.remote.rmi

javax.management.timer

javax.naming

javax.naming.directory

javax.naming.event

javax.naming.ldap

javax.naming.spi

javax.net

javax.net.ssl

javax.print

javax.print.attribute

javax.print.attribute.standard

javax.print.event

javax.rmi

javax.rmi.CORBA

javax.rmi.ssl

javax.security.auth

javax.security.auth.callback

javax.security.auth.kerberos

javax.security.auth.login

javax.security.auth.spi

javax.security.auth.x500

javax.security.cert

javax.security.sasl

javax.sound.midi

javax.sound.midi.spi

javax.sound.sampled

javax.sound.sampled.spi

javax.sql

javax.sql.rowset

javax.sql.rowset.serial

javax.sql.rowset.spi

javax.swing

javax.swing.border

javax.swing.colorchooser

javax.swing.event

javax.swing.filechooser

javax.swing.plaf

javax.swing.plaf.basic

javax.swing.plaf.metal

javax.swing.plaf.multi

javax.swing.plaf.synth

javax.swing.table

javax.swing.text

javax.swing.text

javax.swing.text.parser

javax.swing.text.rtf

javax.swing.tree

javax.swing.undo

javax.transaction

javax.transaction.xa

javax.xml

javax.xml.datatype

javax.xml.namespace

javax.xml.parsers

javax.xml.transform

javax.xml.transform.dom

javax.xml.transform.sax

javax.xml.transform.stream

javax.xml.validation

javax.xml.xpath

org.ietf.jgss

org.omg.CORBA

org.omg.CORBA_2_3

org.omg.CORBA_2_3.portable

org.omg.CORBA.DynAnyPackage

org.omg.CORBA.ORBPackage

org.omg.CORBA.portable

org.omg.CORBA.TypeCodePackage

org.omg.CosNaming

org.omg.CosNaming.NamingContextExtPackage

org.omg.CosNaming.NamingContextPackage

org.omg.Dynamic

org.omg.DynamicAny

org.omg.DynamicAny.DynAnyFactoryPackage

org.omg.DynamicAny.DynAnyPackage

org.omg.IOP

org.omg.IOP.CodecFactoryPackage

org.omg.IOP.CodecPackage

org.omg.Messaging

org.omg.PortableInterceptor

org.omg.PortableInterceptor.ORBInitInfoPackage

org.omg.PortableServer

org.omg.PortableServer.CurrentPackage

org.omg.PortableServer.POAManagerPackage

org.omg.PortableServer.POAPackage

org.omg.PortableServer.portable

org.omg.PortableServer.ServantLocatorPackage

org.omg.SendingContext

org.omg.stub.java.rmi

org.w3c.dom

org.w3c.dom.bootstrap

org.w3c.dom.events

org.w3c.dom.ls

org.xml.sax

org.xml.sax.ext

org.xml.sax.helpers

allclasses-frame

allclasses-noframe

constant-values

deprecated-list

help-doc

JavaTM 2 Platform
Standard Ed. 5.0

javax.management
类 StandardMBean

java.lang.Object
  继承者 javax.management.StandardMBean
所有已实现的接口:
DynamicMBean

public class StandardMBean
extends Object
implements DynamicMBean

一个管理接口由 Java 接口上的反射确定的 MBean。

在 Standard MBean 的使用中,此类为“管理接口”这一概念提供了更多灵活性。直接使用 JMX 规范中介绍的 Standard MBean 模式意味着在 MBean 的实现类与其管理接口之间存在着固定的关系(即如果实现类是 Thing,则管理接口必须是 ThingMBean)。此类能够保留指定带有 Java 接口的管理接口这一便捷性,同时无需在实现与接口类之间存在任何命名关系。

通过从 MBean 中生成 DynamicMBean,此类能够选择任何由 MBean 实现的接口作为其管理接口,但前提是它必须遵守 JMX 模式(即由 getter/setter 等定义的属性)。

此类还提供了一些挂钩,从而能够为由 DynamicMBean 接口返回的 MBeanInfo 提供自定义的描述和名称。

通过使用此类,可以使用以下两种常规方法之一创建 MBean,使用任何实现类名 Impl、由任何接口 Intf 定义的管理接口(就当前 Standard MBean 而言)作为参数:

  • 使用公共构造方法 StandardMBean(impl、interface)
         MBeanServer mbs;
         ...
         Impl impl = new Impl(...);
         StandardMBean mbean = new StandardMBean(impl, Intf.class);
         mbs.registerMBean(mbean, objectName);
         
  • 创建 StandardMBean 子类:
         public class Impl extends StandardMBean implements Intf {
            public Impl() {
              super(Intf.class);
           }
           // implement methods of Intf
         }
    
         [...]
    
         MBeanServer mbs;
         ....
         Impl impl = new Impl();
         mbs.registerMBean(impl, objectName);
         

在任何一种情况下,类 Impl 都必须实现接口 Intf

当然,基于实现和接口类之间的命名关系的 Standard MBean 仍然可用。

从以下版本开始:
1.5

构造方法摘要
protected StandardMBean(Class mbeanInterface)
          使用指定的 mbeanInterface 类从 this 中生成 DynamicMBean。
  StandardMBean(Object implementation, Class mbeanInterface)
          使用指定的 mbeanInterface 类从对象 implementation 中生成 DynamicMBean。
 
方法摘要
protected  void cacheMBeanInfo(MBeanInfo info)
          自定义挂钩:缓存为此对象构建的 MBeanInfo。
 Object getAttribute(String attribute)
          获得 Dynamic MBean 的特定属性的值。
 AttributeList getAttributes(String[] attributes)
          获得 Dynamic 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 的第 sequence 个 BeanParameterInfo 的描述。
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 的第 sequence 个 MBeanParameterInfo 的描述。
protected  int getImpact(MBeanOperationInfo info)
          自定义挂钩:获取将在由此 MBean 返回的 MBeanOperationInfo 中使用的操作的 impact 标志。
 Object getImplementation()
          获取此 MBean 的实现。
 Class getImplementationClass()
          获取此 MBean 的实现的类。
 MBeanInfo getMBeanInfo()
          获取此 MBean 的 MBeanInfo
 Class getMBeanInterface()
          获取此 MBean 的管理接口。
protected  String getParameterName(MBeanConstructorInfo ctor, MBeanParameterInfo param, int sequence)
          自定义挂钩:获取将用于由此 MBean 返回的 MBeanConstructorInfo 的第 sequence 个 BeanParameterInfo 的名称。
protected  String getParameterName(MBeanOperationInfo op, MBeanParameterInfo param, int sequence)
          自定义挂钩:获取将用于由此 MBean 返回的 MBeanOperationInfo 的第 sequence 个 MBeanParameterInfo 的名称。
 Object invoke(String actionName, Object[] params, String[] signature)
          允许在 Dynamic MBean 上调用某个操作。
 void setAttribute(Attribute attribute)
          设置 Dynamic MBean 的特定属性的值。
 AttributeList setAttributes(AttributeList attributes)
          设置 Dynamic MBean 多个属性的值。
 void setImplementation(Object implementation)
          替换包装在此对象中的实现对象。
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

StandardMBean

public StandardMBean(Object implementation,
                     Class mbeanInterface)
              throws NotCompliantMBeanException

使用指定的 mbeanInterface 类从对象 implementation 中生成 DynamicMBean。

参数:
implementation - 此 MBean 的实现。
mbeanInterface - 由此 MBean 实现导出的管理接口。如果为 null,则此对象将使用标准 JMX 设计模式来确定与指定实现关联的管理接口。
抛出:
IllegalArgumentException - 如果给定的 implementation 为 null
NotCompliantMBeanException - 如果 mbeanInterface 不遵守管理接口的 JMX 设计模式,或者给定的 implementation 没有实现指定的接口。

StandardMBean

protected StandardMBean(Class mbeanInterface)
                 throws NotCompliantMBeanException

使用指定的 mbeanInterface 类从 this 中生成 DynamicMBean。

调用 this(this、mbeanInterface)。此构造方法是为子类保留的。

参数:
mbeanInterface - 由此 MBean 导出的管理接口。
抛出:
NotCompliantMBeanException - 如果 mbeanInterface 不遵从管理接口的 JMX 设计模式,或者 this 没有实现指定的接口。
方法详细信息

setImplementation

public void setImplementation(Object implementation)
                       throws NotCompliantMBeanException

替换包装在此对象中的实现对象。

参数:
implementation - 此 MBean 的新实现。implementation 对象必须实现构造此 StandardMBean 时提供的 MBean 接口。
抛出:
IllegalArgumentException - 如果给定的 implementation 为 null
NotCompliantMBeanException - 如果给定的 implementation 没有实现构造时提供的 MBean 接口。
另请参见:
getImplementation()

getImplementation

public Object getImplementation()
获取此 MBean 的实现。

返回:
此 MBean 的实现。
另请参见:
setImplementation(java.lang.Object)

getMBeanInterface

public final Class getMBeanInterface()
获取此 MBean 的管理接口。

返回:
此 MBean 的管理接口。

getImplementationClass

public Class getImplementationClass()
获取此 MBean 的实现的类。

返回:
此 MBean 的实现的类。

getAttribute

public Object getAttribute(String attribute)
                    throws AttributeNotFoundException,
                           MBeanException,
                           ReflectionException
从接口 DynamicMBean 复制的描述
获得 Dynamic MBean 的特定属性的值。

指定者:
接口 DynamicMBean 中的 getAttribute
参数:
attribute - 要检索的属性名
返回:
所检索的属性的值。
抛出:
AttributeNotFoundException
MBeanException - 包装由 MBean 的 getter 所抛出的 java.lang.Exception
ReflectionException - 包装试图调用 getter 时所抛出的 java.lang.Exception
另请参见:
DynamicMBean.setAttribute(javax.management.Attribute)

setAttribute

public void setAttribute(Attribute attribute)
                  throws AttributeNotFoundException,
                         InvalidAttributeValueException,
                         MBeanException,
                         ReflectionException
从接口 DynamicMBean 复制的描述
设置 Dynamic MBean 的特定属性的值。

指定者:
接口 DynamicMBean 中的 setAttribute
参数:
attribute - 要设置的属性的标识及其要设置成的值。
抛出:
AttributeNotFoundException
InvalidAttributeValueException
MBeanException - 包装由 MBean 的 setter 所抛出的 java.lang.Exception
ReflectionException - 包装试图调用 setter 时所抛出的 java.lang.Exception
另请参见:
DynamicMBean.getAttribute(java.lang.String)

getAttributes

public AttributeList getAttributes(String[] attributes)
从接口 DynamicMBean 复制的描述
获得 Dynamic MBean 多个属性的值。

指定者:
接口 DynamicMBean 中的 getAttributes
参数:
attributes - 要检索的属性列表。
返回:
已检索的属性列表。
另请参见:
DynamicMBean.setAttributes(javax.management.AttributeList)

setAttributes

public AttributeList setAttributes(AttributeList attributes)
从接口 DynamicMBean 复制的描述
设置 Dynamic MBean 多个属性的值。

指定者:
接口 DynamicMBean 中的 setAttributes
参数:
attributes - 属性列表:要设置的属性的标识及其要设置成的值。
返回:
已设置的属性的列表,以及它们的新值。
另请参见:
DynamicMBean.getAttributes(java.lang.String[])

invoke

public Object invoke(String actionName,
                     Object[] params,
                     String[] signature)
              throws MBeanException,
                     ReflectionException
从接口 DynamicMBean 复制的描述
允许在 Dynamic MBean 上调用某个操作。

指定者:
接口 DynamicMBean 中的 invoke
参数:
actionName - 要调用的操作的名称。
params - 一个数组,包含调用该操作时所要设置的参数。
signature - 包含操作签名的数组。加载类对象时,使用的类加载器与加载在其上调用操作的 MBean 所用的类加载器相同。
返回:
该操作返回的对象,表示在指定 MBean 上调用该操作的结果。
抛出:
MBeanException - 包装由 MBean 上所调用的方法抛出的 java.lang.Exception
ReflectionException - 包装试图调用该方法时所抛出的 java.lang.Exception

getMBeanInfo

public MBeanInfo getMBeanInfo()
获取此 MBean 的 MBeanInfo

此方法实现了 DynamicMBean.getMBeanInfo()

此方法首先调用 getCachedMBeanInfo(),以便检索此 MBean 的缓存 MBeanInfo(如果有)。如果由 getCachedMBeanInfo() 返回的 MBeanInfo 不为 null,则将其返回。
否则,此方法将使用为此 MBean 指定的管理接口构建此 MBean 的默认 MBeanInfo。

在构建 MBeanInfo 时,此方法将调用一些自定义挂钩,这些挂钩使子类能够提供其自定义的描述、参数名称等。
最后,它将调用 cacheMBeanInfo(),以便缓存新的 MBeanInfo。

指定者:
接口 DynamicMBean 中的 getMBeanInfo
返回:
如果不为 null,则返回缓存的该 MBean 的 MBeanInfo,如果没有缓存,则返回新构建的 MBeanInfo。

getClassName

protected String getClassName(MBeanInfo info)
自定义挂钩:获取将在由此 MBean 返回的 MBeanInfo 中使用的 className。
子类可以重定义此方法来提供其自定义的类名称。默认实现返回 info.getClassName()

参数:
info - 由反射派生的默认 MBeanInfo。
返回:
新 MBeanInfo 的类名称。

getDescription

protected String getDescription(MBeanInfo info)
自定义挂钩:获取将在由此 MBean 返回的 MBeanInfo 中使用的描述。
子类可以重定义此方法来提供其自定义的 MBean 描述。默认实现返回 info.getDescription()

参数:
info - 由反射派生的默认 MBeanInfo。
返回:
对新 MBeanInfo 的描述。

getDescription

protected String getDescription(MBeanFeatureInfo info)

自定义挂钩:获取将在由此 MBean 返回的 MBeanFeatureInfo 中使用的描述。

子类可以重定义此方法来提供其自定义的描述。默认实现返回 info.getDescription()

此方法将由 getDescription(MBeanAttributeInfo)getDescription(MBeanOperationInfo)getDescription(MBeanConstructorInfo) 调用。

参数:
info - 由反射派生的默认 MBeanFeatureInfo。
返回:
对给定 MBeanFeatureInfo 的描述。

getDescription

protected String getDescription(MBeanAttributeInfo info)
自定义挂钩:获取将在由此 MBean 返回的 MBeanAttributeInfo 中使用的描述。

子类可以重定义此方法来提供其自定义的描述。默认实现返回 getDescription((MBeanFeatureInfo) info)

参数:
info - 由反射派生的默认 MBeanAttributeInfo。
返回:
对给定 MBeanAttributeInfo 的描述。

getDescription

protected String getDescription(MBeanConstructorInfo info)
自定义挂钩:获取将在由此 MBean 返回的 MBeanConstructorInfo 中使用的描述。
子类可以重定义此方法来提供其自定义的描述。默认实现返回 getDescription((MBeanFeatureInfo) info)

参数:
info - 由反射派生的默认 MBeanConstructorInfo。
返回:
对给定 MBeanConstructorInfo 的描述。

getDescription

protected String getDescription(MBeanConstructorInfo ctor,
                                MBeanParameterInfo param,
                                int sequence)
自定义挂钩:获取将用于由此 MBean 返回的 MBeanConstructorInfo 的第 sequence 个 BeanParameterInfo 的描述。
子类可以重定义此方法来提供其自定义的描述。默认实现返回 param.getDescription()

参数:
ctor - 由反射派生的默认 MBeanConstructorInfo。
param - 由反射派生的默认 MBeanParameterInfo。
sequence - 所要考虑的参数序列号("0" 是第一个参数,"1" 是第二个参数,等等)。
返回:
对给定 MBeanParameterInfo 的描述。

getParameterName

protected String getParameterName(MBeanConstructorInfo ctor,
                                  MBeanParameterInfo param,
                                  int sequence)
自定义挂钩:获取将用于由此 MBean 返回的 MBeanConstructorInfo 的第 sequence 个 BeanParameterInfo 的名称。
子类可以重定义此方法来提供其自定义的参数名称。默认实现返回 param.getName()

参数:
ctor - 由反射派生的默认 MBeanConstructorInfo。
param - 由反射派生的默认 MBeanParameterInfo。
sequence - 所要考虑的参数序列号("0" 是第一个参数,"1" 是第二个参数,等等)。
返回:
给定 MBeanParameterInfo 的名称。

getDescription

protected String getDescription(MBeanOperationInfo info)
自定义挂钩:获取将在由此 MBean 返回的 MBeanOperationInfo 中使用的描述。
子类可以重定义此方法来提供其自定义的描述。默认实现返回 getDescription((MBeanFeatureInfo) info)

参数:
info - 由反射派生的默认 MBeanOperationInfo。
返回:
对给定 MBeanOperationInfo 的描述。

getImpact

protected int getImpact(MBeanOperationInfo info)
自定义挂钩:获取将在由此 MBean 返回的 MBeanOperationInfo 中使用的操作的 impact 标志。
子类可重定义此方法来提供其自定义的影响标志。默认实现返回 info.getImpact()

参数:
info - 由反射派生的默认 MBeanOperationInfo。
返回:
给定 MBeanOperationInfo 的影响标志。

getParameterName

protected String getParameterName(MBeanOperationInfo op,
                                  MBeanParameterInfo param,
                                  int sequence)
自定义挂钩:获取将用于由此 MBean 返回的 MBeanOperationInfo 的第 sequence 个 MBeanParameterInfo 的名称。
子类可以重定义此方法来提供其自定义的参数名称。默认实现返回 param.getName()

参数:
op - 由反射派生的默认 MBeanOperationInfo。
param - 由反射派生的默认 MBeanParameterInfo。
sequence - 所要考虑的参数序列号("0" 是第一个参数,"1" 是第二个参数,等等)。
返回:
将用于给定 MBeanParameterInfo 的名称。

getDescription

protected String getDescription(MBeanOperationInfo op,
                                MBeanParameterInfo param,
                                int sequence)
自定义挂钩:获取将用于由此 MBean 返回的 MBeanOperationInfo 的第 sequence 个 MBeanParameterInfo 的描述。
子类可以重定义此方法来提供其自定义的描述。默认实现返回 param.getDescription()

参数:
op - 由反射派生的默认 MBeanOperationInfo。
param - 由反射派生的默认 MBeanParameterInfo。
sequence - 所要考虑的参数序列号("0" 是第一个参数,"1" 是第二个参数,等等)。
返回:
对给定 MBeanParameterInfo 的描述。

getConstructors

protected MBeanConstructorInfo[] getConstructors(MBeanConstructorInfo[] ctors,
                                                 Object impl)
自定义挂钩:获取将在由此 MBean 返回的 MBeanInfo 中使用的 MBeanConstructorInfo[]。
默认情况下,如果包装的实现不是 this,则此方法返回 null。实际上,如果包装的实现不是此对象自身,则不可能通过 MBeanServer.createMBean(...) 调用实现构造方法来重新创建一个包装的实现。
换句话说,如果包装的实现为 this,则返回 ctors
子类可以重新定义此方法来修改此行为(如果需要)。

参数:
ctors - 由反射派生的默认 MBeanConstructorInfo[]。
impl - 包装的实现。如果传递了 null,则包装的实现将被忽略,并且返回 ctors
返回:
新 MBeanInfo 的 MBeanConstructorInfo[]。

getCachedMBeanInfo

protected MBeanInfo getCachedMBeanInfo()
自定义挂钩:返回为此对象缓存的 MBeanInfo。

子类可以重定义此方法来实现其自己的缓存策略。默认实现为每个实例存储一个 MBeanInfo 对象。

返回:
缓存的 MBeanInfo,如果没有缓存 MBeanInfo,则返回 null。
另请参见:
cacheMBeanInfo(MBeanInfo)

cacheMBeanInfo

protected void cacheMBeanInfo(MBeanInfo info)
自定义挂钩:缓存为此对象构建的 MBeanInfo。

子类可以重定义此方法来实现其自己的缓存策略。默认实现将 info 存储在此实例中。子类可以定义其他策略,如不保存 info(从而每次调用 getMBeanInfo() 时都将重新构造它)或者当几个 StandardMBean 实例具有相等的 MBeanInfo 值时共享惟一的 MBeanInfo 对象。

参数:
info - 要缓存的新 MBeanInfo。丢弃任何以前缓存的值。此参数可以为 null,在此情况下,没有任何新的缓存值。

JavaTM 2 Platform
Standard Ed. 5.0

提交错误或意见
有关更多的 API 参考资料和开发人员文档,请参阅 Java 2 SDK SE 开发人员文档。该文档包含更详细的、面向开发人员的描述,以及总体概述、术语定义、使用技巧和工作代码示例。

版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策