camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1464566 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/util/ camel-core/src/test/java/org/apache/camel/util/ platforms/karaf/commands/...
Date Thu, 04 Apr 2013 14:27:39 GMT
Author: davsclaus
Date: Thu Apr  4 14:27:39 2013
New Revision: 1464566

URL: http://svn.apache.org/r1464566
Log:
CAMEL-6237: Polished karaf commands

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/util/CamelContextHelperTest.java
    camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractRouteCommand.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?rev=1464566&r1=1464565&r2=1464566&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java Thu Apr  4 14:27:39
2013
@@ -48,6 +48,7 @@ import org.apache.camel.spi.NodeIdFactor
 import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.camel.spi.ProcessorFactory;
 import org.apache.camel.spi.Registry;
+import org.apache.camel.spi.RouteStartupOrder;
 import org.apache.camel.spi.ServicePool;
 import org.apache.camel.spi.ShutdownStrategy;
 import org.apache.camel.spi.TypeConverterRegistry;
@@ -350,6 +351,16 @@ public interface CamelContext extends Su
     RouteDefinition getRouteDefinition(String id);
 
     /**
+     * Returns the order in which the route inputs was started.
+     * <p/>
+     * The order may not be according to the startupOrder defined on the route.
+     * For example a route could be started manually later, or new routes added at runtime.
+     *
+     * @return a list in the order how routes was started
+     */
+    List<RouteStartupOrder> getRouteStartupOrder();
+
+    /**
      * Returns the current routes in this context
      *
      * @return the current routes

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=1464566&r1=1464565&r2=1464566&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Thu
Apr  4 14:27:39 2013
@@ -611,14 +611,6 @@ public class DefaultCamelContext extends
     // Route Management Methods
     // -----------------------------------------------------------------------
 
-    /**
-     * Returns the order in which the route inputs was started.
-     * <p/>
-     * The order may not be according to the startupOrder defined on the route.
-     * For example a route could be started manually later, or new routes added at runtime.
-     *
-     * @return a list in the order how routes was started
-     */
     public List<RouteStartupOrder> getRouteStartupOrder() {
         return routeStartupOrder;
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java?rev=1464566&r1=1464565&r2=1464566&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java Thu
Apr  4 14:27:39 2013
@@ -33,6 +33,7 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.NoSuchBeanException;
 import org.apache.camel.NoSuchEndpointException;
+import org.apache.camel.spi.RouteStartupOrder;
 
 import static org.apache.camel.util.ObjectHelper.isEmpty;
 import static org.apache.camel.util.ObjectHelper.isNotEmpty;
@@ -390,4 +391,21 @@ public final class CamelContextHelper {
         }
         return map;
     }
+
+    /**
+     * Gets the route startup order for the given route id
+     *
+     * @param camelContext  the camel context
+     * @param routeId       the id of the route
+     * @return the startup order, or <tt>0</tt> if not possible to determine
+     */
+    public static int getRouteStartupOrder(CamelContext camelContext, String routeId) {
+        for (RouteStartupOrder order : camelContext.getRouteStartupOrder()) {
+            if (order.getRoute().getId().equals(routeId)) {
+                return order.getStartupOrder();
+            }
+        }
+        return 0;
+    }
+
 }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/util/CamelContextHelperTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/CamelContextHelperTest.java?rev=1464566&r1=1464565&r2=1464566&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/util/CamelContextHelperTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/util/CamelContextHelperTest.java
Thu Apr  4 14:27:39 2013
@@ -18,6 +18,7 @@ package org.apache.camel.util;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.impl.JndiRegistry;
 
@@ -63,7 +64,24 @@ public class CamelContextHelperTest exte
         assertNotNull(foo);
     }
 
+    public void testRouteStartupOrder() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:foo").routeId("foo").startupOrder(222).to("mock:foo");
+                from("direct:bar").routeId("bar").startupOrder(111).to("mock:bar");
+            }
+        });
+
+        assertEquals(111, CamelContextHelper.getRouteStartupOrder(context, "bar"));
+        assertEquals(222, CamelContextHelper.getRouteStartupOrder(context, "foo"));
+
+        // no route with that name
+        assertEquals(0, CamelContextHelper.getRouteStartupOrder(context, "zzz"));
+    }
+
     public static class MyFooBean {
 
     }
+
 }

Modified: camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractRouteCommand.java
URL: http://svn.apache.org/viewvc/camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractRouteCommand.java?rev=1464566&r1=1464565&r2=1464566&view=diff
==============================================================================
--- camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractRouteCommand.java
(original)
+++ camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/AbstractRouteCommand.java
Thu Apr  4 14:27:39 2013
@@ -26,6 +26,8 @@ import org.apache.camel.karaf.commands.i
 import org.apache.felix.gogo.commands.Argument;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
 
+import static org.apache.camel.util.CamelContextHelper.getRouteStartupOrder;
+
 public abstract class AbstractRouteCommand extends OsgiCommandSupport {
     @Argument(index = 0, name = "route", description = "The Camel route ID or a wildcard
expression", required = true, multiValued = false)
     String route;
@@ -74,14 +76,21 @@ public abstract class AbstractRouteComma
         @Override
         public int compare(Route o1, Route o2) {
             // sort by camel context first
-            String camel1 = o1.getRouteContext().getCamelContext().getName();
-            String camel2 = o2.getRouteContext().getCamelContext().getName();
+            CamelContext camel1 = o1.getRouteContext().getCamelContext();
+            CamelContext camel2 = o2.getRouteContext().getCamelContext();
 
-            if (camel1.equals(camel2)) {
-                // and then route names in the same context
-                return o1.getId().compareTo(o2.getId());
+            if (camel1.getName().equals(camel2.getName())) {
+                // and then accordingly to startup order
+                int order1 = getRouteStartupOrder(camel1, o1.getId());
+                int order2 = getRouteStartupOrder(camel2, o2.getId());
+                if (order1 == 0 && order2 == 0) {
+                    // fallback and use name if not startup order was found
+                    return o1.getId().compareTo(o2.getId());
+                } else {
+                    return Integer.compare(order1, order2);
+                }
             } else {
-                return camel1.compareTo(camel2);
+                return camel1.getName().compareTo(camel2.getName());
             }
         }
     }



Mime
View raw message