*/
public final long forwardToSessionQueue() {
if (getSessions().length < 1 || this.subjectQueue.getNumOfEntries() < 1) return 0;
long numMsgs = 0;
MsgQueueUpdateEntry entry = null;
if (log.isLoggable(Level.FINE)) log.fine(ME+": Trying to forward " + this.subjectQueue.getNumOfEntries() + " messages in subject queue to session queue ...");
while (true) {
try {
try {
entry = (MsgQueueUpdateEntry)this.subjectQueue.peek(); // non-blocking
}
catch (Throwable ex) {
log.severe(ME+": Can't get entry from subject queue when trying to forward it to session queue " + ex.getMessage());
// TODO toDead from the subject may be necessary to avoid looping
break;
}
if (entry == null)
break;
if (entry.isDestroyed()) {
log.info(ME+": Message " + entry.getLogId() + " is destroyed, ignoring it");
this.subjectQueue.removeRandom(entry); // Remove the destroyed entry
}
else {
int countForwarded = forwardToSessionQueue(entry);
if (countForwarded > 0) {
this.subjectQueue.removeRandom(entry); // Remove the forwarded entry (blocking)
numMsgs++;
}
else if (countForwarded == -1) { // There are sessions but they don't want PtP
break;
}
}
}
catch(Throwable e) {
MsgQueueEntry[] msgQueueEntries = new MsgQueueEntry[] { entry };
MsgErrorInfo msgErrorInfo = new MsgErrorInfo(glob, msgQueueEntries, null, e); // this.subjectQueue
getMsgErrorHandler().handleError(msgErrorInfo);
try {
this.subjectQueue.removeRandom(entry); // Remove the entry
}
catch (XmlBlasterException ex) {
log.severe(ME+": Can't empty queue when removing '" + entry.getLogId() + "' " + ex.getMessage());
// TODO toDead from the subject may be necessary to avoid looping
break;
}
}
}