specifyServices(new Class[]{EventMailbox.class, JavaSpace.class});
logger.log(Level.INFO, "Getting EventMailbox reference");
EventMailbox mb = (EventMailbox)services[0];
logger.log(Level.INFO, "Getting JavaSpace reference");
JavaSpace space = (JavaSpace)services[1];
// Register and check lease
logger.log(Level.INFO, "Creating MailboxRegistration");
MailboxRegistration mr = getRegistration(mb, DURATION);
checkLease(getMailboxLease(mr), DURATION);
addLease(getMailboxLease(mr), false);
logger.log(Level.INFO, "Getting mailbox listener");
RemoteEventListener mbRel = getMailboxListener(mr);
logger.log(Level.INFO, "Getting our own listener");
TestListener listener = TestUtils.createListener(manager);
//Setup space to generate events
logger.log(Level.INFO, "Setting up space notifications");
EventRegistration er = space.notify(null, null, mbRel, DURATION, null);
checkLease(er.getLease(), DURATION);
addLease(er.getLease(), false);
logger.log(Level.INFO, "Generating some events");
for (i = 0; i < NUM_EVENTS; i++) {
addLease(space.write(new Name("Duh"), null, DURATION), false);
}
//Note: JavaSpaces is allowed to compact event notifications.
// That is, if more than one event is scheduled to be delivered
// for the same notification target, then the one with the latest
// sequence number can be sent (alone). Therefore, for
// NUM_EVENTS > 1, you'll need to add some sort of delay factor
// in order to prevent multiple notifications from beng queue'd
// up together on the space side of the house.
logger.log(Level.INFO, "Checking event count befor enabling");
int eventCount = 0;
assertCount(listener, eventCount);
logger.log(Level.INFO, "Enabling delivery");
mr.enableDelivery(listener);
eventCount += NUM_EVENTS;
logger.log(Level.INFO, "Waiting for event delivery");
waitForEvents(listener, eventCount, MAX_WAIT);
logger.log(Level.INFO, "Verifying event delivery");
assertCount(listener, eventCount);
logger.log(Level.INFO, "Generating some more events");
for (i = 0; i < NUM_EVENTS; i++) {
addLease(space.write(new Name("Yah"), null, DURATION), false);
}
eventCount += NUM_EVENTS;
logger.log(Level.INFO, "Waiting for event delivery");
waitForEvents(listener, eventCount, MAX_WAIT);
logger.log(Level.INFO, "Verifying event delivery");
assertCount(listener, eventCount);
shutdown(0); // Mailbox is at index 0;
logger.log(Level.INFO, "Generating some more events");
for (i = 0; i < NUM_EVENTS; i++) {
addLease(space.write(new Name("Yah"), null, DURATION), false);
}
eventCount += NUM_EVENTS;
logger.log(Level.INFO, "Waiting for event delivery");
waitForEvents(listener, eventCount, MAX_WAIT);