public void handleConnectionException(Throwable throwable, Client client)
{
// forward the exception to delegate listeners and JMS ExceptionListeners; synchronize and
// copy to avoid race conditions
ExceptionListener jmsExceptionListenerCopy;
List delegateListenersCopy = new ArrayList();
synchronized(this)
{
jmsExceptionListenerCopy = jmsExceptionListener;
for(Iterator i = delegateListeners.iterator(); i.hasNext(); )
{
delegateListenersCopy.add(i.next());
}
}
for(Iterator i = delegateListenersCopy.iterator(); i.hasNext(); )
{
ConnectionListener l = (ConnectionListener)i.next();
try
{
log.debug(this + " forwarding remoting failure \"" + throwable + "\" to " + l);
l.handleConnectionException(throwable, client);
}
catch(Exception e)
{
log.warn("Failed to forward " + throwable + " to " + l, e);
}
}
if (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);
}
}