Returns an arbitrarily selected mail deposited in this Repository that
is either ready immediately for delivery, or is younger than it's last_updated plus
the number of failed attempts times the delay time.
Usage: RemoteDeliverySpool calls accept() with some delay and should block until an
unprocessed mail is available.
Synchronized to ensure thread safe access to the underlying spool.
if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) {
getLogger().debug("Method accept(delay) called");
}
return accept(new SpoolRepository.AcceptFilter () {
long youngest = 0;
public boolean accept (String key, String state, long lastUpdated, String errorMessage) {
if (state.equals(Mail.ERROR)) {
//Test the time...
long timeToProcess = delay + lastUpdated;
if (System.currentTimeMillis() > timeToProcess) {
//We're ready to process this again
return true;
} else {
//We're not ready to process this.
if (youngest == 0 || youngest > timeToProcess) {
//Mark this as the next most likely possible mail to process
youngest = timeToProcess;
}
return false;
}
} else {
//This mail is good to go... return the key
return true;
}
}
public long getWaitTime () {
if (youngest == 0) {
return 0;
} else {
long duration = youngest - System.currentTimeMillis();
youngest = 0; //get ready for next round
return duration <= 0 ? 1 : duration;
}
}
});