Hi +1
Thanks for taking care of this. On Mon, Oct 27, 2014 at 2:11 AM, Willem Jiang <willem.ji...@gmail.com> wrote: > Hi Claus, > > Thanks for point that out. > I just did some clean up of the autoStartup DSL, now you can only setup the > autoStartup as old Java DSL does. > > Regards, > > -- > Willem Jiang > > Red Hat, Inc. > Web: http://www.redhat.com > Blog: http://willemjiang.blogspot.com (English) > http://jnn.iteye.com (Chinese) > Twitter: willemjiang > Weibo: 姜宁willem > > > > On October 26, 2014 at 11:06:57 PM, Claus Ibsen (claus.ib...@gmail.com) wrote: >> -1 >> >> This is not as correct as autoStartup is already defined in the Java >> DSL at route definition. We should not add it to processor defintion >> as then its too verbose in the DSL, as it becomes visible where it >> makes no sense, eg from X to Y to Z ... autoStartup... >> >> So remove it from processor definition and find another way to add it >> to the Scala DSL. >> >> And btw this is also wrong >> >> public Type autoStartup(String autoStartup) { >> + return autoStartup(Boolean.valueOf(autoStartup)); >> + } >> >> That should use Camels property placeholder as the string is intended >> as a placeholder key etc. >> >> >> On Sun, Oct 26, 2014 at 9:51 AM, wrote: >> > Repository: camel >> > Updated Branches: >> > refs/heads/master 34e6970f1 -> 595976d1d >> > >> > >> > CAMEL-7961 Add autoStartup into 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/595976d1 >> > Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/595976d1 >> > Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/595976d1 >> > >> > Branch: refs/heads/master >> > Commit: 595976d1dd302760ea1d3cfe0fb34c85be41597a >> > Parents: 34e6970 >> > Author: Willem Jiang >> > Authored: Sun Oct 26 16:51:33 2014 +0800 >> > Committer: Willem Jiang >> > Committed: Sun Oct 26 16:51:33 2014 +0800 >> > >> > ---------------------------------------------------------------------- >> > .../apache/camel/model/ProcessorDefinition.java | 19 +++++ >> > .../scala/org/apache/camel/scala/dsl/DSL.scala | 5 ++ >> > .../camel/scala/dsl/SAbstractDefinition.scala | 5 ++ >> > .../camel/scala/dsl/builder/RouteBuilder.scala | 5 ++ >> > .../camel/scala/dsl/AutoStartupTest.scala | 80 ++++++++++++++++++++ >> > 5 files changed, 114 insertions(+) >> > ---------------------------------------------------------------------- >> > >> > >> > http://git-wip-us.apache.org/repos/asf/camel/blob/595976d1/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 a6a8457..a3b05cd 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 >> > @@ -893,6 +893,21 @@ public abstract class ProcessorDefinition >> > return to(ExchangePattern.InOut, endpoints); >> > } >> > >> > + public Type autoStartup(String autoStartup) { >> > + return autoStartup(Boolean.valueOf(autoStartup)); >> > + } >> > + >> > + public Type autoStartup(boolean autoStartup) { >> > + ProcessorDefinition def = this; >> > + >> > + RouteDefinition route = ProcessorDefinitionHelper.getRoute(def); >> > + if (route != null) { >> > + route.autoStartup(autoStartup); >> > + } >> > + >> > + return (Type) this; >> > + } >> > + >> > /** >> > * Sets the id of this node. >> > * > >> > @@ -1003,6 +1018,10 @@ public abstract class ProcessorDefinition >> > return answer; >> > } >> > >> > + public Type noAutoStartup() { >> > + return autoStartup(false); >> > + } >> > + >> > /** >> > * Pipes and Filters >> EIP: >> > * Creates a {@link Pipeline} so that the message >> > >> > http://git-wip-us.apache.org/repos/asf/camel/blob/595976d1/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 9900246..e061f78 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 >> > @@ -49,6 +49,9 @@ trait DSL { >> > >> > def handle[E <: Throwable : ClassTag](block: => Unit) : >> > SOnExceptionDefinition[E] >> > >> > + def autoStartup(autoStartup :String) : DSL >> > + def autoStartup(autoStartup :Boolean) : DSL >> > + >> > def id(id : String): DSL >> > def idempotentConsumer(expression: Exchange => Any): >> > SIdempotentConsumerDefinition >> > def inOnly: DSL with Block >> > @@ -64,6 +67,8 @@ trait DSL { >> > def marshal(format : DataFormatDefinition) : DSL >> > def multicast : SMulticastDefinition >> > >> > + def noAutoStartup() : DSL >> > + >> > def onCompletion : SOnCompletionDefinition >> > def onCompletion(predicate: Exchange => Boolean) : SOnCompletionDefinition >> > def onCompletion(config: Config[SOnCompletionDefinition]) : >> > SOnCompletionDefinition >> > >> > http://git-wip-us.apache.org/repos/asf/camel/blob/595976d1/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 275b6d0..280cf99 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 >> > @@ -77,6 +77,9 @@ abstract class SAbstractDefinition[P <: >> > ProcessorDefinition[_]] >> extends DSL with >> > >> > def handle[E <: Throwable : ClassTag](block: => Unit) = >> > SOnExceptionDefinition[E](target.onException(classTag[E].runtimeClass.asInstanceOf[Class[E]])).apply(block) >> > >> > + def autoStartup(autoStartup: String) = >> > wrap(target.autoStartup(autoStartup)) >> > + def autoStartup(autoStartup: Boolean) = >> > wrap(target.autoStartup(autoStartup)) >> > + >> > def id(id : String) = wrap(target.id(id)) >> > def idempotentConsumer(expression: Exchange => Any) = >> > SIdempotentConsumerDefinition(target.idempotentConsumer(expression, >> null)) >> > @Deprecated >> > @@ -94,6 +97,8 @@ abstract class SAbstractDefinition[P <: >> > ProcessorDefinition[_]] >> extends DSL with >> > def marshal(format: DataFormatDefinition) = wrap(target.marshal(format)) >> > def multicast = SMulticastDefinition(target.multicast) >> > >> > + def noAutoStartup() = wrap(target.autoStartup(false)) >> > + >> > def onCompletion: SOnCompletionDefinition = { >> > val completion = SOnCompletionDefinition(target.onCompletion) >> > // let's end the block in the Java DSL, we have a better way of handling >> > blocks here >> > >> > http://git-wip-us.apache.org/repos/asf/camel/blob/595976d1/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 5d68b63..b1aaad4 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 >> > @@ -125,6 +125,9 @@ class RouteBuilder extends Preamble with DSL with >> > RoutesBuilder >> with Languages w >> > >> > def filter(predicate: Exchange => Any) = stack.top.filter(predicate) >> > >> > + def autoStartup(autoStartup :String) = stack.top.autoStartup(autoStartup) >> > + def autoStartup(autoStartup :Boolean) = >> > stack.top.autoStartup(autoStartup) >> > + >> > def id(id : String) = stack.top.id(id) >> > def idempotentConsumer(expression: Exchange => Any) = >> > stack.top.idempotentConsumer(expression) >> > def inOnly = stack.top.inOnly >> > @@ -152,6 +155,8 @@ class RouteBuilder extends Preamble with DSL with >> > RoutesBuilder >> with Languages w >> > def marshal(format: DataFormatDefinition) = stack.top.marshal(format) >> > def multicast = stack.top.multicast >> > >> > + def noAutoStartup() = stack.top.autoStartup(false) >> > + >> > def onCompletion = { >> > stack.size match { >> > case 0 => SOnCompletionDefinition(builder.onCompletion)(this) >> > >> > http://git-wip-us.apache.org/repos/asf/camel/blob/595976d1/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/AutoStartupTest.scala >> > ---------------------------------------------------------------------- >> > diff --git >> > a/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/AutoStartupTest.scala >> b/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/AutoStartupTest.scala >> > new file mode 100644 >> > index 0000000..b70c29e >> > --- /dev/null >> > +++ >> > b/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/AutoStartupTest.scala >> > @@ -0,0 +1,80 @@ >> > +/** >> > + * 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.ServiceStatus >> > +import org.apache.camel.ServiceStatus.{Started, Stopped} >> > +import org.apache.camel.builder.RouteBuilder >> > +import org.apache.camel.scala.dsl >> > +import org.apache.camel.scala.dsl.AutoStartupTest._ >> > +import org.apache.camel.test.junit4.CamelTestSupport >> > +import org.scalatest.{BeforeAndAfterAll, FunSuiteLike} >> > + >> > +class AutoStartupTest extends CamelTestSupport with FunSuiteLike with >> > BeforeAndAfterAll >> { >> > + >> > + override protected def createRouteBuilders(): Array[RouteBuilder] = { >> > + Array( >> > + createRoute(_ from s"direct:start1" id withoutDslRouteId to >> > "mock:output"), >> > + createRoute(_ from s"direct:start2" id booleanDslRouteId autoStartup >> > false to >> "mock:output"), >> > + createRoute(_ from s"direct:start3" id stringDslRouteId autoStartup >> > "false" >> to "mock:output"), >> > + createRoute(_ from s"direct:start4" id noAutoStartupDslRouteId >> > noAutoStartup() >> to "mock:output") >> > + ) >> > + } >> > + >> > + override def beforeAll: Unit = { >> > + setUp() >> > + } >> > + >> > + test("route without auto startup dsl, is started by default") { >> > + assertRouteStatus(withoutDslRouteId, Started) >> > + } >> > + >> > + test("route with auto startup dsl using 'false' boolean, is stopped") { >> > + assertRouteStatus(booleanDslRouteId, Stopped) >> > + } >> > + >> > + test("route with auto startup dsl using 'false' string, is stopped") { >> > + assertRouteStatus(stringDslRouteId, Stopped) >> > + } >> > + >> > + test("route with no auto startup dsl, is stopped") { >> > + assertRouteStatus(noAutoStartupDslRouteId, Stopped) >> > + } >> > + >> > + private def assertRouteStatus(routeId: String, status: ServiceStatus) { >> > + assert(context().getRouteStatus(routeId) === status) >> > + } >> > + >> > + override protected def afterAll(): Unit = { >> > + tearDown() >> > + } >> > +} >> > + >> > +object AutoStartupTest { >> > + >> > + private val withoutDslRouteId: String = "without-dsl-route" >> > + private val booleanDslRouteId: String = "boolean-dsl-route" >> > + private val stringDslRouteId: String = "string-dsl-route" >> > + private val noAutoStartupDslRouteId: String = "no-auto-startup-dsl-route" >> > + >> > + private def createRoute(routeBuilderFunction: (dsl.builder.RouteBuilder) >> => Unit): RouteBuilder = >> > + new dsl.builder.RouteBuilder { >> > + routeBuilderFunction(this) >> > + }.builder >> > + >> > +} >> > + >> > >> >> >> >> -- >> Claus Ibsen >> ----------------- >> Red Hat, Inc. >> Email: cib...@redhat.com >> Twitter: davsclaus >> Blog: http://davsclaus.com >> Author of Camel in Action: http://www.manning.com/ibsen >> hawtio: http://hawt.io/ >> fabric8: http://fabric8.io/ >> > -- Claus Ibsen ----------------- Red Hat, Inc. Email: cib...@redhat.com Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen hawtio: http://hawt.io/ fabric8: http://fabric8.io/