Java Reference
In-Depth Information
Object[] args2 = { "ch12.timer.periodic", "message", "data",
new Date(), new Long( 6000 ) };
String[] sig2 = { "java.lang.String", "java.lang.String",
"java.lang.Object", "java.util.Date", "long" };
client.invoke( timerName, "addNotification", args2, sig2 );
Object[] args3 = { "ch12.timer.periodic20", "message", "data",
new Date(), new Long( 2000 ), new Long( 20 ) };
String[] sig3 = { "java.lang.String", "java.lang.String",
"java.lang.Object", "java.util.Date",
"long", "long" };
client.invoke( timerName, "addNotification", args3, sig3 );
client.addNotificationListener( timerName, 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[] )
{
TimerSetup setup = new TimerSetup();
}
}
You use two of the three overloaded addNotification() methods to add a notifi-
cation. You add a repeating notification to be sent every six seconds and a
repeating notification to be sent every two seconds with 20 occurrences. The
notification types are ch12.timer.periodic and ch12.timer.periodic20. All noti-
fications are added with the current date as their sending date.
12.5.1
Testing the timer service
After running the new JMXBookAgent and the TimerSetup class, you should expect
something like the following for output:
ch12.timer.periodic20
ch12.timer.periodic
ch12.timer.periodic20
Search WWH ::




Custom Search