You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ge...@apache.org on 2009/01/06 13:36:37 UTC

svn commit: r731926 - in /activemq/camel/trunk/components/camel-scala/src: main/scala/org/apache/camel/scala/dsl/ main/scala/org/apache/camel/scala/dsl/builder/ test/scala/org/apache/camel/scala/dsl/

Author: gertv
Date: Tue Jan  6 04:36:36 2009
New Revision: 731926

URL: http://svn.apache.org/viewvc?rev=731926&view=rev
Log:
CAMEL-463: Adding support for thread()

Added:
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SThreadType.scala
    activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ThreadTest.scala
Modified:
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractType.scala
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala

Modified: activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala?rev=731926&r1=731925&r2=731926&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala (original)
+++ activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala Tue Jan  6 04:36:36 2009
@@ -42,6 +42,7 @@
   def resequence(expression: Exchange => Any) : SResequencerType
   def setbody(expression: Exchange => Any) : DSL
   def setheader(header: String, expression: Exchange => Any) : DSL
+  def thread(number: Int) : SThreadType
   def unmarshal(format: DataFormatType) : DSL
   def aggregate(expression: Exchange => Any) : SAggregatorType
   def idempotentconsumer(expression: Exchange => Any): SIdempotentConsumerType

Modified: activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractType.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractType.scala?rev=731926&r1=731925&r2=731926&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractType.scala (original)
+++ activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractType.scala Tue Jan  6 04:36:36 2009
@@ -102,6 +102,8 @@
   
   def setheader(name: String, expression: Exchange => Any) = new SProcessorType(target.setHeader(name, expression).asInstanceOf[ProcessorType[P] forSome {type P}])
   
+  def thread(count: Int) = new SThreadType(target.thread(count))
+  
   def unmarshal(format: DataFormatType) = {
     target.unmarshal(format)
     this

Added: activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SThreadType.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SThreadType.scala?rev=731926&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SThreadType.scala (added)
+++ activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SThreadType.scala Tue Jan  6 04:36:36 2009
@@ -0,0 +1,29 @@
+/**
+ * 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 org.apache.camel.model.ThreadType
+import org.apache.camel.scala.dsl.builder.RouteBuilder
+
+/**
+ * Scala enrichment for Camel's ThreadType
+ */
+class SThreadType(val target: ThreadType)(implicit val builder: RouteBuilder) extends SAbstractType with Wrapper[ThreadType] {
+ 
+  val unwrap = target
+  
+}

Modified: activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala?rev=731926&r1=731925&r2=731926&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala (original)
+++ activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala Tue Jan  6 04:36:36 2009
@@ -77,6 +77,7 @@
   def resequence(expression: Exchange => Any) = stack.top.resequence(expression)
   def setbody(expression : Exchange => Any) = stack.top.setbody(expression)
   def setheader(name: String, expression: Exchange => Any) = stack.top.setheader(name, expression)
+  def thread(count: Int) = stack.top.thread(count)
   def unmarshal(format: DataFormatType) = stack.top.unmarshal(format)
   def aggregate(expression: Exchange => Any) = stack.top.aggregate(expression)
 

Added: activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ThreadTest.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ThreadTest.scala?rev=731926&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ThreadTest.scala (added)
+++ activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ThreadTest.scala Tue Jan  6 04:36:36 2009
@@ -0,0 +1,64 @@
+/**
+ * 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 scala.dsl.builder.RouteBuilder
+import _root_.scala.collection.mutable.HashSet
+import junit.framework.Assert._
+
+/**
+ * Test for threads support in Scala DSL
+ */
+class ThreadTest extends ScalaTestSupport {
+  
+  val threads = new HashSet[Thread]()
+  
+  override def setUp() = {
+    threads.clear
+    super.setUp
+  }
+
+  def testSimpleThreads() = doTestThreads("direct:a", "mock:a")
+  def testBlockThreads() = doTestThreads("direct:b", "mock:b")
+  
+  def doTestThreads(from: String, mock: String) = {
+    mock expect {_.count = 5}
+    test {
+      from ! (1, 2, 3, 4, 5)
+    }
+    assertEquals(3, threads.size)
+  }
+  
+  val builder = new RouteBuilder {
+     //START SNIPPET: simple
+     "direct:a" thread(3) process(counter) to("mock:a")
+     //END SNIPPET: simple
+     
+     //START SNIPPET: block
+     "direct:b" thread(3) apply {
+       process(counter)
+       to("mock:b")
+     }
+     //END SNIPPET: block
+     
+     def counter(exchange: org.apache.camel.Exchange) {
+       threads += Thread.currentThread
+     }
+  }
+}
+
+