Java Reference
In-Depth Information
Not only that, the adapter gives you a quick method of dynamically creating and
registering additional MBeans. Essentially, the HTML adapter provides you a
simple management tool for working with MBeans. The HTML adapter returns a
protocol ( HTML ) that your web browser renders as a useable application. But
let's not get ahead of ourselves; first you need to create the simple JMX agent.
2.3.1
Writing the HelloAgent class
Listing 2.2 presents the HelloAgent class. Don't worry if you don't understand or
recognize what is going on in the listing; you will learn more about agents as the
topic progresses (part 3). For now, you need only a basic understanding of the
agent code. Boiled down to the simplest steps, listing 2.2 does the following:
Creates the MBean server and HTML adapter
1
Registers (and thus enables you to manage) the MBean
2
Uniquely identifies the MBean
3
Registers and starts the HTML adapter
4
Listing 2.2
HelloAgent.java
package jmxbook.ch2;
import javax.management.*;
import com.sun.jdmk.comm.*;
public class HelloAgent
{
private MBeanServer mbs = null;
public HelloAgent()
{
mbs = MBeanServerFactory.createMBeanServer( "HelloAgent" );
B
Creates
HTML
adapter
C
HtmlAdaptorServer adapter = new HtmlAdaptorServer();
HelloWorld hw = new HelloWorld();
Creates HelloWorld
MBean instance
ObjectName adapterName = null;
ObjectName helloWorldName = null;
D
Creates ObjectName
instance; registers
HelloWorld MBean
try
{
helloWorldName =
new ObjectName( "HelloAgent:name=helloWorld1" );
mbs.registerMBean( hw, helloWorldName );
E
adapterName =
new ObjectName( "HelloAgent:name=htmladapter,port=9092" );
Search WWH ::




Custom Search