Java Reference
In-Depth Information
Listing 6.3
PollingSetup.java
package jmxbook.ch6;
import javax.management.*;
import com.sun.jdmk.comm.*;
import jmxbook.ch3.*;
public class PollingSetup implements NotificationListener
{
public PollingSetup()
{
try
{
RmiConnectorClient client = RMIClientFactory.getClient();
ObjectName pollingName = new
ObjectName( "JMXBookAgent:name=polling");
client.createMBean( "jmxbook.ch6.Polling", pollingName );
client.addNotificationListener( pollingName, this,
null, null );
}
catch( Exception e )
{
ExceptionUtil.printException( e );
}
}
public void handleNotification( Notification not, Object obj )
{
String type = not.getType();
System.out.println( type );
}
public static void main( String args[] )
{
PollingSetup setup = new PollingSetup ();
}
}
This setup class follows the format of the ones you created previously. However,
in this case, after creating the MBean, it adds itself as a listener to receive any
notifications the MBean emits.
Before running the setup class, you need to make sure you have an instance of
the JMXBookAgent running. Use the following command to do so:
javac jmxbook.ch3.JMXBookAgent
After the agent successfully starts, execute the PollingSetup class to create your
Polling MBean. Next, open your browser to http://localhost:9092, and you will
Search WWH ::




Custom Search