final NotificationEmitterService nes = getNotificationEmitterService();
final NotificationBuilder builder =
new NotificationBuilder( testEmitListener.TEST_TYPE, TEST_SOURCE );
final testEmitListener listener = new testEmitListener();
nes.addNotificationListener( listener, null, null);
final Notification notif = builder.buildNew( TEST_MESSAGE);
builder.putMapData( notif, TEST_KEY, TEST_VALUE );
// call emitNotification() and verify it was emitted
nes.emitNotification( notif );
while( listener.getLast() == null )
{
// wait...
mySleep( 20 );
}
final Notification retrieved = listener.getLast();
assert( retrieved.getType().equals( notif.getType() ) );
assert( Util.getAMXNotificationValue( retrieved, TEST_KEY, String.class).equals( TEST_VALUE ) );
assert( retrieved.getSource().equals( TEST_SOURCE ) );
assert( retrieved.getMessage().equals( TEST_MESSAGE ) );
// now emit many Notifications.
listener.clear();
long start = now();
final int ITER = 200;
for( int i = 0; i < ITER; ++i)
{
final Notification temp = builder.buildNew( TEST_MESSAGE);
builder.putMapData( notif, TEST_KEY, TEST_VALUE );
nes.emitNotification( temp );
}
printElapsedIter( "Emitted Notifications", start, ITER );
start = now();
while( listener.getNumHeard() < ITER )
{
mySleep( 10 );
}
printElapsedIter( "After sending, received emitted Notifications", start, ITER );