Java Reference
In-Depth Information
B
The
DynamicMBeanSupport
class provides an implementation for all the methods
from the
DynamicMBean
interface. Subclasses can override them, but these imple-
mentations should be good enough for most situations. The
getAttribute()
and
setAttribute()
methods use introspection (using the
java.lang.reflect
pack-
age) to get and set the value of class member variables. In addition, the
setAt-
tribute()
method invokes the
getType()
method to discover the type of a
member variable whether the requester has proper access to an attribute as
defined by the MBean's management interface. If it is an invalid request,
get-
Type()
returns
null
. The
invoke()
method does something similar in that it also
uses introspection to invoke operations of the class.
The four methods that make using this class advantageous are
addMBeanAt-
tribute()
,
addMBeanConstructor()
,
addMBeanOperation()
, and
buildDynamic-
MBeanInfo()
. The add methods allow subclasses to create their
MBeanInfo
object
by adding portions of it as needed. For instance, look in the constructor of the
class: it invokes the
addMBeanAttribute()
method in order to expose the
description
field of this MBean. Of course, it is not necessary to expose this
field, but doing so serves as a good example. The constructor also adds itself to
the
MBeanInfo
object. Finally, the
buildDynamicMBeanInfo()
method is called to
put everything together in an
MBeanInfo
instance as needed.
5.7 Summary
This chapter introduced you to a more complex type of MBean: the Dynamic
MBean. You learned that Dynamic MBeans are useful when managing evolving
resources or resources with unstable interfaces. In addition, you learned that
Dynamic MBeans generate their management interface at runtime using a stan-
dard set of
JMX
metadata classes. In addition to writing Dynamic MBeans, you
created a super class that can save you time and effort in future Dynamic MBean
development.
Chapter 6 covers the
JMX
notification model surrounding MBeans. That
chapter will teach you about using standard
JMX
notifications, creating your own
notifications, and receiving notifications from MBeans.