|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjavax.management.modelmbean.RequiredModelMBean
public class RequiredModelMBean
此类是 ModelMBean 的实现。每个发行的 JMX Agent 必须带有 ModelMBean 的适当实现,且该类必须是指定的 RequiredModelMBean。
Java 资源使用 MBeanServer 的 createMBean 方法来实例化 RequiredModelMBean,希望以这种方式获得可管理性。然后该资源设置 RequiredModelMBean 实例的 MBeanInfo 和 Descriptor。通过 ModelMBean 的 ModelMBeanInfo 公开的属性和操作像其他 MBean 一样可以从 MBean、连接器/适配器进行访问。通过使用 Descriptor,可以定义托管应用程序中的值和方法,并可以将它们映射到 ModelMBean 的属性和操作。此映射可以在 XML 格式的文件中定义,也可以以编程方式在运行时动态定义。
MBeanServer 中实例化的每个 RequiredModelMBean 都将是可管理的:
通过连接到该 MBeanServer 的连接器/适配器,可以远程访问其属性和操作。
Java 对象不能在 MBeanServer 中进行注册,除非它是 JMX 兼容的 MBean。通过实例化 RequiredModelMBean,资源得到了保证,因此 MBean 是有效的。每个公共方法必须抛出 MBeanException 和 RuntimeOperationsException,允许使用这些异常包装来自分布式通信(RMI、EJB 等)的异常。
| 构造方法摘要 | |
|---|---|
RequiredModelMBean() 构造带有空 ModelMBeanInfo 的 RequiredModelMBean。 |
|
RequiredModelMBean(ModelMBeanInfo mbi) 使用传入的 ModelMBeanInfo 构造 RequiredModelMBean 对象。 |
|
| 方法摘要 | |
|---|---|
void |
addAttributeChangeNotificationListener(NotificationListener inlistener, String inAttributeName, Object inhandback) 注册一个将 NotificationListener 接口实现为侦听器的对象。 |
void |
addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) 注册一个将 NotificationListener 接口实现为侦听器的对象。 |
Object |
getAttribute(String attrName) 返回为此 ModelMBean 定义的指定属性的值。 |
AttributeList |
getAttributes(String[] attrNames) 返回 ModelMBean 中几个属性的值。 |
protected ClassLoaderRepository |
getClassLoaderRepository() 返回用于执行类加载的 Class Loader Repository。 |
MBeanInfo |
getMBeanInfo() 返回此 RequiredModelMBean 公开的属性、操作、构造方法和通知是为了便于管理。 |
MBeanNotificationInfo[] |
getNotificationInfo() 返回总是由 RequiredModelMBean 生成的 Notification 数组。 |
Object |
invoke(String opName, Object[] opArgs, String[] sig) 调用 RequiredModelMBean 上的(或通过它调用)某个方法,并返回方法的执行结果。 |
void |
load() 使用在持久存储中找到的 MBean 的数据实例化此 MBean。 |
void |
postDeregister() 允许 MBean 在已从 MBean 服务器注销之后执行任何所需要的操作。 |
void |
postRegister(Boolean registrationDone) 允许 MBean 在已注册到 MBean 服务器之后或注册失败之后执行任何所需要的操作。 |
void |
preDeregister() 允许 MBean 在由 MBean 服务器注销之前执行任何所需要的操作。 |
ObjectName |
preRegister(MBeanServer server, ObjectName name) 允许 MBean 在注册到 MBean 服务器之前执行任何所需要的操作。 |
void |
removeAttributeChangeNotificationListener(NotificationListener inlistener, String inAttributeName) 从 RequiredModelMBean 移除一个 attributeChangeNotifications 的侦听器。 |
void |
removeNotificationListener(NotificationListener listener) 从 RequiredModelMBean 移除一个 Notification 的侦听器。 |
void |
removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) 从此 MBean 移除一个侦听器。 |
void |
sendAttributeChangeNotification(Attribute inOldVal, Attribute inNewVal) 将包含属性的原有值和新值的 attributeChangeNotification 发送到 ModelMBean 上已注册的 AttributeChangeNotification 侦听器。 |
void |
sendAttributeChangeNotification(AttributeChangeNotification ntfyObj) 将传入的 attributeChangeNotification 发送到 ModelMBean 上已注册的 attributeChangeNotification 侦听器。 |
void |
sendNotification(Notification ntfyObj) 以 jmx.modelmbean.generic 通知形式将传入的 Notification 发送到 ModelMBean 上已注册的 Notification 侦听器。 |
void |
sendNotification(String ntfyText) 将包含传入文本字符串的 Notification 发送到 ModelMBean 上已注册的 Notification 侦听器。 |
void |
setAttribute(Attribute attribute) 设置指定的 ModelMBean 的指定属性值。 |
AttributeList |
setAttributes(AttributeList attributes) 设置此 ModelMBean 的属性数组的值。 |
void |
setManagedResource(Object mr, String mr_type) 设置对象的实例句柄,我们将根据该句柄执行此 ModelMBean 管理接口(MBeanInfo 和 Descripto)中的所有方法。 |
void |
setModelMBeanInfo(ModelMBeanInfo mbi) 使用传入的 ModelMBeanInfo 实例化 ModelMBean 对象。 |
void |
store() 捕获此 MBean 实例的当前状态,并将它写出到持久存储中。 |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 构造方法详细信息 |
|---|
public RequiredModelMBean()
throws MBeanException,
RuntimeOperationsException
RequiredModelMBean。
可以使用 setModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) 方法来自定义 RequiredModelMBean 的 MBeanInfo 和 Descriptor。自定义 RequiredModelMBean 的 MBeanInfo 和 Descriptor 之后,可以在 MBeanServer 中注册 RequiredModelMBean。
MBeanException - 包装了一个分布式通信异常。
RuntimeOperationsException - 在对象的构造期间包装了一个
RuntimeException。
public RequiredModelMBean(ModelMBeanInfo mbi)
throws MBeanException,
RuntimeOperationsException
setModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) 方法自定义 RequiredModelMBean 的 MBeanInfo 和 Descriptor。自定义 RequiredModelMBean 的 MBeanInfo 和 Descriptor 之后,可以向 MBeanServer 注册 RequiredModelMBean。
mbi - RequiredModelMBean 要使用的 ModelMBeanInfo 对象。给定的 ModelMBeanInfo 根据
setModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) 指定的方式进行复制和修改
MBeanException - 包装了一个分布式通信异常。
RuntimeOperationsException - 包装了一个 {link java.lang.IllegalArgumentException}:传入参数中的 MBeanInfo 为 null。
| 方法详细信息 |
|---|
public void setModelMBeanInfo(ModelMBeanInfo mbi)
throws MBeanException,
RuntimeOperationsException
如果目前已经注册了 ModelMBean,则此方法抛出包装 IllegalStateException 的 RuntimeOperationsException
如果给定的 inModelMBeanInfo 不包含任何 GENERIC 或 ATTRIBUTE_CHANGE 通知的 ModelMBeanNotificationInfo,则 RequiredModelMBean 将为这些缺少的通知提供它自己的默认 ModelMBeanNotificationInfo。
ModelMBean 中的
setModelMBeanInfo
mbi - ModelMBean 要使用的 ModelMBeanInfo 对象。
MBeanException - 包装了一个分布式通信异常。
RuntimeOperationsException -
IllegalArgumentException。IllegalStateException。
public void setManagedResource(Object mr,
String mr_type)
throws MBeanException,
RuntimeOperationsException,
InstanceNotFoundException,
InvalidTargetObjectTypeException
ModelMBean 中的
setManagedResource
mr - 作为托管资源的对象
mr_type - 托管资源的引用类型。
MBeanException - 如果对象初始化程序已抛出异常。
InstanceNotFoundException - 如果找不到托管资源对象
InvalidTargetObjectTypeException - 托管资源对象应为 "ObjectReference"。
RuntimeOperationsException - 如果设置资源时包装一个
RuntimeException。
public void load()
throws MBeanException,
RuntimeOperationsException,
InstanceNotFoundException
使用在持久存储中找到的 MBean 的数据实例化此 MBean。加载的数据可以包括属性和操作值。
此方法的调用应在此实例的构造或实例化期间,且在向 MBeanServer 注册该 MBean 之前。
如果此类的实例不支持持久存储,则抛出包装 ServiceNotFoundException 的 MBeanException。
PersistentMBean 中的
load
MBeanException - 包装另一个异常,或者不支持持久存储
RuntimeOperationsException - 包装来自持久机制的异常
InstanceNotFoundException - 不能从持久存储找到或加载此 MBean
public void store()
throws MBeanException,
RuntimeOperationsException,
InstanceNotFoundException
捕获此 MBean 实例的当前状态,并将它写出到持久存储中。存储的状态可以包括属性和操作值。
如果此类的实例不支持持久存储,则抛出包装 ServiceNotFoundException 的 MBeanException。
来自 MBean 和属性描述符的持久策略用于指导此方法的执行。如果 'persistPolicy' 是以下值,则应存储 MBean:
!= "never" = "always" = "onTimer" and now > 'lastPersistTime' + 'persistPeriod' = "NoMoreOftenThan" and now > 'lastPersistTime' + 'persistPeriod' = "onUnregister"
如果 'persistPolicy' 字段是以下值,则不存储 MBean:
= "never"
= "onUpdate"
= "onTimer" && now < 'lastPersistTime' + 'persistPeriod'
PersistentMBean 中的
store
MBeanException - 包装另一个异常,或者如果不支持持久存储
RuntimeOperationsException - 包装来自持久机制的异常
InstanceNotFoundException - 不能找到/访问持久存储
public MBeanInfo getMBeanInfo()
DynamicMBean 中的
getMBeanInfo
public Object invoke(String opName,
Object[] opArgs,
String[] sig)
throws MBeanException,
ReflectionException
如果要调用的给定方法连同提供的签名与 RequiredModelMbean 可访问方法中的某个方法匹配,则将调用此匹配的方法。否则将在托管资源上尝试调用给定的方法。
该操作返回的最后一个值可以在该操作的描述符中进行缓存,此描述符位于 ModelMBeanOperationInfo 的描述符中。有效值将位于 'value' 字段中(如果有)。如果描述符中的 'currencyTimeLimit' 字段为:
注:由于与此规范以前版本不一致,因此对于 currencyTimeLimit,建议不要使用负值或零。要指示某个缓存的值永远无效,请忽略 currencyTimeLimit 字段。要指示它总是有效,请为此字段使用一个非常大的值。
DynamicMBean 中的
invoke
opName - 要调用的方法名称。此名称可以是包括类名称的完全限定方法名,如果类名称是在操作描述符的 'class' 字段中定义的,则此名称也可以仅为方法名称。
opArgs - 包含调用操作时要设置的参数的数组
sig - 包含操作签名的数组。用于加载类对象的类加载器与用于加载 MBean(要在其上调用操作)的类加载器相同。
MBeanException - 包装以下 Exceptions 之一:
ServiceNotFoundException: 为指定操作或托管资源定义的 ModelMBeanOperationInfo 或 descriptor 都不为 null。InvalidTargetObjectTypeException: 'targetType' 字段值不为 'objectReference'。ReflectionException - 包装一个试图调用该方法时抛出的
Exception。
RuntimeOperationsException - 包装一个
IllegalArgumentException。方法名称为 null。
public Object getAttribute(String attrName)
throws AttributeNotFoundException,
MBeanException,
ReflectionException
注:由于与此规范以前版本不一致,因此对于 currencyTimeLimit,建议不要使用负值或零。要指示某个缓存的值永远无效,请忽略 currencyTimeLimit 字段。要指示它总是有效,请为此字段使用一个非常大的值。
如果 'getMethod' 字段包含有效的操作描述符名称,则执行操作描述符所描述的方法。该方法的响应将作为属性值返回。如果操作失败或返回值的类型与属性声明的类型不兼容,则将抛出异常。
如果没有定义 'getMethod' 字段,则返回属性的默认值。如果返回值的类型与属性声明的类型不兼容,则将抛出异常。
属性声明的类型是 MBeanAttributeInfo.getType() 返回的 String。如果以下条件中有一个为真,则值与此类型兼容:
在此实现中,对于需要调用 getMethod 的每种情况,因为该方法是通过标准的 "invoke" 方法调用的并因此需要 operationInfo,所以必须为该 getMethod 指定一个操作,以便调用正确工作。
DynamicMBean 中的
getAttribute
attrName - 指定要检索的属性名称的 String。它必须与 ModelMBeanAttributeInfo 名称匹配。
AttributeNotFoundException - 如果指定的属性在 MBean 中不是可访问的。以下情况可能导致 AttributeNotFoundException:
MBeanException - 包装以下 Exception 之一:
InvalidAttributeValueException: 从属性的获取方法检索到一个错误值类型,或者描述符中未定义属性的 'getMethod' 字段且默认值不存在。ServiceNotFoundException: 没有为属性的获取方法定义 ModelMBeanOperationInfo,或者没有与 ModelMBeanOperationInfo 关联的描述符,或者托管资源为 null。InvalidTargetObjectTypeException 'targetType' 字段值不是 'objectReference'。ReflectionException - 包装试图调用设置方法时抛出的
Exception。
RuntimeOperationsException - 包装
IllegalArgumentException:参数中的属性名称为 null。
setAttribute(javax.management.Attribute)
public AttributeList getAttributes(String[] attrNames)
DynamicMBean 中的
getAttributes
attrNames - 要检索的属性名称的 String 数组。
RuntimeOperationsException - 包装一个
IllegalArgumentException:参数中的对象名称为 null,或参数中的属性为 null。
setAttributes(javax.management.AttributeList)
public void setAttribute(Attribute attribute)
throws AttributeNotFoundException,
InvalidAttributeValueException,
MBeanException,
ReflectionException
如果 currencyTimeLimit > 0,则在属性描述符的 'value' 字段中缓存属性的新值,并且 'lastUpdatedTimeStamp' 字段设置为当前时间戳。
如果属性描述符的 persist 字段不为 null,则来自属性描述符的 Persistence 策略用于指导在持久存储中存储属性。
如果 'persistPolicy' 字段是以下值,则存储 MBean:
Model MBean 的 ModelMBeanInfo 存储于文件中。
DynamicMBean 中的
setAttribute
attribute - 包含要设置的属性的名称和要设置的值的 Attribute 实例。
AttributeNotFoundException - 如果指定的属性在 MBean 中不是可访问的。
InvalidAttributeValueException - 如果没有为指定的属性定义描述符。
MBeanException - 包装以下 Exception 之一:
ServiceNotFoundException。注意,如果也没有定义任何 getMethod 字段,则将自动启用缓存。InvalidTargetObjectTypeException 'targetType' 字段值不是 'objectReference'。ReflectionException - 包装试图调用设置方法时抛出的
Exception。
RuntimeOperationsException - 包装一个
IllegalArgumentException:参数中的属性为 null。
getAttribute(java.lang.String)
public AttributeList setAttributes(AttributeList attributes)
DynamicMBean 中的
setAttributes
attributes - 属性列表:要设置的属性的标识和这些属性要设置的值。
RuntimeOperationsException - 包装一个
IllegalArgumentException:参数中的对象名称为 null,或参数中的属性为 null。
getAttributes(java.lang.String[])
public void addNotificationListener(NotificationListener listener,
NotificationFilter filter,
Object handback)
throws IllegalArgumentException
NotificationBroadcaster 中的
addNotificationListener
listener - 将处理由已注册的 MBean 发出的通知的侦听器对象。
filter - 过滤器对象。如果为 null,则在处理通知之前将不执行过滤。
handback - 当发出通知时,要发送到带有通知的侦听器的上下文。
IllegalArgumentException - 侦听器不可以为 null。
removeNotificationListener(javax.management.NotificationListener)
public void removeNotificationListener(NotificationListener listener)
throws ListenerNotFoundException
NotificationBroadcaster 中的
removeNotificationListener
listener - 正在处理由注册的 MBean 发出的通知的侦听器名称。此方法将移除与此侦听器相关的所有信息。
ListenerNotFoundException - 侦听器未在 MBean 中注册,或为 null。
addNotificationListener(javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object)
public void removeNotificationListener(NotificationListener listener,
NotificationFilter filter,
Object handback)
throws ListenerNotFoundException
NotificationEmitter 复制的描述
从此 MBean 移除一个侦听器。该 MBean 必须有一个与给定 listener、filter 和 handback 参数完全匹配的侦听器。如果有多个此类侦听器,则只移除一个侦听器。
当且仅当在要移除的侦听器中 filter 和 handback 参数为 null 时,这两个参数才可以为 null。
NotificationEmitter 中的
removeNotificationListener
listener - 以前添加到此 MBean 中的侦听器。
filter - 添加侦听器时指定的过滤器。
handback - 添加侦听器时指定的回送。
ListenerNotFoundException - 如果没有在该 MBean 中注册侦听器,或者没有用给定的过滤器和回送注册它。
public void sendNotification(Notification ntfyObj)
throws MBeanException,
RuntimeOperationsException
ModelMBeanNotificationBroadcaster 复制的描述
ModelMBeanNotificationBroadcaster 中的
sendNotification
ntfyObj - 要传递给侦听器对象的 'handleNotification' 方法的通知。
MBeanException - 包装一个分布式通信异常。
RuntimeOperationsException - 包装一个 IllegalArgumentException:传入参数中的 Notification 对象为 null。
public void sendNotification(String ntfyText)
throws MBeanException,
RuntimeOperationsException
ModelMBeanNotificationBroadcaster 复制的描述
ModelMBeanNotificationBroadcaster 中的
sendNotification
ntfyText - Notification 中要传递到侦听器对象的 'handleNotification' 方法的文本。 所构造的 Notification 将为: 类型 "jmx.modelmbean.generic" 源 此 ModelMBean 实例 序列 1
MBeanException - 包装一个分布式通信异常。
RuntimeOperationsException - 包装一个 IllegalArgumentException:传入参数中的 Notification 文本字符串为 null。
public MBeanNotificationInfo[] getNotificationInfo()
RequiredModelMBean 还可能总是发送两个其他通知:
"name=GENERIC,descriptorType=notification,log=T,severity=6,displayName=jmx.modelmbean.generic""name=ATTRIBUTE_CHANGE,descriptorType=notification,log=T,severity=6,displayName=jmx.attribute.change" 的标准属性更改通知
NotificationBroadcaster 中的
getNotificationInfo
public void addAttributeChangeNotificationListener(NotificationListener inlistener,
String inAttributeName,
Object inhandback)
throws MBeanException,
RuntimeOperationsException,
IllegalArgumentException
ModelMBeanNotificationBroadcaster 复制的描述
ModelMBeanNotificationBroadcaster 中的
addAttributeChangeNotificationListener
inlistener - 将处理由已注册的 MBean 发出的通知的侦听器对象。
inAttributeName - 要为其接收更改通知的 ModelMBean 属性名称。如果参数为 null,则所有更改将导致发布 attributeChangeNotification。
inhandback - 当发出通知时,要发送到带有通知的侦听器的上下文。
MBeanException - 包装一个分布式通信异常。
RuntimeOperationsException - 包装一个 IllegalArgumentException。传入参数中的属性名称不存在。
IllegalArgumentException - 侦听器不可以为 null。
ModelMBeanNotificationBroadcaster.removeAttributeChangeNotificationListener(javax.management.NotificationListener, java.lang.String)
public void removeAttributeChangeNotificationListener(NotificationListener inlistener,
String inAttributeName)
throws MBeanException,
RuntimeOperationsException,
ListenerNotFoundException
ModelMBeanNotificationBroadcaster 复制的描述
ModelMBeanNotificationBroadcaster 中的
removeAttributeChangeNotificationListener
inlistener - 正在处理由注册的 MBean 发出的通知的侦听器名称。此方法将移除与此侦听器相关的所有信息。
inAttributeName - 侦听器不再为其接收 attributeChangeNotifications 的属性。如果为 null,则将移除所有 attributeChangeNotifications 的侦听器。
MBeanException - 包装一个分布式通信异常。
RuntimeOperationsException - 包装一个 IllegalArgumentException 如果 inAttributeName 参数没有对应一个属性名称。
ListenerNotFoundException - 侦听器未在 MBean 中注册,或为 null。
ModelMBeanNotificationBroadcaster.addAttributeChangeNotificationListener(javax.management.NotificationListener, java.lang.String, java.lang.Object)
public void sendAttributeChangeNotification(AttributeChangeNotification ntfyObj)
throws MBeanException,
RuntimeOperationsException
ModelMBeanNotificationBroadcaster 复制的描述
ModelMBeanNotificationBroadcaster 中的
sendAttributeChangeNotification
ntfyObj - 要传递给侦听器对象的 'handleNotification' 方法的通知。
MBeanException - 包装一个分布式通信异常。
RuntimeOperationsException - 包装一个 IllegalArgumentException:传入参数中的 AttributeChangeNotification 对象为 null。
public void sendAttributeChangeNotification(Attribute inOldVal,
Attribute inNewVal)
throws MBeanException,
RuntimeOperationsException
ModelMBeanNotificationBroadcaster 复制的描述
ModelMBeanNotificationBroadcaster 中的
sendAttributeChangeNotification
inOldVal - 属性的原始值
inNewVal - 属性的当前值
所构造的 attributeChangeNotification 将为: 类型 "jmx.attribute.change" 源 此 ModelMBean 实例 序列 1 attributeName oldValue.getName() attributeType oldValue's class attributeOldValue oldValue.getValue() attributeNewValue newValue.getValue()
MBeanException - 包装一个分布式通信异常。
RuntimeOperationsException - 包装一个 IllegalArgumentException:传入参数中的 Attribute 对象为 null,或参数中两个 Attribute 对象的名称不同。
protected ClassLoaderRepository getClassLoaderRepository()
ClassLoaderRepository。
public ObjectName preRegister(MBeanServer server,
ObjectName name)
throws Exception
为确保 RequireModelMBean 的运行时语义正确,重新加载或重写此方法的任何 RequiredModelMBean 的子类都应在自己的 preRegister 实现中调用 super.preRegister(server, name)。
MBeanRegistration 中的
preRegister
server - 将在其中注册 MBean 的 MBean 服务器。
name - MBean 的对象名称。如果传递到
MBeanServer 接口中的
createMBean 或
registerMBean 方法的名称参数为 null,则此名称为 null。在这种情况下,此方法必须返回新 MBean 的非 null ObjectName。
name 参数不为 null,那么它通常(但并非必要)是返回的值。
Exception - 此异常由 MBean 服务器捕获,并以
MBeanRegistrationException 的形式重新抛出。
public void postRegister(Boolean registrationDone)
为确保 RequireModelMBean 的运行时语义正确,重新加载或重写此方法的任何 RequiredModelMBean 的子类都应在自己的 postRegister 实现中调用 super.postRegister(registrationDone)。
MBeanRegistration 中的
postRegister
registrationDone - 指示 MBean 是否已成功注册到 MBean 服务器中。值 false 意味着注册失败。
public void preDeregister()
throws Exception
为确保 RequireModelMBean 的运行时语义正确,重新加载或重写此方法的任何 RequiredModelMBean 的子类都应在自己的 preDeregister 实现中调用 super.preDeregister()。
MBeanRegistration 中的
preDeregister
Exception - 此异常由 MBean 服务器捕获,并以
MBeanRegistrationException 的形式重新抛出。
public void postDeregister()
为确保 RequireModelMBean 的运行时语义正确,重新加载或重写此方法的任何 RequiredModelMBean 的子类都应在自己的 postDeregister 实现中调用 super.postDeregister()。
MBeanRegistration 中的
postDeregister
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。