boolean succeeded = false; // attempt this task again?
boolean deleteEvent = false; // delete the retrieved event?
boolean doNotify = true; // attempt notification?
ServiceRegistration reg = null; //
RemoteEventListener listener = null; // event delivery target
RemoteEvent ev = null; // event to deliver
if (deliveryLogger.isLoggable(Level.FINEST)) {
deliveryLogger.log(Level.FINEST,
"Attempting event delivery for: {0} at {1}",
new Object[] {
regID,
new java.util.Date(System.currentTimeMillis())
});
}
// Put an upper time limit on how long to keep
// this task on the active list. This prevents
// slow/bad event recipients from monopolizing
// a thread in the thread pool. This will not
// prevent a "malicious" event recipient from
// hanging up this thread if it never returns
// from the notify() call.
long curTime = System.currentTimeMillis();
if (curTime - startTime() > MAX_TIME) {
succeeded = true;
deleteEvent = false;
doNotify = false;
if (deliveryLogger.isLoggable(Level.FINEST)) {
deliveryLogger.log(Level.FINEST,
"Cancelling delivery due to time limit expiration.");
}
} else {
// Get required delivery information
concurrentObj.readLock();
try {
try {
// Note: the following method will throw a
// ThrowThis exception if the registration
// is invalid (i.e. expired or non-existent)
reg = getServiceRegistration(regID);
listener = reg.getEventTarget();
ev = getNextEvent(reg);
// Check to see if either the listener or the event
// is null. If so, skip the notify() call.
// If the event is not null, make an
// additional check to see if the event is on the
// unknown event list for this registration.
// If so, then skip the notify() call as well.
if (listener == null) {
succeeded = true; // don't try again
deleteEvent = false; // don't delete event
doNotify = false; // skip notify
if (deliveryLogger.isLoggable(Level.FINEST)) {
deliveryLogger.log(Level.FINEST,
"Cancelling delivery because of disabled listener");
}
} else if (ev == null) {
succeeded = true; // don't try again
// Note that if getNextEvent returned null
// then there was a problem reading or extracting
// the event. If so, the EventLog mechanism
// wil have already advanced past the offending
// event, so we don't have to remove it.
deleteEvent = false;
doNotify = false; // skip notify
if (deliveryLogger.isLoggable(Level.FINEST)) {
deliveryLogger.log(Level.FINEST,
"Cancelling delivery because of null event");
}
} else if (ev != null &&
reg.getUnknownEvents().containsKey(
new EventID(ev))) {
// If this event type caused an
// UnknownEventException in the past, then
// delete it since it likely do so again.
succeeded = true; // don't try again
deleteEvent = true; // delete event
doNotify = false; // skip notify
if (deliveryLogger.isLoggable(Level.FINEST)) {
deliveryLogger.log(Level.FINEST,
"Cancelling delivery because of unknown event");
}
}
} catch (ThrowThis tt) { // reg was not valid ... skip it
succeeded = true; // don't try again
deleteEvent = false; // don't remove event
doNotify = false; // skip notify
if (deliveryLogger.isLoggable(Level.FINEST)) {
deliveryLogger.log(Level.FINEST,
"Cancelling delivery because of unknown registration");
}
}
} finally {
concurrentObj.readUnlock();
}
} // end else
// Important - don't hold any locks during a remote invocation
if (doNotify) {
if (deliveryLogger.isLoggable(Level.FINEST)) {
deliveryLogger.log(Level.FINEST,
"Delivering evt: {0}, ID {1}, Seq# {2}",
new Object[] {ev, new Long(ev.getID()),
new Long(ev.getSequenceNumber())});
}
try {
// Notify target listener and note a successful delivery
listener.notify(ev);
succeeded = true;