From 5e0b032bfef9509e64af2960452aed44b6e6cb22 Mon Sep 17 00:00:00 2001 From: Diego Parra Date: Tue, 26 Nov 2013 15:54:10 -0300 Subject: added scalariform --- .../main/scala/test/SimpleRequestProcessor.scala | 71 +++++++++++----------- 1 file changed, 34 insertions(+), 37 deletions(-) (limited to 'kamon-playground/src/main') diff --git a/kamon-playground/src/main/scala/test/SimpleRequestProcessor.scala b/kamon-playground/src/main/scala/test/SimpleRequestProcessor.scala index 7cdfae73..1c1dba4f 100644 --- a/kamon-playground/src/main/scala/test/SimpleRequestProcessor.scala +++ b/kamon-playground/src/main/scala/test/SimpleRequestProcessor.scala @@ -19,7 +19,7 @@ import akka.actor._ import spray.routing.SimpleRoutingApp import akka.util.Timeout import spray.httpx.RequestBuilding -import scala.concurrent.{Await, Future} +import scala.concurrent.{ Await, Future } import kamon.spray.UowDirectives import kamon.trace.Trace import kamon.Kamon @@ -34,7 +34,7 @@ object SimpleRequestProcessor extends App with SimpleRoutingApp with RequestBuil import system.dispatcher val act = system.actorOf(Props(new Actor { - def receive: Actor.Receive = { case any => sender ! any } + def receive: Actor.Receive = { case any ⇒ sender ! any } }), "com") implicit val timeout = Timeout(30 seconds) @@ -44,42 +44,42 @@ object SimpleRequestProcessor extends App with SimpleRoutingApp with RequestBuil val random = new Random() startServer(interface = "localhost", port = 9090) { get { - path("test"){ + path("test") { uow { complete { - val futures = pipeline(Get("http://10.254.209.14:8000/")).map(r => "Ok") :: pipeline(Get("http://10.254.209.14:8000/")).map(r => "Ok") :: Nil + val futures = pipeline(Get("http://10.254.209.14:8000/")).map(r ⇒ "Ok") :: pipeline(Get("http://10.254.209.14:8000/")).map(r ⇒ "Ok") :: Nil - Future.sequence(futures).map(l => "Ok") + Future.sequence(futures).map(l ⇒ "Ok") } } } ~ - path("reply" / Segment) { reqID => - uow { + path("reply" / Segment) { reqID ⇒ + uow { + complete { + if (Trace.context().isEmpty) + println("ROUTE NO CONTEXT") + + (replier ? reqID).mapTo[String] + } + } + } ~ + path("ok") { complete { - if (Trace.context().isEmpty) - println("ROUTE NO CONTEXT") - - (replier ? reqID).mapTo[String] + //Thread.sleep(random.nextInt(1) + random.nextInt(5) + random.nextInt(2)) + "ok" + } + } ~ + path("future") { + dynamic { + complete(Future { "OK" }) + } + } ~ + path("error") { + complete { + throw new NullPointerException + "okk" } } - } ~ - path("ok") { - complete{ - //Thread.sleep(random.nextInt(1) + random.nextInt(5) + random.nextInt(2)) - "ok" - } - } ~ - path("future") { - dynamic { - complete(Future { "OK" }) - } - } ~ - path("error") { - complete { - throw new NullPointerException - "okk" - } - } } } @@ -98,21 +98,18 @@ object Verifier extends App { val pipeline = sendReceive - val futures = Future.sequence(for(i <- 1 to 500) yield { - pipeline(Get("http://127.0.0.1:9090/reply/"+i)).map(r => r.entity.asString == i.toString) + val futures = Future.sequence(for (i ← 1 to 500) yield { + pipeline(Get("http://127.0.0.1:9090/reply/" + i)).map(r ⇒ r.entity.asString == i.toString) }) - println("Everything is: "+ Await.result(futures, 10 seconds).forall(a => a == true)) + println("Everything is: " + Await.result(futures, 10 seconds).forall(a ⇒ a == true)) } - - - } class Replier extends Actor with ActorLogging { def receive = { - case anything => - if(Trace.context.isEmpty) + case anything ⇒ + if (Trace.context.isEmpty) log.warning("PROCESSING A MESSAGE WITHOUT CONTEXT") log.info("Processing at the Replier") -- cgit v1.2.3