You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2010/03/22 04:02:59 UTC

svn commit: r925943 - /camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java

Author: ningjiang
Date: Mon Mar 22 03:02:58 2010
New Revision: 925943

URL: http://svn.apache.org/viewvc?rev=925943&view=rev
Log:
CAMEL-2564 Should react to ContextStoppedEvent and invoke stop on CamelContext

Modified:
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java?rev=925943&r1=925942&r2=925943&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java Mon Mar 22 03:02:58 2010
@@ -37,6 +37,7 @@ import org.springframework.context.Appli
 import org.springframework.context.ApplicationListener;
 import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.context.event.ContextStoppedEvent;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 import static org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException;
@@ -102,6 +103,12 @@ public class SpringCamelContext extends 
             } catch (Exception e) {
                 throw wrapRuntimeCamelException(e);
             }
+        } else if (event instanceof ContextStoppedEvent) {
+            try {
+                maybeStop();
+            } catch (Exception e) {
+                throw wrapRuntimeCamelException(e);
+            }
         }
 
         if (eventEndpoint != null) {
@@ -201,6 +208,15 @@ public class SpringCamelContext extends 
         }
     }
 
+    private void maybeStop() throws Exception {
+        if (!isStopping() && !isStopped()) {
+            stop();
+        } else {
+            // ignore as Camel is already stopped
+            LOG.trace("Ignoring maybeStop() as Apache Camel is already stopped");
+        }
+    }
+
     @Override
     public String toString() {
         StringBuilder sb = new StringBuilder();