XmlBlasterException xmlBlasterException = msgErrorInfo.getXmlBlasterException();
ErrorCode errorCode = xmlBlasterException.getErrorCode();
message = xmlBlasterException.getMessage();
MsgQueueEntry[] msgQueueEntries = msgErrorInfo.getMsgQueueEntries();
DispatchManager dispatchManager = (this.sessionInfo == null) ? null : this.sessionInfo.getDispatchManager();
I_Queue msgQueue = msgErrorInfo.getQueue(); // is null if entry is not yet in queue
if (log.isLoggable(Level.FINER)) log.finer("Error handling started: " + msgErrorInfo.toString());
if (msgQueueEntries != null && msgQueueEntries.length > 0) {
// 1. Generate dead letters from passed messages
glob.getRequestBroker().deadMessage(msgQueueEntries, msgQueue, message);
if (msgQueue != null) {
// Remove the above published dead message from the queue
try {
if (log.isLoggable(Level.FINE)) log.fine("Removing " + msgQueueEntries.length + " dead messages from queue");
long removed = 0L;
boolean tmp[] = msgQueue.removeRandom(msgQueueEntries);
for (int i=0; i < tmp.length; i++) if (tmp[i]) removed++;
if (removed != msgQueueEntries.length) {
log.warning("Expected to remove " + msgQueueEntries.length + " messages from queue but where only " + removed + ": " + message);
}
}
catch (XmlBlasterException e) {
log.warning("Can't remove " + msgQueueEntries.length + " messages from queue: " + e.getMessage() + ". Original cause was: " + message);
}
}
}
if (xmlBlasterException.isUser()) {
// The update() method from the client has thrown a ErrorCode.USER* error
if (log.isLoggable(Level.FINE)) log.fine("Error handlig for exception " + errorCode.toString() + " done");
return;
}
// 2a. Generate dead letters if there are some entries in the queue
size = (msgQueue == null) ? 0 : msgQueue.getNumOfEntries();
if (log.isLoggable(Level.FINE)) log.fine("Flushing " + size + " remaining message from queue");
if (size > 0) {
try {
QueuePropertyBase queueProperty = (QueuePropertyBase)msgQueue.getProperties();
if (queueProperty == null || queueProperty.onFailureDeadMessage()) {
while (msgQueue.getNumOfEntries() > 0L) {
List<I_Entry> list = msgQueue.peek(-1, MAX_BYTES);
MsgQueueEntry[] msgArr = (MsgQueueEntry[])list.toArray(new MsgQueueEntry[list.size()]);
if (msgArr.length > 0) {
glob.getRequestBroker().deadMessage(msgArr, (I_Queue)null, message);
}
if (msgArr.length > 0) {
msgQueue.removeRandom(msgArr);
}
}
}
else {
log.severe("PANIC: Only onFailure='" + Constants.ONOVERFLOW_DEADMESSAGE +
"' is implemented, " + msgQueue.getNumOfEntries() + " messages are lost: " + message);
}
}
catch(Throwable e) {
e.printStackTrace();
log.severe("PANIC: givingUpDelivery failed, " + size +
" messages are lost: " + message + ": " + e.toString());
}
}
// 2b. Generate dead letters if there is a raw message which we could not parse
if (msgErrorInfo.getMsgUnitRaw() != null) {
MsgUnitRaw msgUnitRaw = msgErrorInfo.getMsgUnitRaw();
glob.getRequestBroker().publishDeadMessageRaw(msgErrorInfo.getSessionName(), msgUnitRaw, message, null);
}
// We do a auto logout if the callback is down
if (dispatchManager == null || dispatchManager.isDead()) {
if (log.isLoggable(Level.FINE)) log.fine("Doing error handling for dead connection state ...");
if (dispatchManager!=null) dispatchManager.shutdown();
// 3. Kill login session
if (this.sessionInfo != null && // if callback has been configured (async)
sessionInfo.getConnectQos().getSessionCbQueueProperty().getCallbackAddresses().length > 0) {
log.warning("Callback server is lost, killing login session of client " +
((msgQueue == null) ? "unknown" : msgQueue.getStorageId().toString()) +
": " + message);
try {
DisconnectQos disconnectQos = new DisconnectQos(glob);
disconnectQos.deleteSubjectQueue(false);
glob.getAuthenticate().disconnect(this.sessionInfo.getAddressServer(),