Java Reference
In-Depth Information
2.3 Creating a JMX agent
Now that you have your first MBean, you need to make it available for use. To do
so, you must register it in a
JMX
agent. Therefore, you need to create the
Hello-
Agent
class, which is a simple
JMX
agent.
As described in chapter 1,
JMX
agents are
JMX
components in the agent layer
of
JMX
and are the containers for MBeans. Part 3 of the topic covers
JMX
agents
in detail.
The
HelloAgent
class performs three important tasks:
■
It creates an
MBeanServer
instance to contain MBeans.
■
It creates an
HTML
adapter to handle connections from
HTML
clients.
■
It registers a new instance of the
HelloWorld
MBean.
As you are about to see, the
HelloAgent
class is probably the simplest agent you will
ever write, but it is still quite powerful. This fact again highlights one of the bene-
fits of using
JMX
: it is simple and yet useful. In a matter of moments, you have
developed the
HelloWorld
MBean. You can now easily manage this MBean by writ-
ing a simple agent that uses the
HTML
adapter provided by Sun Microsystems.
Using any web browser, the adapter allows you to interact with the agent to view
all registered MBeans and their attributes. Figure 2.3 depicts this interaction.
Specifically, the adapter lets you:
■
View the
readable
MBean attributes
■
Update the
writable
attributes
■
Invoke the other remaining methods
Figure 2.3
Using a Web browser to contact the HTML adapter present in the MBean server