Java Reference
In-Depth Information
{
private MBeanServer mbs = null;
public HelloAgent ( )
{
mbs = MBeanServerFactory.createMBeanServer( "HelloAgent" );
HtmlAdaptorServer adapter = new HtmlAdaptorServer();
HelloWorld hw = new HelloWorld();
ObjectName adapterName = null;
ObjectName helloWorldName = null;
try
{
adapterName = new ObjectName(
"HelloAgent:name=htmladapter,port=9092" );
mbs.registerMBean( adapter, adapterName );
adapter.setPort( 9092 )
adapter.start();
helloWorldName = new ObjectName(
"HelloAgent:name=helloWorld1" );
mbs.registerMBean( hw, helloWorldName );
hw.addNotificationListener( this, null, null );
}
catch( Exception e )
{
e.printStackTrace();
}
}//constructor
public void handleNotification(
Notification notif, Object handback )
{
System.out.println( "Receiving notification..." );
System.out.println( notif.getType() );
System.out.println( notif.getMessage() );
}
public static void main( String args[] )
{
HelloAgent agent = new HelloAgent();
}
}//class
C
Register to
receive
notifications
D
Implemented
from listener
interface
B
The first addition to the agent is the inclusion of the NotificationListener
interface. Recall that this interface declares a single method, handleNotifica-
tion() , which will be called when a notification is being delivered from a source
the listener has registered with.
Search WWH ::




Custom Search