# HG changeset patch # User Tomas Zeman # Date 1437744700 -7200 # Node ID 04af787ba66ffa614581d1c22af2483cd1f3cf3b # Parent 1e78bb2c0c84ea7b77f7a1bd11c0a4b40f68d798 Configuration via config-annotation diff -r 1e78bb2c0c84 -r 04af787ba66f .hgignore --- a/.hgignore Fri Jul 24 07:36:09 2015 +0000 +++ b/.hgignore Fri Jul 24 15:31:40 2015 +0200 @@ -3,3 +3,4 @@ .*.sw* *.class target +src/main/resources/settings.conf diff -r 1e78bb2c0c84 -r 04af787ba66f build.sbt --- a/build.sbt Fri Jul 24 07:36:09 2015 +0000 +++ b/build.sbt Fri Jul 24 15:31:40 2015 +0200 @@ -16,6 +16,9 @@ , "io.spray" %% "spray-json" % sprayVer , "com.typesafe.akka" %% "akka-actor" % akkaVer , "com.typesafe.akka" %% "akka-slf4j" % akkaVer +, "com.wacai" %% "config-annotation" % "0.3.2" ) +addCompilerPlugin("org.scalamacros" % "paradise" % "2.0.1" cross CrossVersion.full) + Revolver.settings diff -r 1e78bb2c0c84 -r 04af787ba66f src/main/resources/application.conf --- a/src/main/resources/application.conf Fri Jul 24 07:36:09 2015 +0000 +++ b/src/main/resources/application.conf Fri Jul 24 15:31:40 2015 +0200 @@ -1,3 +1,5 @@ +include "settings.conf" + spray { can.client { idle-timeout = 90 s diff -r 1e78bb2c0c84 -r 04af787ba66f src/main/scala/Example.scala --- a/src/main/scala/Example.scala Fri Jul 24 07:36:09 2015 +0000 +++ b/src/main/scala/Example.scala Fri Jul 24 15:31:40 2015 +0200 @@ -2,6 +2,7 @@ import akka.actor._ import spray.http.Uri +import com.typesafe.config.ConfigFactory object LoggingActor extends Actor with ActorLogging { log.info("Initializing LoggingActor") @@ -10,18 +11,29 @@ } } -object Example extends App { +object Example extends App with settings { val system = ActorSystem() val stream = system.actorOf(Props(new ChangesStreamActor( system.actorOf(Props(LoggingActor))))) - stream ! Uri("http://localhost:5984/example/_changes").withQuery( + def config = ConfigFactory.load() + + stream ! Uri(s"${couchConf.url}/_changes").withQuery( "feed" -> "continuous" - , "heartbeat" -> "5000" + , "heartbeat" -> couchConf.heartbeat.toMillis.toString , "include_docs" -> "true" ) } +import com.wacai.config.annotation._ +import scala.concurrent.duration._ +@conf trait settings extends Configurable { + val couchConf = new { + val url = "http://localhost:5984/example" + val heartbeat = 5 seconds + } +} + // vim: set ts=2 sw=2 et: