Java Reference
In-Depth Information
group of MBeans; the domain uniquely differentiates this
MBeanServer
from any
other. Each
MBeanServer
contains a supplied domain name, allowing you to
group MBeans in a meaningful way. If you invoke the factory
create()
method
again with an identical domain name parameter, it will simply return the previ-
ously created HelloAgent
MBeanServer
instance. (You will learn more about the
MBeanServer
class later in chapter 8. For now, keep in mind that an
MBeanServer
object acts as a registry, enabling storage, lookup, and manipulation of MBeans.)
The next step is to create some way for management applications to contact the
HelloAgent
. Recall that agents open themselves up to management applications
by constructing protocol adapters and connectors. Adapters and connectors are
a major reason why
JMX
is so powerful and versatile. These components are Java
objects that allow management applications to use a specific protocol to contact
JMX
agents. (You will learn more about them, and create more complex exam-
ples, as the topic continues.) This chapter only makes use of the
HTML
adapter;
to create the adapter, you just need to invoke its default constructor, as seen in
the
HelloAgent
class.
D
Registering and managing the MBean
Once the adapter has been created, you need to register it on the
MBeanServer
.
This brings up an interesting point about adapters (and connectors): they are
also MBeans. Thus the Java classes that make up the adapters and connectors
are written to conform to one of the MBean types defined by the
JMX
specifica-
tion. Because they are MBeans, they can be managed during runtime like other
MBeans. However, before you can register an MBean, you need to make sure you
can identify and find it again; this is where the
javax.management.ObjectName
class comes into play.
E
Uniquely identifying MBeans
So far, the agent has created the
MBeanServer
and registered an
HTML
adapter
with it. Now it is time to examine how the
MBeanServer
keeps track of objects reg-
istered with it. Look back at the code that registers the
HelloWorld
MBean
instance on the
MBeanServer
. When registering an MBean, you need to be able
to distinguish it from every other MBean that might be registered.
To do this, you must create an instance of the
javax.management.ObjectName
class. The
ObjectName
class is a
JMX
class that provides a naming system for
MBeans, allowing unique identification of MBeans registered in the MBean
server. Each
ObjectName
consists of two parts:
D