Java Reference
In-Depth Information
8.2.4
MBean manipulation
The following sections describe the methods declared to manipulate MBeans.
They include methods to get and set attributes, invoke MBean operations, and
gather other MBean information. The methods available to manipulate MBeans
produce the same results regardless of MBean type. All MBeans are described
with MBean metadata objects internally in the MBean; therefore, the MBean
type is not important when performing these methods. (For more information
about MBean metadata objects, look back to chapter 4.)
The Object getAttribute( ObjectName name, String attribute ) method
This method returns the value of the attribute with the name supplied in the
String parameter from the MBean corresponding to the supplied MBean. The
ObjectName must refer to a registered MBean, and the String value must be a
readable attribute of that MBean. The value is returned as an instance of the
Object class. In addition to some of the exceptions you have already seen ( MBean-
Exception , InstanceNotFoundException , ReflectionException , and RuntimeOpera-
tionsException ), this method throws the AttributeNotFoundException exception.
This exception indicates that the requested attribute could not be found on the
given MBean.
The AttributeList getAttributes( ObjectName name,
String[] attributes ) method
The getAttributes() method performs the same function as the previous
method, but operates over an array of attribute names (the String array param-
eter). The ObjectName must refer to a registered MBean, and the String values
must be readable attributes of that MBean. The return value of this method is an
instance of AttributeList . (The AttributeList class was covered in detail in
chapter 4.) It contains a set of Attribute objects, each of which contains the
name and value of an attribute.
In contrast to the getAttribute() method, this method throws only three
exceptions: InstanceNotFoundException , ReflectionException , and RuntimeOp-
erationsException .
The void setAttribute( ObjectName name, Attribute attribute ) method
The setAttribute() method takes an ObjectName parameter and an Attribute
parameter. The ObjectName corresponds to a registered MBean. The Attribute
object must contain the name of a writeable MBean attribute and the value to
which to set the attribute.
Search WWH ::




Custom Search