}
// forward the exception to delegate listener and JMS ExceptionListeners; synchronize
// to avoid race conditions
ExceptionListener jmsExceptionListenerCopy;
ConnectionFailureListener remotingListenerCopy;
synchronized(this)
{
jmsExceptionListenerCopy = jmsExceptionListener;
remotingListenerCopy = remotingListener;
}
boolean forwardToJMSListener = true;
if (remotingListenerCopy != null)
{
try
{
log.trace(this + " forwarding remoting failure \"" + throwable + "\" to " + remotingListenerCopy);
//We only forward to the JMS listener if failover did not successfully handle the exception
//If failover handled the exception transparently then there is effectively no problem
//with the logical connection that the client needs to be aware of
forwardToJMSListener = !remotingListenerCopy.handleConnectionException(throwable, client);
}
catch(Exception e)
{
log.warn("Failed to forward " + throwable + " to " + remotingListenerCopy, e);
}
}
if (forwardToJMSListener && jmsExceptionListenerCopy != null)
{
JMSException jmsException = null;
if (throwable instanceof Error)
{
final String msg = "Caught Error on underlying remoting connection";
log.error(this + ": " + msg, throwable);
jmsException = new JMSException(msg + ": " + throwable.getMessage());
}
else if (throwable instanceof Exception)
{
Exception e = (Exception)throwable;
jmsException = new JMSException("Failure on underlying remoting connection");
jmsException.setLinkedException(e);
}
else
{
// Some other Throwable subclass
final String msg = "Caught Throwable on underlying remoting connection";
log.error(this + ": " + msg, throwable);
jmsException = new JMSException(msg + ": " + throwable.getMessage());
}
jmsExceptionListenerCopy.onException(jmsException);
}
}