Author: gertv
Date: Wed May 21 07:36:57 2008
New Revision: 658710
URL: http://svn.apache.org/viewvc?rev=658710&view=rev
Log:
CAMEL-463: Adding a pinch of syntax sugar for specifying Frequency/Period
Added:
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/Frequency.scala
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/RichInt.scala
Modified:
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/dsl/ThrottlerTest.scala
Added:
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/Frequency.scala
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/Frequency.scala?rev=658710&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/Frequency.scala
(added)
+++
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/Frequency.scala
Wed May 21 07:36:57 2008
@@ -0,0 +1,31 @@
+/**
+ * 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 frequency (count per period)
+ * @param count the number of occurrences
+ * @param period the time period for this frequency
+ */
+class Frequency(val count: Int, val period: Period) {
+
+ def seconds = {
+ period.seconds
+ 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=658710&r1=658709&r2=658710&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
Wed May 21 07:36:57 2008
@@ -22,6 +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)
+ implicit def enrichInt(int: Int) = new RichInt(int)
}
Added:
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/RichInt.scala
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/RichInt.scala?rev=658710&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/RichInt.scala
(added)
+++
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/RichInt.scala
Wed May 21 07:36:57 2008
@@ -0,0 +1,28 @@
+/**
+ * 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
+
+/**
+ * Rich wrapper for Int, providing a convenient syntax for specifying Period
and Frequency
+ */
+class RichInt(val int: Int) {
+
+ def seconds = new Period(int).seconds
+
+ def per(period: Int) = new Frequency(int, new Period(period))
+
+}
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=658710&r1=658709&r2=658710&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
Wed May 21 07:36:57 2008
@@ -60,7 +60,7 @@
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 throttle(frequency: Frequency) = stack.top.throttle(frequency)
def loadbalance = stack.top.loadbalance
def delay(delay: Period) = stack.top.delay(delay)
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=658710&r1=658709&r2=658710&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
Wed May 21 07:36:57 2008
@@ -70,7 +70,7 @@
this
}
- def throttle(count: Int) = new STrottlerType(target.throttler(count))
+ def throttle(frequency: Frequency) = new
STrottlerType(target.throttler(frequency.count).timePeriodMillis(frequency.period.milliseconds))
def loadbalance = new SLoadBalanceType(target.loadBalance)
Modified:
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=658710&r1=658709&r2=658710&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ThrottlerTest.scala
(original)
+++
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ThrottlerTest.scala
Wed May 21 07:36:57 2008
@@ -42,13 +42,13 @@
val builder =
new RouteBuilder {
//START SNIPPET: simple
- "seda:a" throttle 3 per 2 seconds to ("mock:a")
+ "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 {
+ throttle (3 per 2 seconds) {
to ("mock:c")
}
}