You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2008/11/03 10:18:32 UTC

svn commit: r710028 - in /servicemix/components/engines/servicemix-camel/trunk/src: main/java/org/apache/servicemix/camel/JbiEndpoint.java test/java/org/apache/servicemix/camel/JbiProducerTest.java

Author: gertv
Date: Mon Nov  3 01:18:31 2008
New Revision: 710028

URL: http://svn.apache.org/viewvc?rev=710028&view=rev
Log:
SM-1671: DeploymentException on shutdown when multiple routes target the same JBI endpoint

Added:
    servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiProducerTest.java   (with props)
Modified:
    servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java

Modified: servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java?rev=710028&r1=710027&r2=710028&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java (original)
+++ servicemix/components/engines/servicemix-camel/trunk/src/main/java/org/apache/servicemix/camel/JbiEndpoint.java Mon Nov  3 01:18:31 2008
@@ -30,6 +30,8 @@
 import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.util.URISupport;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * Represents an {@link org.apache.camel.Endpoint} for interacting with JBI
@@ -62,6 +64,8 @@
     }
 
     protected class JbiProducer extends DefaultProducer<Exchange> implements AsyncProcessor {
+        
+        private final Log log = LogFactory.getLog(JbiProducer.class);
 
         private CamelConsumerEndpoint consumer;
 
@@ -72,15 +76,18 @@
         @Override
         public void start() throws Exception {
             consumer = new CamelConsumerEndpoint(jbiComponent.getBinding(), JbiEndpoint.this);
-            //consumer.start();
             jbiComponent.addEndpoint(consumer);
             super.start();
         }
         @Override
         public void stop() throws Exception {
-            //consumer.stop();
-            jbiComponent.removeEndpoint(consumer);
-            super.stop();
+            if (isStopped()) {
+                log.debug("Camel producer for " + super.getEndpoint() + " has already been stopped");
+            } else {
+                log.debug("Stopping Camel producer for " + super.getEndpoint());
+                jbiComponent.removeEndpoint(consumer);
+                super.stop();
+            }
         }
 
         public void process(Exchange exchange) throws Exception {

Added: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiProducerTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiProducerTest.java?rev=710028&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiProducerTest.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiProducerTest.java Mon Nov  3 01:18:31 2008
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.camel;
+
+import javax.jbi.management.DeploymentException;
+
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * Test for {@link JbiEndpoint.JbiProducer}  
+ */
+public class JbiProducerTest extends JbiCamelErrorHandlingTestSupport {
+  
+    /*
+     * Ensure that no exceptions get thrown when shutting down the routes
+     */
+    public void testShutdown() throws Exception {
+        client.stop();
+        try {
+            camelContext.stop();
+        } catch (DeploymentException e) {
+            fail("Shutdown should not throw " + e);
+        }
+    }
+    
+    @Override
+    protected void tearDown() throws Exception {
+        // testing shutdown, so will do this manually
+    }
+  
+    @Override
+    protected RouteBuilder createRoutes() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // two routes that target the same service endpoint 
+                from("jbi:service:urn:test:service1").to("jbi:service:urn:test:target-service");
+                from("jbi:service:urn:test:service2").to("jbi:service:urn:test:target-service");
+            }
+        };
+    }
+}

Propchange: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiProducerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native