Author: gnodet
Date: Fri Sep  8 02:39:48 2006
New Revision: 441456

URL: http://svn.apache.org/viewvc?view=rev&rev=441456
Log:
Fix lw jms component lifecycle

Modified:
    
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsReceiverComponent.java
    
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsServiceComponent.java

Modified: 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsReceiverComponent.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsReceiverComponent.java?view=diff&rev=441456&r1=441455&r2=441456
==============================================================================
--- 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsReceiverComponent.java
 (original)
+++ 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsReceiverComponent.java
 Fri Sep  8 02:39:48 2006
@@ -45,56 +45,56 @@
         if (template == null) {
             throw new IllegalArgumentException("Must have a template set");
         }
-        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);
-            }
-        } else { // JMS 1.1 style
-            consumer = session.createConsumer(defaultDestination, selector);
-        }
     }
     
     public void start() throws JBIException {
         // Start receiving messages only when the component has actually been 
started.
         super.start();
         try {
+            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);
+                }
+            } else { // JMS 1.1 style
+                consumer = session.createConsumer(defaultDestination, 
selector);
+            }
             connection.start();
             consumer.setMessageListener(this);
         } catch (JMSException e) {
@@ -104,12 +104,14 @@
 
     public void stop() throws JBIException {
         try {
+            if (consumer != null) {
+                consumer.close();
+            }
+            if (session != null) {
+                session.close();
+            }
             if (connection != null) {
                 connection.close();
-            } else if (session != null) {
-                session.close();
-            } else if (consumer != null) {
-                consumer.close();
             }
         } catch (JMSException e) {
             throw new JBIException("Unable to stop jms component");

Modified: 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsServiceComponent.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsServiceComponent.java?view=diff&rev=441456&r1=441455&r2=441456
==============================================================================
--- 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsServiceComponent.java
 (original)
+++ 
incubator/servicemix/branches/servicemix-3.0/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsServiceComponent.java
 Fri Sep  8 02:39:48 2006
@@ -71,56 +71,56 @@
         if (template == null) {
             throw new IllegalArgumentException("Must have a template set");
         }
-        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);
-            }
-        } else { // JMS 1.1 style
-            consumer = session.createConsumer(defaultDestination, selector);
-        }
     }
 
     public void start() throws JBIException {
         // Start receiving messages only when the component has actually been 
started.
         super.start();
         try {
+            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);
+                }
+            } else { // JMS 1.1 style
+                consumer = session.createConsumer(defaultDestination, 
selector);
+            }
             connection.start();
             consumer.setMessageListener(this);
         } catch (JMSException e) {
@@ -130,12 +130,14 @@
 
     public void stop() throws JBIException {
         try {
+            if (consumer != null) {
+                consumer.close();
+            }
+            if (session != null) {
+                session.close();
+            }
             if (connection != null) {
                 connection.close();
-            } else if (session != null) {
-                session.close();
-            } else if (consumer != null) {
-                consumer.close();
             }
         } catch (JMSException e) {
             throw new JBIException("Unable to stop jms component");


Reply via email to