Java Reference
In-Depth Information
Listing 3.7
HelloWorldSetup.java
package jmxbook.ch3;
import javax.management.*;
import jmxbook.ch2.*;
import com.sun.jdmk.comm.*;
public class HelloWorldSetup
{
public HelloWorldSetup()
{
try
{
RmiConnectorClient client = RMIClientFactory.getClient();
ObjectName hwName = new
ObjectName( "JMXBookAgent:name=helloWorld");
client.createMBean( "jmxbook.ch2.HelloWorld",
hwName );
client.invoke( hwName, "printGreeting", null, null );
}
catch( Exception e )
{
e.printStackTrace();
}
}
public static void main( String args[] )
{
HelloWorldSetup setup = new HelloWorldSetup ();
}
}
Just a reminder: don't worry about the particulars of the
RMI
client right now.
Keep in mind that it lets you invoke the methods of the MBean server contained
in the
JMX
agent. For instance, in the setup class, you invoke the
createMBean()
and
invoke()
methods. Both of these methods correspond directly to methods in
the
MBeanServer
API
.
Because the agent is already running, compile and run the setup class. You
should see the following output:
TYPE = SUN RMI
PORT = 2099
HOST = t8100x0232
SERVER = name=RmiConnectorServer
Looking at the agent output, you should see an additional line:
Hello World! I am a Standard MBean.