cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r748604 - in /cxf/trunk/rt/transports/jms/src/main: java/org/apache/cxf/transport/jms/ resources/schemas/wsdl/
Date Fri, 27 Feb 2009 17:17:33 GMT
Author: dkulp
Date: Fri Feb 27 17:17:33 2009
New Revision: 748604

URL: http://svn.apache.org/viewvc?rev=748604&view=rev
Log:
[CXF-2034] Add lifecycle listener to make sure the listeners are shutdown
If the user specifies a CorrelationID and the destination cannot handle that, bring up a new
temporary queue to handle it to avoid a "hang".

Modified:
    cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java
    cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConfiguration.java
    cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
    cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSFactory.java
    cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSOldConfigHolder.java
    cxf/trunk/rt/transports/jms/src/main/resources/schemas/wsdl/jms.xsd

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=748604&r1=748603&r2=748604&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
Fri Feb 27 17:17:33 2009
@@ -24,6 +24,7 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
+import java.lang.ref.WeakReference;
 import java.util.Map;
 import java.util.UUID;
 import java.util.concurrent.ConcurrentHashMap;
@@ -35,6 +36,9 @@
 import javax.jms.MessageListener;
 import javax.jms.Session;
 
+import org.apache.cxf.Bus;
+import org.apache.cxf.buslifecycle.BusLifeCycleListener;
+import org.apache.cxf.buslifecycle.BusLifeCycleManager;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
@@ -54,6 +58,7 @@
  * Message. This is then provided in the Exchange and also sent to the incomingObserver
  */
 public class JMSConduit extends AbstractConduit implements JMSExchangeSender, MessageListener
{
+
     static final Logger LOG = LogUtils.getL7dLogger(JMSConduit.class);
     
     private static final String CORRELATED = JMSConduit.class.getName() + ".correlated";
@@ -62,8 +67,10 @@
     private JMSConfiguration jmsConfig;
     private Map<String, Exchange> correlationMap;
     private DefaultMessageListenerContainer jmsListener;
+    private DefaultMessageListenerContainer allListener;
     private String conduitId;
     private AtomicLong messageCount;
+    private JMSBusLifeCycleListener listener;
 
     public JMSConduit(EndpointInfo endpointInfo, EndpointReferenceType target, JMSConfiguration
jmsConfig) {
         super(target);
@@ -108,12 +115,32 @@
             .get(JMSConstants.JMS_CLIENT_REQUEST_HEADERS);
 
         JmsTemplate jmsTemplate = JMSFactory.createJmsTemplate(jmsConfig, headers);
-        if (!exchange.isOneWay() && jmsListener == null) {
-            jmsListener = JMSFactory.createJmsListener(jmsConfig, this, jmsConfig.getReplyDestination(),

-                                                       conduitId);
+        String userCID = headers != null ? headers.getJMSCorrelationID() : null;
+        DefaultMessageListenerContainer jmsList = jmsListener;
+        if (!exchange.isOneWay()) {
+            if (userCID == null || !jmsConfig.isUseConduitIdSelector()) { 
+                if (jmsListener == null) {
+                    jmsListener = JMSFactory.createJmsListener(jmsConfig, this, 
+                                                               jmsConfig.getReplyDestination(),

+                                                               conduitId, 
+                                                               false);
+                    addBusListener(exchange.get(Bus.class));
+                }
+                jmsList = jmsListener;
+            } else {
+                if (allListener == null) {
+                    allListener = JMSFactory.createJmsListener(jmsConfig, 
+                                                               this, 
+                                                               null, 
+                                                               null, 
+                                                               true);
+                    addBusListener(exchange.get(Bus.class));
+                }
+                jmsList = allListener;
+            }
         }
         
-        final javax.jms.Destination replyTo = exchange.isOneWay() ? null : jmsListener.getDestination();
+        final javax.jms.Destination replyTo = exchange.isOneWay() ? null : jmsList.getDestination();
 
         final String correlationId = (headers != null && headers.isSetJMSCorrelationID())

             ? headers.getJMSCorrelationID() 
@@ -154,8 +181,6 @@
                         throw new RuntimeException("Timeout receiving message with correlationId
"
                                                    + correlationId);
                     }
-                    
-                    
                 }
             }
         } else {
@@ -163,6 +188,46 @@
         }
     }
 
+    static class JMSBusLifeCycleListener implements BusLifeCycleListener {
+        final WeakReference<JMSConduit> ref;
+        BusLifeCycleManager blcm;
+        JMSBusLifeCycleListener(JMSConduit c, BusLifeCycleManager b) {
+            ref = new WeakReference<JMSConduit>(c);
+            blcm = b;
+            blcm.registerLifeCycleListener(this);
+        }
+        
+        public void initComplete() {
+        }
+
+        public void postShutdown() {
+        }
+
+        public void preShutdown() {
+            unreg();
+            blcm = null;
+            JMSConduit c = ref.get();
+            if (c != null) {
+                c.listener = null;
+                c.close();
+            }
+        }
+        public void unreg() {
+            if (blcm != null) {
+                blcm.unregisterLifeCycleListener(this);
+            }
+        }
+    }
+    private synchronized void addBusListener(Bus bus) {
+        if (listener == null && bus != null) {
+            BusLifeCycleManager blcm = bus.getExtension(BusLifeCycleManager.class);
+            if (blcm != null) {
+                listener = new JMSBusLifeCycleListener(this,
+                                                       blcm);
+            }
+        }
+    }
+
     /**
      * When a message is received on the reply destination the correlation map is searched
for the
      * correlationId. If it is found the message is converted to a CXF message and the thread
sending the
@@ -208,9 +273,16 @@
     }
 
     public void close() {
+        if (listener != null) {
+            listener.unreg();
+            listener = null;
+        }
         if (jmsListener != null) {
             jmsListener.shutdown();
         }
+        if (allListener != null) {
+            allListener.shutdown();
+        }
         LOG.log(Level.FINE, "JMSConduit closed ");
     }
 
@@ -228,9 +300,16 @@
 
     @Override
     protected void finalize() throws Throwable {
+        if (listener != null) {
+            listener.unreg();
+            listener = null;
+        }
         if (jmsListener != null) {
             jmsListener.shutdown();
         }
+        if (allListener != null) {
+            allListener.shutdown();
+        }
         super.finalize();
     }
 

Modified: cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConfiguration.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConfiguration.java?rev=748604&r1=748603&r2=748604&view=diff
==============================================================================
--- cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConfiguration.java
(original)
+++ cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConfiguration.java
Fri Feb 27 17:17:33 2009
@@ -74,7 +74,7 @@
     private String replyDestination;
     private String messageType = JMSConstants.TEXT_MESSAGE_TYPE;
     private boolean pubSubDomain;
-    private boolean useConduitIdSelector = true;
+    private Boolean useConduitIdSelector;
     private String conduitSelectorPrefix = "";
     private boolean autoResolveDestination;
     private long recoveryInterval = DEFAULT_VALUE;
@@ -332,9 +332,15 @@
     }
 
     public boolean isUseConduitIdSelector() {
+        if (useConduitIdSelector == null) {
+            return true;
+        }
         return useConduitIdSelector;
     }
-
+    public boolean isSetUseConduitIdSelector() {
+        return useConduitIdSelector != null;
+    }
+    
     public int getMaxConcurrentTasks() {
         return maxConcurrentTasks;
     }

Modified: cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java?rev=748604&r1=748603&r2=748604&view=diff
==============================================================================
--- cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
(original)
+++ cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
Fri Feb 27 17:17:33 2009
@@ -102,7 +102,8 @@
         org.apache.cxf.common.i18n.Message msg = 
             new org.apache.cxf.common.i18n.Message("INSUFFICIENT_CONFIGURATION_DESTINATION",
LOG, name);
         jmsConfig.ensureProperlyConfigured(msg);
-        jmsListener = JMSFactory.createJmsListener(jmsConfig, this, jmsConfig.getTargetDestination(),
null);
+        jmsListener = JMSFactory.createJmsListener(jmsConfig, this, 
+                                                   jmsConfig.getTargetDestination(), null,
true);
     }
 
     public void deactivate() {
@@ -196,6 +197,10 @@
     }
 
     public void sendExchange(Exchange exchange, final Object replyObj) {
+        if (exchange.isOneWay()) {
+            //Don't need to send anything
+            return;
+        }
         Message inMessage = exchange.getInMessage();
         final Message outMessage = exchange.getOutMessage();
         if (jmsConfig.isPubSubDomain()) {

Modified: cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSFactory.java?rev=748604&r1=748603&r2=748604&view=diff
==============================================================================
--- cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSFactory.java
(original)
+++ cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSFactory.java
Fri Feb 27 17:17:33 2009
@@ -117,7 +117,8 @@
     public static DefaultMessageListenerContainer createJmsListener(JMSConfiguration jmsConfig,
                                                                     MessageListener listenerHandler,
                                                                     String destinationName,

-                                                                    String messageSelectorPrefix)
{
+                                                                    String messageSelectorPrefix,
+                                                                    boolean userCID) {
         DefaultMessageListenerContainer jmsListener = jmsConfig.isUseJms11()
             ? new DefaultMessageListenerContainer() : new DefaultMessageListenerContainer102();
         jmsListener.setConcurrentConsumers(jmsConfig.getConcurrentConsumers());
@@ -141,13 +142,15 @@
             jmsListener.setCacheLevel(jmsConfig.getCacheLevel());
         }
         String staticSelectorPrefix = jmsConfig.getConduitSelectorPrefix();
-        if (messageSelectorPrefix != null && jmsConfig.isUseConduitIdSelector())
{
-            jmsListener.setMessageSelector("JMSCorrelationID LIKE '" 
+        if (!userCID || jmsConfig.isSetUseConduitIdSelector()) {
+            if (messageSelectorPrefix != null && jmsConfig.isUseConduitIdSelector())
{
+                jmsListener.setMessageSelector("JMSCorrelationID LIKE '" 
                                             + staticSelectorPrefix 
                                             + messageSelectorPrefix + "%'");
-        } else if (staticSelectorPrefix.length() > 0) {
-            jmsListener.setMessageSelector("JMSCorrelationID LIKE '" 
+            } else if (staticSelectorPrefix.length() > 0) {
+                jmsListener.setMessageSelector("JMSCorrelationID LIKE '" 
                                             + staticSelectorPrefix +  "%'");
+            }
         }
         if (jmsConfig.getDestinationResolver() != null) {
             jmsListener.setDestinationResolver(jmsConfig.getDestinationResolver());

Modified: cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSOldConfigHolder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSOldConfigHolder.java?rev=748604&r1=748603&r2=748604&view=diff
==============================================================================
--- cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSOldConfigHolder.java
(original)
+++ cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSOldConfigHolder.java
Fri Feb 27 17:17:33 2009
@@ -96,7 +96,9 @@
             //if (clientConfig.isSetClientReceiveTimeout()) {
             jmsConfig.setReceiveTimeout(clientConfig.getClientReceiveTimeout());
             //}
-            jmsConfig.setUseConduitIdSelector(clientConfig.isUseConduitIdSelector());
+            if (clientConfig.isSetUseConduitIdSelector()) {
+                jmsConfig.setUseConduitIdSelector(clientConfig.isUseConduitIdSelector());
+            }
             if (clientConfig.isSetConduitSelectorPrefix()) {
                 jmsConfig.setConduitSelectorPrefix(clientConfig.getConduitSelectorPrefix());
             }

Modified: cxf/trunk/rt/transports/jms/src/main/resources/schemas/wsdl/jms.xsd
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/jms/src/main/resources/schemas/wsdl/jms.xsd?rev=748604&r1=748603&r2=748604&view=diff
==============================================================================
--- cxf/trunk/rt/transports/jms/src/main/resources/schemas/wsdl/jms.xsd (original)
+++ cxf/trunk/rt/transports/jms/src/main/resources/schemas/wsdl/jms.xsd Fri Feb 27 17:17:33
2009
@@ -55,7 +55,7 @@
     			<xs:attribute name="messageTimeToLive" type="xs:long"
     				default="0" />
                 <xs:attribute name="conduitSelectorPrefix" type="xs:string" use="optional"
default=""/>    				
-                <xs:attribute name="useConduitIdSelector" type="xs:boolean" use="optional"
default="true"/>
+                <xs:attribute name="useConduitIdSelector" type="xs:boolean" use="optional"/>
     		</xs:extension>
     	</xs:complexContent>
     </xs:complexType>



Mime
View raw message