Author: ningjiang
Date: Mon Apr 20 09:59:41 2009
New Revision: 766635

URL: http://svn.apache.org/viewvc?rev=766635&view=rev
Log:
CAMEL-1547, CAMEL-1546 resolved some issues of restarting the CamelContext

Modified:
    
camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    
camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/processor/interceptor/Delayer.java
    
camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java

Modified: 
camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=766635&r1=766634&r2=766635&view=diff
==============================================================================
--- 
camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
 (original)
+++ 
camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
 Mon Apr 20 09:59:41 2009
@@ -76,7 +76,7 @@
     private static final transient Log LOG = 
LogFactory.getLog(DefaultCamelContext.class);
     private static final String NAME_PREFIX = "camel-";
     private static int nameSuffix;
-
+    private boolean routeDefinitionInitiated;
     private String name;
     private final Map<String, Endpoint> endpoints = new HashMap<String, 
Endpoint>();
     private final Map<String, Component> components = new HashMap<String, 
Component>();
@@ -390,9 +390,8 @@
             this.routes = new ArrayList<Route>();
         }
 
-        if (routes != null) {
+        if (routes != null) {            
             this.routes.addAll(routes);
-
             lifecycleStrategy.onRoutesAdd(routes);
             if (shouldStartRoutes()) {
                 startRoutes(routes);
@@ -660,7 +659,11 @@
                 startServices(component);
             }
         }
-        startRouteDefinitions(routeDefinitions);
+        // To avoid initiating the routeDefinitions after stopping the camel 
context
+        if (!routeDefinitionInitiated) {            
+            startRouteDefinitions(routeDefinitions);
+            routeDefinitionInitiated = true;
+        } 
     }
 
     protected void startRouteDefinitions(Collection<RouteType> list) throws 
Exception {
@@ -679,7 +682,8 @@
             for (Component component : components.values()) {
                 stopServices(component);
             }
-        }
+        }        
+        servicesToClose.clear();
     }
 
     protected void startRoutes(Collection<Route> routeList) throws Exception {

Modified: 
camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/processor/interceptor/Delayer.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/processor/interceptor/Delayer.java?rev=766635&r1=766634&r2=766635&view=diff
==============================================================================
--- 
camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/processor/interceptor/Delayer.java
 (original)
+++ 
camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/processor/interceptor/Delayer.java
 Mon Apr 20 09:59:41 2009
@@ -45,13 +45,13 @@
      * @param context the camel context the delayer is connected to
      * @return the delayer or null if none can be found
      */
-    public static DelayInterceptor getDelayer(CamelContext context) {
+    public static Delayer getDelayer(CamelContext context) {
         if (context instanceof DefaultCamelContext) {
             DefaultCamelContext defaultCamelContext = (DefaultCamelContext) 
context;
             List<InterceptStrategy> list = 
defaultCamelContext.getInterceptStrategies();
             for (InterceptStrategy interceptStrategy : list) {
-                if (interceptStrategy instanceof DelayInterceptor) {
-                    return (DelayInterceptor)interceptStrategy;
+                if (interceptStrategy instanceof Delayer) {
+                    return (Delayer)interceptStrategy;
                 }
             }
         }

Modified: 
camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java?rev=766635&r1=766634&r2=766635&view=diff
==============================================================================
--- 
camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
 (original)
+++ 
camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
 Mon Apr 20 09:59:41 2009
@@ -18,6 +18,7 @@
 
 import junit.framework.TestCase;
 import org.apache.camel.Component;
+import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.bean.BeanComponent;
 
 /**
@@ -38,5 +39,27 @@
         Component component = ctx.getComponent("bean");
         assertNull(component);
     }
+    
+    public void testRestartCamelContext() throws Exception {
+        DefaultCamelContext ctx = new DefaultCamelContext();
+        ctx.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:endpointA").to("mock:endpointB");                
+            }            
+        });
+        ctx.start();
+        assertEquals("Should have one RouteService", ctx.getRoutes().size(), 
1);
+        String routeString = ctx.getRoutes().toString();
+        ctx.stop();
+        assertEquals("Should have one RouteService", ctx.getRoutes().size(), 
1);        
+        ctx.start();
+        assertEquals("Should have one RouteService", ctx.getRoutes().size(), 
1);
+        assertEquals("The RouteString should be same", routeString, 
ctx.getRoutes().toString());
+        ctx.stop();
+        assertEquals("Should have one RouteService", ctx.getRoutes().size(), 
1);       
+                
+    }
+
 
 }


Reply via email to