camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject git commit: CAMEL-7725 Added the startupOrder in camel-scala DSL with thanks to Edin
Date Wed, 20 Aug 2014 02:42:00 GMT
Repository: camel
Updated Branches:
  refs/heads/master c4f5f8ce7 -> 8a48ccf13


CAMEL-7725 Added the startupOrder in camel-scala DSL with thanks to Edin


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8a48ccf1
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8a48ccf1
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8a48ccf1

Branch: refs/heads/master
Commit: 8a48ccf139efee1319c807dde65b908873b95f06
Parents: c4f5f8c
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Wed Aug 20 10:25:59 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Wed Aug 20 10:34:59 2014 +0800

----------------------------------------------------------------------
 .../apache/camel/model/ProcessorDefinition.java | 11 ++++
 .../scala/org/apache/camel/scala/dsl/DSL.scala  |  1 +
 .../camel/scala/dsl/SAbstractDefinition.scala   |  1 +
 .../camel/scala/dsl/builder/RouteBuilder.scala  |  1 +
 .../apache/camel/scala/dsl/StartOrderTest.scala | 54 ++++++++++++++++++++
 5 files changed, 68 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/8a48ccf1/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index a704e05..3d2714e 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -2411,6 +2411,17 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
         return blocks.isEmpty() ? null : blocks.removeLast();
     }
 
+    public Type startupOrder(int startupOrder) {
+        ProcessorDefinition<?> def = this;
+
+        RouteDefinition route = ProcessorDefinitionHelper.getRoute(def);
+        if (route != null) {
+            route.startupOrder(startupOrder);
+        }
+
+        return (Type) this;
+    }
+
     /**
      * Stops continue routing the current {@link org.apache.camel.Exchange} and marks it
as completed.
      *

http://git-wip-us.apache.org/repos/asf/camel/blob/8a48ccf1/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
----------------------------------------------------------------------
diff --git a/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
index 839f644..a94416c 100644
--- a/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
+++ b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
@@ -88,6 +88,7 @@ trait DSL {
   def setProperty(header: String, expression: Exchange => Any) : DSL
   def sort[T](expression: Exchange => Any, comparator: Comparator[T] = null) : DSL
   def split(expression: Exchange => Any) : SSplitDefinition
+  def startupOrder(startupOrder :Int) : DSL
   def stop : DSL
 
   def threads : SThreadsDefinition

http://git-wip-us.apache.org/repos/asf/camel/blob/8a48ccf1/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala
----------------------------------------------------------------------
diff --git a/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala
b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala
index a488997..16005c5 100644
--- a/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala
+++ b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala
@@ -131,6 +131,7 @@ abstract class SAbstractDefinition[P <: ProcessorDefinition[_]] extends
DSL with
   def setProperty(name: String, expression: Exchange => Any) = wrap(target.setProperty(name,
expression))
   def sort[T](expression: (Exchange) => Any, comparator: Comparator[T] = null) = wrap(target.sort(expression,
comparator))
   def split(expression: Exchange => Any) = SSplitDefinition(target.split(expression))
+  def startupOrder(startupOrder :Int) = wrap(target.startupOrder(startupOrder))
   def stop = wrap(target.stop)
 
   def threads = SThreadsDefinition(target.threads)

http://git-wip-us.apache.org/repos/asf/camel/blob/8a48ccf1/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
----------------------------------------------------------------------
diff --git a/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
index 26e19bb..dead968 100644
--- a/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
+++ b/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
@@ -181,6 +181,7 @@ class RouteBuilder extends Preamble with DSL with RoutesBuilder with Languages
w
   def setProperty(name: String, expression: Exchange => Any) = stack.top.setProperty(name,
expression)
   def sort[T](expression: (Exchange) => Any, comparator: Comparator[T] = null) = stack.top.sort(expression,
comparator)
   def split(expression: Exchange => Any) = stack.top.split(expression)
+  def startupOrder(startupOrder :Int) = stack.top.startupOrder(startupOrder)
   def stop = stack.top.stop
 
   def threads = stack.top.threads

http://git-wip-us.apache.org/repos/asf/camel/blob/8a48ccf1/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/StartOrderTest.scala
----------------------------------------------------------------------
diff --git a/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/StartOrderTest.scala
b/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/StartOrderTest.scala
new file mode 100644
index 0000000..73239f6
--- /dev/null
+++ b/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/StartOrderTest.scala
@@ -0,0 +1,54 @@
+/**
+ * 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.camel.scala.dsl
+
+import java.util.List
+import org.apache.camel.scala.dsl.builder.RouteBuilder
+import org.apache.camel.spi.RouteStartupOrder;
+import org.junit.Assert.assertEquals
+import org.junit.Test
+
+class StartOrderTest extends ScalaTestSupport {
+
+  @Test
+  def testRouteA() {
+    "mock:result" expect { _.expectedMessageCount(1)}
+
+    test {
+      "direct:start" ! "Hello World"
+    }
+
+    assertMockEndpointsSatisfied()
+
+    assertEquals(4, context().getRouteStartupOrder().size())
+    assertEquals("seda://foo", context().getRouteStartupOrder().get(0).getRoute().getEndpoint().getEndpointUri())
+    assertEquals("direct://start", context().getRouteStartupOrder().get(1).getRoute().getEndpoint().getEndpointUri())
+    assertEquals("seda://bar", context().getRouteStartupOrder().get(2).getRoute().getEndpoint().getEndpointUri())
+    assertEquals("direct://bar", context().getRouteStartupOrder().get(3).getRoute().getEndpoint().getEndpointUri())
+  }
+
+
+  val builder = new RouteBuilder {
+
+    from("direct:start").startupOrder(2).to("seda:foo")
+    "seda:foo" startupOrder 1 to "mock:result"
+    "direct:bar" startupOrder 9 to "seda:bar"
+    "seda:bar" startupOrder 5 to "mock:other"
+
+  }
+
+}
\ No newline at end of file


Mime
View raw message