[jboss-cvs] JBossAS SVN: r60896 - branches/JBoss_3_2_7_JBAS-4122/messaging/src/main/org/jboss/mq.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Feb 26 04:00:46 EST 2007
Author: galder.zamarreno at jboss.com
Date: 2007-02-26 04:00:46 -0500 (Mon, 26 Feb 2007)
New Revision: 60896
Modified:
branches/JBoss_3_2_7_JBAS-4122/messaging/src/main/org/jboss/mq/Connection.java
branches/JBoss_3_2_7_JBAS-4122/messaging/src/main/org/jboss/mq/SpyMessageConsumer.java
branches/JBoss_3_2_7_JBAS-4122/messaging/src/main/org/jboss/mq/SpySession.java
Log:
[JBAS-4122] bug fix ported
Modified: branches/JBoss_3_2_7_JBAS-4122/messaging/src/main/org/jboss/mq/Connection.java
===================================================================
--- branches/JBoss_3_2_7_JBAS-4122/messaging/src/main/org/jboss/mq/Connection.java 2007-02-25 22:20:47 UTC (rev 60895)
+++ branches/JBoss_3_2_7_JBAS-4122/messaging/src/main/org/jboss/mq/Connection.java 2007-02-26 09:00:46 UTC (rev 60896)
@@ -182,8 +182,14 @@
/** Last message ID returned */
private int lastMessageID;
- //the exceptionListener
+ /** the exceptionListener */
private ExceptionListener exceptionListener;
+
+ /** The exception listener lock */
+ private Object elLock = new Object();
+
+ /** The exception listener invocation thread */
+ private Thread elThread;
/** Used in message id generation */
private StringBuffer sb = new StringBuffer();
@@ -418,45 +424,46 @@
* Notification of a failure on this connection
*
* @param reason the reason for the failure
- * @param e the exception
+ * @param t the throwable
*/
- public void asynchFailure(String reason, Exception e)
+ public void asynchFailure(String reason, Throwable t)
{
if (trace)
- log.trace("Notified of failure reason=" + reason + " " + this, e);
+ log.trace("Notified of failure reason=" + reason + " " + this, t);
// Exceptions due to closing will be ignored.
if (closing)
return;
JMSException excep;
- if (e instanceof JMSException)
- excep = (JMSException) e;
+ if (t instanceof JMSException)
+ excep = (JMSException) t;
else
- excep = new SpyJMSException(reason, e);
+ excep = new SpyJMSException(reason, t);
- if (exceptionListener != null)
+ synchronized (elLock)
{
- synchronized (exceptionListener)
+ ExceptionListener el = exceptionListener;
+ if (el != null && elThread == null)
{
- if (exceptionListener != null)
+ try
{
- try
- {
- exceptionListener.onException(excep);
- }
- catch (Throwable t)
- {
- log.warn("Connection failure: ", excep);
- log.warn("Exception listener ended abnormally: ", t);
- }
+ Runnable run = new ExceptionListenerRunnable(el, excep);
+ elThread = new Thread(getThreadGroup(), run, "ExceptionListener " + this);
+ elThread.setDaemon(false);
+ elThread.start();
}
- else
+ catch (Throwable t1)
+ {
log.warn("Connection failure: ", excep);
+ log.warn("Unable to start exception listener thread: ", t1);
+ }
}
- }
- else
- log.warn("Connection failure: ", excep);
+ else if (elThread != null)
+ log.warn("Connection failure, already in the exception listener", excep);
+ else
+ log.warn("Connection failure, use javax.jms.Connection.setExceptionListener() to handle this error and reconnect", excep);
+ }
}
/**
@@ -1394,4 +1401,46 @@
}
}
}
+
+ /**
+ * The Exception listener runnable
+ */
+ class ExceptionListenerRunnable implements Runnable
+ {
+ ExceptionListener el;
+ JMSException excep;
+
+ /**
+ * Create a new ExceptionListener runnable
+ *
+ * @param el the exception exception
+ * @param excep the jms exception
+ */
+ public ExceptionListenerRunnable(ExceptionListener el, JMSException excep)
+ {
+ this.el = el;
+ this.excep = excep;
+ }
+
+ public void run()
+ {
+ try
+ {
+ synchronized (el)
+ {
+ el.onException(excep);
+ }
+ }
+ catch (Throwable t)
+ {
+ log.warn("Connection failure: ", excep);
+ log.warn("Exception listener ended abnormally: ", t);
+ }
+
+ synchronized (elLock)
+ {
+ elThread = null;
+ }
+ }
+ }
}
Modified: branches/JBoss_3_2_7_JBAS-4122/messaging/src/main/org/jboss/mq/SpyMessageConsumer.java
===================================================================
--- branches/JBoss_3_2_7_JBAS-4122/messaging/src/main/org/jboss/mq/SpyMessageConsumer.java 2007-02-25 22:20:47 UTC (rev 60895)
+++ branches/JBoss_3_2_7_JBAS-4122/messaging/src/main/org/jboss/mq/SpyMessageConsumer.java 2007-02-26 09:00:46 UTC (rev 60896)
@@ -732,9 +732,9 @@
}
}
}
- catch (JMSException e)
+ catch (Throwable t)
{
- log.warn("Message consumer closing due to error in listening thread.", e);
+ log.warn("Message consumer closing due to error in listening thread.", t);
try
{
close();
@@ -742,6 +742,7 @@
catch (Exception ignore)
{
}
+ session.asynchFailure("Message consumer closing due to error in listening thread.", t);
}
}
Modified: branches/JBoss_3_2_7_JBAS-4122/messaging/src/main/org/jboss/mq/SpySession.java
===================================================================
--- branches/JBoss_3_2_7_JBAS-4122/messaging/src/main/org/jboss/mq/SpySession.java 2007-02-25 22:20:47 UTC (rev 60895)
+++ branches/JBoss_3_2_7_JBAS-4122/messaging/src/main/org/jboss/mq/SpySession.java 2007-02-26 09:00:46 UTC (rev 60896)
@@ -1136,6 +1136,17 @@
// Private -------------------------------------------------------
/**
+ * Invoked to notify of asynchronous failure
+ *
+ * @param message the message
+ * @param t the throwable
+ */
+ void asynchFailure(String message, Throwable t)
+ {
+ connection.asynchFailure(message, t);
+ }
+
+ /**
* Rollback a transaction
*
* @throws JMSException for any error
More information about the jboss-cvs-commits
mailing list