cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r703239 - /cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java
Date Thu, 09 Oct 2008 19:58:24 GMT
Author: dkulp
Date: Thu Oct  9 12:58:24 2008
New Revision: 703239

URL: http://svn.apache.org/viewvc?rev=703239&view=rev
Log:
Fix potential race condition where a response COULD come back before the waiting thread was
waiting for it.

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

Modified: cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java?rev=703239&r1=703238&r2=703239&view=diff
==============================================================================
--- cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java
(original)
+++ cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java
Thu Oct  9 12:58:24 2008
@@ -109,13 +109,8 @@
 
         final String correlationId = (headers != null && headers.isSetJMSCorrelationID())
? headers
             .getJMSCorrelationID() : JMSUtils.generateCorrelationId();
-        // String selector = "JMSCorrelationID = '" + correlationId + "'";
-        Message inMessage = null;
-        if (!exchange.isOneWay()) {
-            inMessage = new MessageImpl();
-            correlationMap.put(correlationId, inMessage);
-        }
-        jmsTemplate.send(jmsConfig.getTargetDestination(), new MessageCreator() {
+            
+        MessageCreator messageCreator = new MessageCreator() {
             public javax.jms.Message createMessage(Session session) throws JMSException {
                 String messageType = jmsConfig.getMessageType();
                 final javax.jms.Message jmsMessage;
@@ -125,7 +120,7 @@
                 LOG.log(Level.FINE, "client sending request: ", jmsMessage);
                 return jmsMessage;
             }
-        });
+        };
 
         /**
          * If the message is not oneWay we will expect to receive a reply on the listener.
To receive this
@@ -133,10 +128,14 @@
          * fill to Message and notify this thread
          */
         if (!exchange.isOneWay()) {
+            Message inMessage = new MessageImpl();
             synchronized (inMessage) {
+                correlationMap.put(correlationId, inMessage);
+                jmsTemplate.send(jmsConfig.getTargetDestination(), messageCreator);
                 try {
                     inMessage.wait(jmsTemplate.getReceiveTimeout());
                 } catch (InterruptedException e) {
+                    correlationMap.remove(correlationId);
                     throw new RuntimeException(e);
                 }
                 correlationMap.remove(correlationId);
@@ -149,6 +148,8 @@
             if (incomingObserver != null) {
                 incomingObserver.onMessage(inMessage);
             }
+        } else {
+            jmsTemplate.send(jmsConfig.getTargetDestination(), messageCreator);
         }
     }
 



Mime
View raw message