servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r358310 - in /incubator/servicemix/trunk/servicemix-components/src/main/java/org/servicemix/components/jms: JmsReceiverComponent.java JmsServiceComponent.java
Date Wed, 21 Dec 2005 15:57:39 GMT
Author: gnodet
Date: Wed Dec 21 07:57:36 2005
New Revision: 358310

URL: http://svn.apache.org/viewcvs?rev=358310&view=rev
Log:
Fix JmsServiceComponent : the consumer is created by the template and is thus closed just
after creation

Modified:
    incubator/servicemix/trunk/servicemix-components/src/main/java/org/servicemix/components/jms/JmsReceiverComponent.java
    incubator/servicemix/trunk/servicemix-components/src/main/java/org/servicemix/components/jms/JmsServiceComponent.java

Modified: incubator/servicemix/trunk/servicemix-components/src/main/java/org/servicemix/components/jms/JmsReceiverComponent.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-components/src/main/java/org/servicemix/components/jms/JmsReceiverComponent.java?rev=358310&r1=358309&r2=358310&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/main/java/org/servicemix/components/jms/JmsReceiverComponent.java
(original)
+++ incubator/servicemix/trunk/servicemix-components/src/main/java/org/servicemix/components/jms/JmsReceiverComponent.java
Wed Dec 21 07:57:36 2005
@@ -46,7 +46,6 @@
             throw new IllegalArgumentException("Must have a template set");
         }
         connectionFactory = template.getConnectionFactory();
-//PS Fix: START
         /*
          * Component code did not work for JMS 1.02 compliant provider because uses APIs
          * that did not exist in JMS 1.02 : ConnectionFactory.createConnection,
@@ -68,14 +67,13 @@
             connection = connectionFactory.createConnection();
             session = connection.createSession(template.isSessionTransacted(), template.getSessionAcknowledgeMode());
         }
-//PS Fix: END
 
         Destination defaultDestination = template.getDefaultDestination();
         if (defaultDestination == null) {
             defaultDestination = template.getDestinationResolver().resolveDestinationName(session,
template.getDefaultDestinationName(),
                     template.isPubSubDomain());
         }
-//PS Fix: START
+
         /*
          * Component code did not work for JMS 1.02 compliant provider because uses APIs
          * that did not exist in JMS 1.02: Session.createConsumer
@@ -91,27 +89,12 @@
         } else { // JMS 1.1 style
             consumer = session.createConsumer(defaultDestination, selector);
         }
-//PS Fix: END
+
         consumer.setMessageListener(this);
         connection.start();
     }
 
     public void destroy() throws Exception {
-//PS Fix: START
-        /*
-        if (consumer != null) {
-            consumer.close();
-            consumer = null;
-        }
-        if (session != null) {
-            session.close();
-            session = null;
-        }
-        if (connection != null) {
-            connection.close();
-            connection = null;
-        }
-        */
         try {
             if (connection != null) {
                 connection.close();
@@ -125,7 +108,6 @@
             session = null;
             consumer = null;
         }
-//PS Fix: END
     }
 
     public JmsTemplate getTemplate() {

Modified: incubator/servicemix/trunk/servicemix-components/src/main/java/org/servicemix/components/jms/JmsServiceComponent.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-components/src/main/java/org/servicemix/components/jms/JmsServiceComponent.java?rev=358310&r1=358309&r2=358310&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/main/java/org/servicemix/components/jms/JmsServiceComponent.java
(original)
+++ incubator/servicemix/trunk/servicemix-components/src/main/java/org/servicemix/components/jms/JmsServiceComponent.java
Wed Dec 21 07:57:36 2005
@@ -15,13 +15,15 @@
  * limitations under the License. 
  * 
  **/
-
 package org.servicemix.components.jms;
+
 import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.InOut;
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.MessagingException;
 import javax.jbi.messaging.NormalizedMessage;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
 import javax.jms.Destination;
 import javax.jms.JMSException;
 import javax.jms.Message;
@@ -37,7 +39,6 @@
 import org.springframework.jms.JmsException;
 import org.springframework.jms.core.JmsTemplate;
 import org.springframework.jms.core.MessageCreator;
-import org.springframework.jms.core.SessionCallback;
 
 /**
  * A component which uses a {@link JmsTemplate} to consume messages from a destination, forward
then intot the JBI
@@ -53,6 +54,9 @@
     private JmsTemplate template;
     private String selector;
     private MessageConsumer consumer;
+    private ConnectionFactory connectionFactory;
+    private Connection connection;
+    private Session session;
 
     /**
      * called by Spring framework after initialization
@@ -62,18 +66,53 @@
         if (template == null) {
             throw new IllegalArgumentException("Must have a template set");
         }
-        template.execute(new SessionCallback() {
-            public Object doInJms(Session session) throws JMSException {
-                Destination defaultDestination = template.getDefaultDestination();
-                if (defaultDestination == null) {
-                    defaultDestination = template.getDestinationResolver().resolveDestinationName(session,
-                            template.getDefaultDestinationName(), template.isPubSubDomain());
-                }
-                consumer = session.createConsumer(defaultDestination, selector);
-                return null;
+        connectionFactory = template.getConnectionFactory();
+        /*
+         * Component code did not work for JMS 1.02 compliant provider because uses APIs
+         * that did not exist in JMS 1.02 : ConnectionFactory.createConnection,
+         * Connection.createSession
+         */
+        if (template instanceof org.springframework.jms.core.JmsTemplate102) {
+            //Note1 - would've preferred to call JmsTemplate102 methods but they are protected.
+            if (template.isPubSubDomain()) {
+                javax.jms.TopicConnection tc;
+                connection = tc = ((javax.jms.TopicConnectionFactory)connectionFactory).createTopicConnection();
+                session = tc.createTopicSession(template.isSessionTransacted(), template.getSessionAcknowledgeMode());
+            }
+            else {
+                javax.jms.QueueConnection qc;
+                connection = qc = ((javax.jms.QueueConnectionFactory)connectionFactory).createQueueConnection();
+                session = qc.createQueueSession(template.isSessionTransacted(), template.getSessionAcknowledgeMode());
+            }
+        } else { // JMS 1.1 style
+            connection = connectionFactory.createConnection();
+            session = connection.createSession(template.isSessionTransacted(), template.getSessionAcknowledgeMode());
+        }
+
+        Destination defaultDestination = template.getDefaultDestination();
+        if (defaultDestination == null) {
+            defaultDestination = template.getDestinationResolver().resolveDestinationName(session,
template.getDefaultDestinationName(),
+                    template.isPubSubDomain());
+        }
+        
+        /*
+         * Component code did not work for JMS 1.02 compliant provider because uses APIs
+         * that did not exist in JMS 1.02: Session.createConsumer
+         */
+        if (template instanceof org.springframework.jms.core.JmsTemplate102) {
+            //Note1 - would've preferred to call JmsTemplate102.createConsumer but it is
protected. Code below is same.
+            //Note2 - assert that defaultDestination is correct type according to isPubSubDomain()
+            if (template.isPubSubDomain()) {
+                consumer = ((javax.jms.TopicSession)session).createSubscriber((javax.jms.Topic)defaultDestination,
selector, template.isPubSubNoLocal());
+            } else {
+                consumer = ((javax.jms.QueueSession)session).createReceiver((javax.jms.Queue)defaultDestination,
selector);
             }
-        }, true);
+        } else { // JMS 1.1 style
+            consumer = session.createConsumer(defaultDestination, selector);
+        }
+
         consumer.setMessageListener(this);
+        connection.start();
     }
 
     /**
@@ -81,8 +120,18 @@
      * @throws Exception 
      */
     public void destroy() throws Exception {
-        if (consumer != null) {
-            consumer.close();
+        try {
+            if (connection != null) {
+                connection.close();
+            } else if (session != null) {
+                session.close();
+            } else if (consumer != null) {
+                consumer.close();
+            }
+        } finally {
+            connection = null;
+            session = null;
+            consumer = null;
         }
     }
 



Mime
View raw message