camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r657874 - in /activemq/camel/trunk/components/camel-scala: ./ src/main/scala/org/apache/camel/scala/ src/main/scala/org/apache/camel/scala/builder/ src/main/scala/org/apache/camel/scala/dsl/ src/test/scala/org/apache/camel/scala/ src/test/s...
Date Mon, 19 May 2008 17:29:38 GMT
Author: gertv
Date: Mon May 19 10:29:37 2008
New Revision: 657874

URL: http://svn.apache.org/viewvc?rev=657874&view=rev
Log:
CAMEL-463: Adding Scala DSL support for throttler/delayer/load balancer

Added:
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/Period.scala
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SDelayerType.scala
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SLoadBalanceType.scala
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SThrottlerType.scala
    activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/DelayerTest.scala
    activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/LoadBalancerTest.scala
    activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ThrottlerTest.scala
Removed:
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/RichChoice.scala
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/RichProcessor.scala
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/RichUriString.scala
Modified:
    activemq/camel/trunk/components/camel-scala/   (props changed)
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/Preamble.scala
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/builder/RouteBuilder.scala
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/ScalaDsl.scala
    activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/RichMockEndpoint.scala
    activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SplitterRouteBuilderTest.scala

Propchange: activemq/camel/trunk/components/camel-scala/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon May 19 10:29:37 2008
@@ -5,3 +5,5 @@
 target
 .settings
 eclipse-classes
+.manager
+velocity.log

Added: activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/Period.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/Period.scala?rev=657874&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/Period.scala
(added)
+++ activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/Period.scala
Mon May 19 10:29:37 2008
@@ -0,0 +1,32 @@
+/**
+ * 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;
+
+/**
+ * Represents a period (expressed in milliseconds) in time
+ */
+class Period(var milliseconds : Long) {
+
+  /**
+   * Convert the current value from seconds -> milliseconds
+   */
+  def seconds = {
+    milliseconds *= 1000
+    this
+  }
+  
+}

Modified: activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/Preamble.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/Preamble.scala?rev=657874&r1=657873&r2=657874&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/Preamble.scala
(original)
+++ activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/Preamble.scala
Mon May 19 10:29:37 2008
@@ -22,5 +22,6 @@
 trait Preamble {
 
   implicit def exchangeWrapper(exchange: Exchange[T] forSome {type T}) = new RichExchange(exchange)
+  implicit def intToPeriod(int: Int) : Period = new Period(int)
 
 }

Modified: activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/builder/RouteBuilder.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/builder/RouteBuilder.scala?rev=657874&r1=657873&r2=657874&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/builder/RouteBuilder.scala
(original)
+++ activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/builder/RouteBuilder.scala
Mon May 19 10:29:37 2008
@@ -60,5 +60,8 @@
   def otherwise = stack.top.otherwise
   def multicast = stack.top.multicast
   def process(function: Exchange => Unit) = stack.top.process(function)
+  def throttle(count: Int) = stack.top.throttle(count)
+  def loadbalance = stack.top.loadbalance
+  def delay(delay: Period) = stack.top.delay(delay)
 
 }

Added: activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SDelayerType.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SDelayerType.scala?rev=657874&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SDelayerType.scala
(added)
+++ activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SDelayerType.scala
Mon May 19 10:29:37 2008
@@ -0,0 +1,46 @@
+/**
+ * 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.DelayerType
+import org.apache.camel.scala.builder.RouteBuilder
+
+/**
+ * Scala enrichment for Camel's DelayerType
+ */
+class SDelayerType(val target: DelayerType)(implicit val builder: RouteBuilder) extends ScalaDsl
with Wrapper[DelayerType] {
+ 
+  val unwrap = target
+
+  def ms = this
+  def milliseconds = ms
+    
+  def sec = {
+    valueInMs *= 1000
+    this
+  }
+  def seconds = sec
+  
+  def min = {
+    valueInMs *= (60 * 1000)
+    this
+  }
+  def minutes = min
+  
+  def valueInMs : Long = target.getDelay().asInstanceOf[Long]
+  def valueInMs_=(period: Long) = target.setDelay(period)
+}

Added: activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SLoadBalanceType.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SLoadBalanceType.scala?rev=657874&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SLoadBalanceType.scala
(added)
+++ activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SLoadBalanceType.scala
Mon May 19 10:29:37 2008
@@ -0,0 +1,34 @@
+/**
+ * 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.LoadBalanceType
+import org.apache.camel.scala.builder.RouteBuilder
+
+/**
+ * Scala enrichment for Camel's LoadBalanceType
+ */
+class SLoadBalanceType(val target: LoadBalanceType)(implicit val builder: RouteBuilder) extends
ScalaDsl with Wrapper[LoadBalanceType] {
+ 
+  val unwrap = target
+  
+  def roundrobin = {
+    target.roundRobin
+    this;
+  }
+  
+}

Added: activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SThrottlerType.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SThrottlerType.scala?rev=657874&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SThrottlerType.scala
(added)
+++ activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SThrottlerType.scala
Mon May 19 10:29:37 2008
@@ -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 org.apache.camel.model.ThrottlerType
+import org.apache.camel.scala.builder.RouteBuilder
+
+/**
+ * Scala enrichment for Camel's ThrottlerType
+ */
+class STrottlerType(val target: ThrottlerType)(implicit val builder: RouteBuilder) extends
ScalaDsl with Wrapper[ThrottlerType] {
+ 
+  val unwrap = target
+  
+  /**
+   * Time period in milliseconds
+   */
+  def per(period: Int) = {
+    target.setTimePeriodMillis(period)
+    this
+  }
+  
+  def ms = this
+  def milliseconds = ms
+    
+  def sec = {
+    valueInMs *= 1000
+    this
+  }
+  def seconds = sec
+  
+  def min = {
+    valueInMs *= (60 * 1000)
+    this
+  }
+  def minutes = min
+
+  def valueInMs = target.getTimePeriodMillis()
+  def valueInMs_=(period: Long) = target.setTimePeriodMillis(period)
+}

Modified: activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/ScalaDsl.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/ScalaDsl.scala?rev=657874&r1=657873&r2=657874&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/ScalaDsl.scala
(original)
+++ activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/ScalaDsl.scala
Mon May 19 10:29:37 2008
@@ -69,5 +69,11 @@
     target.process(new ScalaProcessor(function))
     this
   }
+  
+  def throttle(count: Int) = new STrottlerType(target.throttler(count))
+  
+  def loadbalance = new SLoadBalanceType(target.loadBalance)
+  
+  def delay(period: Period) = new SDelayerType(target.delayer(period.milliseconds))
 
 }

Modified: activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/RichMockEndpoint.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/RichMockEndpoint.scala?rev=657874&r1=657873&r2=657874&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/RichMockEndpoint.scala
(original)
+++ activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/RichMockEndpoint.scala
Mon May 19 10:29:37 2008
@@ -18,7 +18,7 @@
 
 import org.apache.camel.component.mock.MockEndpoint
 
-class RichMockEndpoint(endpoint: MockEndpoint) {
+class RichMockEndpoint(val endpoint: MockEndpoint) {
 
   def received(messages: AnyRef*) {
     val list = new java.util.ArrayList[AnyRef](messages.length)

Added: activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/DelayerTest.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/DelayerTest.scala?rev=657874&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/DelayerTest.scala
(added)
+++ activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/DelayerTest.scala
Mon May 19 10:29:37 2008
@@ -0,0 +1,65 @@
+/**
+ * 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.w3c.dom.Document
+import scala.builder.RouteBuilder
+
+/**
+ * Test case for message delayer
+ */
+class DelayerTest extends ScalaTestSupport {
+  
+  def testSimpleDelayer = {
+    "mock:a" expect { _.count = 0 }      
+    "seda:a" ! "any given message"   
+    "mock:a" assert()
+    //messages should only arrive after waiting a while 
+    "mock:a" expect { _.count = 1 }
+    "mock:a" expect { _.setResultWaitTime(1500)}
+    "mock:a" assert();
+  }
+  
+  def testBlockDelayer = {
+    "mock:b" expect { _.count = 1 }
+    "mock:c" expect { _.count = 0 }
+    "seda:b" ! "any given message"   
+    "mock:b" assert()
+    "mock:c" assert()
+    //messages should only arrive after waiting a while 
+    "mock:c" expect { _.count = 1 }
+    "mock:c" expect { _.setResultWaitTime(1500)}
+    "mock:b" assert()
+    "mock:c" assert()
+  }    
+  val builder =
+    new RouteBuilder {
+       //START SNIPPET: simple
+       "seda:a" delay(1 seconds) to ("mock:a")
+       //END SNIPPET: simple
+       
+       //START SNIPPET: block
+       "seda:b" ==> {
+         to ("mock:b")
+         delay(1 seconds) {
+           to ("mock:c")
+         }
+       }
+       //END SNIPPET: block
+    }
+
+}

Added: activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/LoadBalancerTest.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/LoadBalancerTest.scala?rev=657874&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/LoadBalancerTest.scala
(added)
+++ activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/LoadBalancerTest.scala
Mon May 19 10:29:37 2008
@@ -0,0 +1,50 @@
+/**
+ * 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.w3c.dom.Document
+import scala.builder.RouteBuilder
+
+/**
+ * Test case for message load balancer
+ */
+class LoadBalancerTest extends ScalaTestSupport {
+  
+  def testSimpleTrottler = {
+    "mock:a" expect { _.received("message 1", "message 4") } 
+    "mock:b" expect { _.received("message 2", "message 5") }
+    "mock:c" expect { _.received("message 3", "message 6") }
+    for (id <- 1 to 6) "direct:a" ! "message " + id   
+    "mock:a" assert()
+    "mock:b" assert()
+    "mock:c" assert()
+  }
+    
+  val builder =
+    new RouteBuilder {
+       //START SNIPPET: loadbalance
+       "direct:a" ==> {
+         loadbalance roundrobin {
+           to ("mock:a")
+           to ("mock:b")
+           to ("mock:c")
+         }
+       }
+       //END SNIPPET: loadbalance
+    }
+
+}

Modified: activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SplitterRouteBuilderTest.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SplitterRouteBuilderTest.scala?rev=657874&r1=657873&r2=657874&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SplitterRouteBuilderTest.scala
(original)
+++ activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SplitterRouteBuilderTest.scala
Mon May 19 10:29:37 2008
@@ -56,6 +56,6 @@
          }
        }
        //END SNIPPET: block
-    }.print
+    }
 
 }

Added: activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ThrottlerTest.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ThrottlerTest.scala?rev=657874&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ThrottlerTest.scala
(added)
+++ activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ThrottlerTest.scala
Mon May 19 10:29:37 2008
@@ -0,0 +1,58 @@
+/**
+ * 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.w3c.dom.Document
+import scala.builder.RouteBuilder
+
+/**
+ * Test case for message throttler
+ */
+class ThrottlerTest extends ScalaTestSupport {
+  
+  def testSimpleTrottler = {
+    "mock:a" expect { _.count = 3 } 
+    "mock:a" expect { _.setResultWaitTime(1000) }  
+    for (id <- 1 to 6) "seda:a" ! id   
+    "mock:a" assert()
+  }
+  
+  def testBlockTrottler = {
+    "mock:b" expect { _.count = 6 }
+    "mock:c" expect { _.count = 3 } 
+    "mock:c" expect { _.setResultWaitTime(1000) }  
+    for (id <- 1 to 6) "seda:b" ! id   
+    "mock:b" assert()
+  }
+  
+  val builder =
+    new RouteBuilder {
+       //START SNIPPET: simple
+       "seda:a" throttle 3 per 2 seconds to ("mock:a")
+       //END SNIPPET: simple
+       
+       //START SNIPPET: block
+       "seda:b" ==> {
+         to ("mock:b")
+         throttle(3) per 2 seconds {
+           to ("mock:c")
+         }
+       }
+       //END SNIPPET: block
+    }
+
+}



Mime
View raw message