--- 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
--- 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
--- 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
--- 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: