cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1130459 - /cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/continuations/JMSContinuation.java
Date Thu, 02 Jun 2011 10:04:12 GMT
Author: ningjiang
Date: Thu Jun  2 10:04:11 2011
New Revision: 1130459

URL: http://svn.apache.org/viewvc?rev=1130459&view=rev
Log:
CXF-3567
Do not use timer for JMSContinuation timeout task

Modified:
    cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/continuations/JMSContinuation.java

Modified: cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/continuations/JMSContinuation.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/continuations/JMSContinuation.java?rev=1130459&r1=1130458&r2=1130459&view=diff
==============================================================================
--- cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/continuations/JMSContinuation.java
(original)
+++ cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/continuations/JMSContinuation.java
Thu Jun  2 10:04:11 2011
@@ -20,20 +20,22 @@
 package org.apache.cxf.transport.jms.continuations;
 
 import java.util.Collection;
-import java.util.Timer;
-import java.util.TimerTask;
+import java.util.logging.Logger;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
+import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.continuations.Continuation;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.transport.MessageObserver;
 import org.apache.cxf.transport.jms.JMSConfiguration;
+import org.apache.cxf.workqueue.WorkQueue;
+import org.apache.cxf.workqueue.WorkQueueManager;
 import org.springframework.jms.listener.AbstractMessageListenerContainer;
 import org.springframework.jms.listener.DefaultMessageListenerContainer;
 
 public class JMSContinuation implements Continuation {
-    
+    private static final Logger LOG = LogUtils.getL7dLogger(JMSContinuation.class);
     private Bus bus;
     private Message inMessage;
     private MessageObserver incomingObserver;
@@ -46,7 +48,8 @@ public class JMSContinuation implements 
     private volatile boolean isNew = true;
     private volatile boolean isPending;
     private volatile boolean isResumed;
-    private Timer timer;
+    private volatile boolean isCanceled;
+    private WorkQueue workQueue;
     
     public JMSContinuation(Bus b, Message m, MessageObserver observer,
                            Collection<JMSContinuation> cList, 
@@ -58,7 +61,16 @@ public class JMSContinuation implements 
         continuations = cList;
         this.jmsListener = jmsListener;
         this.jmsConfig = jmsConfig;
-    }    
+        WorkQueueManager manager = bus.getExtension(WorkQueueManager.class);
+        if (manager != null) {
+            workQueue =  manager.getNamedWorkQueue("jms-continuation");
+            if (workQueue == null) {
+                workQueue = manager.getAutomaticWorkQueue();
+            }
+        } else {
+            LOG.warning("ERROR_GETTING_WORK_QUEUE");
+        }
+    }
     
     public Object getObject() {
         return userObject;
@@ -134,12 +146,10 @@ public class JMSContinuation implements 
     }
 
     protected void createTimerTask(long timeout) {
-        timer = new Timer();
-        timer.schedule(new TimerTask() {
+        workQueue.schedule(new Runnable() {
             public void run() {
                 synchronized (JMSContinuation.this) { 
-                    if (isPending) {
-                        cancelTimerTask();
+                    if (isPending && !isCanceled) {
                         doResume();
                     }
                 }
@@ -147,11 +157,8 @@ public class JMSContinuation implements 
         }, timeout);
     }
     
-    protected void cancelTimerTask() {
-        if (timer != null) {
-            timer.cancel();
-            timer = null;
-        }
+    protected synchronized void cancelTimerTask() {
+        isCanceled = true;
     }
     
     protected void updateContinuations(boolean remove) {



Mime
View raw message