You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/09/05 11:11:07 UTC

[2/2] camel git commit: CAMEL-8783: Fixed scala dsl to let the routes be unprepared during the various ways Scala DSL allow to build routes. Camel will prepare the routes before start, which is the correct spot.

CAMEL-8783: Fixed scala dsl to let the routes be unprepared during the various ways Scala DSL allow to build routes. Camel will prepare the routes before start, which is the correct spot.

Conflicts:
	components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala


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

Branch: refs/heads/camel-2.15.x
Commit: e081e569ac71896e59141647bc19d09306fdb3ed
Parents: dacc46d
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Sep 5 11:04:52 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Sep 5 11:06:50 2015 +0200

----------------------------------------------------------------------
 .../org/apache/camel/model/RouteDefinition.java   | 11 +++++++++++
 .../camel/scala/dsl/builder/RouteBuilder.scala    | 18 +++++++++++++++---
 .../apache/camel/scala/dsl/TransactedTest.scala   | 16 ++++++++++++----
 3 files changed, 38 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e081e569/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java b/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
index 54e7e55..82ec245 100644
--- a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
@@ -129,6 +129,17 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition> {
         prepared.set(true);
     }
 
+    /**
+     * Marks the route definition as un-prepared.
+     * <p/>
+     * This is needed if routes have been created by components such as
+     * <tt>camel-scala</tt>. To unset the prepare so the routes can be prepared
+     * at a later stage when scala has build the routes completely.
+     */
+    public void markUnprepared() {
+        prepared.set(false);
+    }
+
     @Override
     public String toString() {
         if (getId() != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/e081e569/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 1734c8e..5ef5793 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
@@ -20,6 +20,7 @@ package dsl.builder
 
 import org.apache.camel.model.DataFormatDefinition
 import org.apache.camel.{Exchange, RoutesBuilder}
+import org.apache.camel.model._
 import org.apache.camel.builder.{LoggingErrorHandlerBuilder, DeadLetterChannelBuilder, ErrorHandlerBuilder}
 
 import org.apache.camel.spi.Policy
@@ -30,7 +31,6 @@ import reflect.{ClassTag, classTag}
 import org.apache.camel.scala.dsl._
 
 import org.apache.camel.scala.dsl.languages.Languages
-import java.lang.String
 import java.util.Comparator
 import org.slf4j.{Logger, LoggerFactory}
 
@@ -46,6 +46,18 @@ class RouteBuilder extends Preamble with DSL with RoutesBuilder with Languages w
     override def configure() {
       onJavaBuilder(this)
     }
+
+    override def checkInitialized(): Unit = {
+      super.checkInitialized()
+
+      // must un-prepare the routes as they may have been eager pre-pared before scala has properly build the entire routes
+      // Camel will prepare the routes before the routes is started so it happens eventually at the right time
+      val it = getRouteCollection.getRoutes.iterator()
+      while (it.hasNext) {
+        var route = it.next()
+        route.markUnprepared()
+      }
+    }
   }
 
   val stack = new Stack[DSL]
@@ -65,7 +77,7 @@ class RouteBuilder extends Preamble with DSL with RoutesBuilder with Languages w
    */
   def onJavaBuilder(builder: org.apache.camel.builder.RouteBuilder) {}
 
-  implicit def stringToRoute(target: String) : SRouteDefinition = new SRouteDefinition(builder.from(target), this)  
+  implicit def stringToRoute(target: String) : SRouteDefinition = new SRouteDefinition(builder.from(target), this)
   implicit def unwrap[W](wrapper: Wrapper[W]) = wrapper.unwrap
   implicit def constantToExpression(value: Any) : (Exchange => Any) = (exchange: Exchange) => value 
 
@@ -196,7 +208,7 @@ class RouteBuilder extends Preamble with DSL with RoutesBuilder with Languages w
   def throttle(frequency: Frequency) = stack.top.throttle(frequency)
   def throwException(exception: Exception) = stack.top.throwException(exception)
   def transacted = stack.top.transacted
-  def transacted(uri: String) = stack.top.transacted
+  def transacted(uri: String) = stack.top.transacted(uri)
   def transform(expression: Exchange => Any) = stack.top.transform(expression)
 
   def unmarshal(format: DataFormatDefinition) = stack.top.unmarshal(format)

http://git-wip-us.apache.org/repos/asf/camel/blob/e081e569/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/TransactedTest.scala
----------------------------------------------------------------------
diff --git a/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/TransactedTest.scala b/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/TransactedTest.scala
index 700ce50..6d84de4 100644
--- a/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/TransactedTest.scala
+++ b/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/TransactedTest.scala
@@ -22,11 +22,10 @@ import org.junit.Test
 import org.springframework.transaction.support.{DefaultTransactionStatus, AbstractPlatformTransactionManager}
 import org.springframework.transaction.{TransactionDefinition, TransactionStatus, PlatformTransactionManager}
 
-
 class TransactedTest extends ScalaTestSupport {
 
   @throws(classOf[Exception])
-  override def createRegistry: JndiRegistry  = {
+  override def createRegistry: JndiRegistry = {
     val registry = super.createRegistry
     // Just setup a dummy platform transaction manager for testing
     registry.bind("transactionManager", new AbstractPlatformTransactionManager() {
@@ -36,7 +35,9 @@ class TransactedTest extends ScalaTestSupport {
 
       override def doRollback(status: DefaultTransactionStatus): Unit = {}
 
-      override def doGetTransaction(): AnyRef = {new Object()}
+      override def doGetTransaction(): AnyRef = {
+        new Object()
+      }
     })
     registry
   }
@@ -54,8 +55,15 @@ class TransactedTest extends ScalaTestSupport {
   override lazy val builder = {
 
     new ScalaRouteBuilder(context()) {
-      from("direct:start").transacted.to("mock:result")
+
+      "direct:start" ==> {
+        routeId("myRoute")
+        transacted
+        to("mock:foo")
+        to("mock:result")
+      }
     }
   }
+
 }