From 1a7251a4ec94b154678a6b832bb71271cc085432 Mon Sep 17 00:00:00 2001 From: Sagara Gunathunga Date: Tue, 28 Feb 2012 12:46:26 +0000 Subject: [PATCH] Applied patch for TRANSPORTS-35. --- .../transport/jms/ServiceTaskManager.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/modules/jms/src/main/java/org/apache/axis2/transport/jms/ServiceTaskManager.java b/modules/jms/src/main/java/org/apache/axis2/transport/jms/ServiceTaskManager.java index 2dd3a83..112c92b 100644 --- a/modules/jms/src/main/java/org/apache/axis2/transport/jms/ServiceTaskManager.java +++ b/modules/jms/src/main/java/org/apache/axis2/transport/jms/ServiceTaskManager.java @@ -144,6 +144,9 @@ public class ServiceTaskManager { /** The JMS Connection shared between multiple polling tasks - when enabled (reccomended) */ private Connection sharedConnection = null; + /** Is this error triggers a JMS onException ?*/ + private volatile boolean isOnExceptionError = false; + /** * Start or re-start the Task Manager by shutting down any existing worker tasks and * re-creating them. However, if this is STM is PAUSED, a start request is ignored. @@ -464,9 +467,13 @@ public void run() { synchronized(pollingTasks) { pollingTasks.remove(this); } - - // My time is up, so if I am going away, create another - scheduleNewTaskIfAppropriate(); + + // if this is a JMS onException, ServiceTaskManager#onException will schedule + // a new polling task + if (!isOnExceptionError) { + // My time is up, so if I am going away, create another + scheduleNewTaskIfAppropriate(); + } } } @@ -592,6 +599,8 @@ private void handleMessage(Message message, UserTransaction ut) { */ public void onException(JMSException j) { + isOnExceptionError = true; + if (!isSTMActive()) { requestShutdown(); return; @@ -631,9 +640,9 @@ public void onException(JMSException j) { } if (!connected) { + retryDuration = (long) (retryDuration * reconnectionProgressionFactor); log.error("Reconnection attempt : " + (r++) + " for service : " + serviceName + " failed. Next retry in " + (retryDuration/1000) + "seconds"); - retryDuration = (long) (retryDuration * reconnectionProgressionFactor); if (retryDuration > maxReconnectDuration) { retryDuration = maxReconnectDuration; } @@ -641,6 +650,10 @@ public void onException(JMSException j) { try { Thread.sleep(retryDuration); } catch (InterruptedException ignore) {} + } else { + isOnExceptionError = false; + log.info("Reconnection attempt: " + r + " for service: " + serviceName + + " was successful!"); } } while (!isSTMActive() || getConnectedTaskCount() < concurrentConsumers);