Java Reference
In-Depth Information
private MBeanServer server = null;
Create MBean
server
public JMXBookAgent()
{
System.out.println("\n\tCREATE the MBeanServer.");
server = MBeanServerFactory.createMBeanServer("JMXBookAgent");
Add agent
connectivity
startHTMLAdapter();
startRMIConnector();
}
}
At this point, you need to import only two packages for the agent: javax.manage-
ment.* and com.sun.jdmk.comm.* (later in the topic, you will add more packages
as necessary). The latter package includes the classes for the HTML adapter and
the RMI connector.
The constructor must initialize its MBean server. It does so using the
domain name JMXBookAgent . In addition, the constructor invokes two meth-
ods: one starts the HTML adapter, and the other starts the RMI connector.
The next two sections discuss the implementation of the connectivity invoked
by the constructor.
3.2.2
Adding agent connectivity
To make your agent more useful, you'll add an adapter and connector that allow
you to interact with the agent visually and programmatically. You need the HTML
adapter in order to perform tasks similar to those in chapter 2: it is a quick way to
view the contents of the agent (its MBeans). If you used the HTML adapter exclu-
sively, you would not be able to register and receive MBean notifications.
However, in order to work with notifications (and for later examples), you
need to interact with the agent programmatically. To do so, you will add the RMI
connector to the agent. It will let you connect to the agent using an RMI client
and directly through program code.
The next two sections walk you through adding the connectivity to the agent.
Adding the HTML adapter
You saw the code for adding the HTML adapter in chapter 2. In this chapter, this
code is broken out into its own method called startHTMLAdapter() . Listing 3.2
shows the method implementation.
Search WWH ::




Custom Search