Java Reference
In-Depth Information
Getting attribute values
In order to get an attribute's value, you need to know the name of the attribute.
This attribute name is provided in the
MBeanInfo
object returned from the
get
M-
BeanInfo()
method. In the
getAttribute()
method, you pass a single attribute
name. In the
getAttributes()
method, you pass an array of attribute names.
The
getAttribute()
method returns a value of type
Object
in order to gener-
ically encapsulate the actual value of the exposed attribute. The other method,
getAttributes()
, returns an instance of the
AttributeList
class. The
Attribute-
List
class is a subclass of
java.util.ArrayList
and is a collection of
Attribute
objects. Each
Attribute
object encapsulates an attribute name and its value, and
provides support for an
equals()
method. Both
AttributeList
and
Attribute
are in the
javax.management
package.
Setting attribute values
The
setAttribute()
method accepts a single
Attribute
object as an argument. It
attempts to set the value of the MBean attribute with the name returned by the
getName()
method from its
Attribute
argument. The
setAttributes()
method
acts exactly like
setAttribute()
, but it operates over an
AttributeList
argument.
For all four methods, if an invalid attribute name is specified, an
Attribute-
NotFoundException
exception should be thrown. For the set methods, if an
invalid attribute value is specified, an
InvalidAttributeValueException
excep-
tion should be thrown. We say “should” because this is only an interface—the
actual implementation depends on the developer.
Before moving on, let's summarize some of the information presented in
the last two sections. Table 5.1 provides a summary of setting and getting attrib-
ute values.
Table 5.1 Summary of information concerning setting and getting attribute values of
a Dynamic MBean
Dynamic MBean method
Return value
Incoming arguments
String
attribute name
getAttribute()
Object
String[]
of attribute names
getAttributes()
AttributeList
setAttribute()
void
Attribute
setAttributes()
AttributeList
AttributeList
Now, let's move on and discuss how Dynamic MBeans expose operations.