Java Reference
In-Depth Information
Listing 10.4
MLetWrapperSetup.java
package jmxbook.ch10;
import javax.management.*;
import com.sun.jdmk.comm.*;
import jmxbook.ch3.*;
public class MLetWrapperSetup implements NotificationListener
{
public MLetWrapperSetup()
{
try
{
RmiConnectorClient client = RMIClientFactory.getClient();
Object[] args = { "JMXBookAgent:name=mlet" };
String[] sig = { "java.lang.String" };
ObjectName wrapperName =
new ObjectName( "JMXBookAgent:name=mletwrapper");
client.createMBean( "jmxbook.ch10.MLetWrapper",
wrapperName, args, sig );
client.addNotificationListener( wrapperName, 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[] )
{
MLetWrapperSetup setup = new MLetWrapperSetup();
}
}
You can add more code to the handleNotification() method to output more
information about the received notifications if desired. For now, the method only
prints out each notification type. After compiling this class, start the JMXBook-
Agent and execute the setup class with the following command:
java jmxbook.ch10.MLetWrapperSetup
Search WWH ::




Custom Search