Permalink
Browse files

Cleaning up import and unused HubActor

  • Loading branch information...
1 parent 0040dcf commit 6bdbdb82b7cd2df3b735ab6f76312e0a32cc8b11 @kelvl kelvl committed Apr 28, 2013
@@ -1,14 +1,12 @@
package com.twilio.shadow
-import akka.actor.{Actor, ActorSystem, Props}
+import akka.actor.{ActorSystem, Props}
import spray.io.{SingletonHandler, IOExtension}
import spray.can.server.{ServerSettings, HttpServer}
-import spray.io.IOServer.{Bound, Bind}
-import spray.can.client.{HttpClient, ClientSettings, DefaultHttpClient}
-import com.yammer.metrics.Metrics
+import spray.io.IOServer.Bind
+import spray.can.client.{HttpClient, ClientSettings}
import com.yammer.metrics.core.MetricsRegistry
import com.typesafe.config.ConfigFactory
-import spray.http.HttpResponse
object Boot extends App{
@@ -1,79 +0,0 @@
-package com.twilio.shadow
-
-import akka.actor.{ActorRef, Actor}
-import spray.util.SprayActorLogging
-import scala.collection.mutable
-import spray.http.{FormData, HttpRequest, HttpResponse}
-import spray.httpx.unmarshalling._
-import org.json4s.JsonDSL._
-import org.json4s.native.JsonMethods._
-
-case class Register(eventSourceActor: ActorRef)
-case class UnRegister(eventSourceActor: ActorRef)
-case class Broadcast(message: AnyRef)
-
-class HubActor extends Actor with SprayActorLogging {
-
- val eventSources = mutable.HashSet[ActorRef]()
-
- def receive = {
- case Register(sseActor) => {
- eventSources += sseActor
-
- log.info(s"Registering actor $sseActor")
- }
- case UnRegister(sseActor) => {
- eventSources -= sseActor
- log.info(s"UnRegistering actor $sseActor")
- }
-
- case Broadcast(entry: ShadowEntry) => {
- val jsonStr = compact(render(shadowEntryJson(entry)))
- eventSources.foreach( _ ! jsonStr )
- }
- }
-
-
- def shadowEntryJson(entry: ShadowEntry) = {
- val req = httpRequestToJson(entry.request)
-
- val json =
- ("request" -> (
- ("original" -> req) ~
- ("modified" -> req)
- )) ~
- ("results" -> List(entry.responses._1, entry.responses._2).map( x => httpResponseToJson(x._1) ~ ("elapsed_time" -> x._2) ))
-
- json
- }
-
- def httpRequestToJson(httpRequest: HttpRequest) = {
-
- val request = httpRequest.parseAll
-
- val formParams = request.entity.as[FormData].fold( fa => Map[String, String](), fb => fb.fields)
-
- val queryParams = request.queryParams
-
- val json =
- ("url" -> request.path) ~
- ("headers" -> request.headers.map { x => x.name -> x.value }.toMap ) ~
- ("post" -> formParams) ~
- ("method" -> request.method.value) ~
- ("get" -> queryParams)
- json
- }
-
- def httpResponseToJson(httpResponse: HttpResponse) = {
-
- val json =
- ("headers" -> httpResponse.headers.map { x => (
- (x.name -> x.value)
- ) }.toMap) ~
- ("status_code" -> httpResponse.status.value) ~
- ("type" -> "http_response") ~
- ("body" -> httpResponse.entity.asString)
- json
- }
-
-}
@@ -2,7 +2,6 @@ package com.twilio.shadow
import akka.actor.{ActorSystem, ActorRef, Actor}
import spray.routing._
-import spray.routing.directives.LoggingMagnet
import spray.can.client.HttpDialog
import com.yammer.metrics.core.{MetricsRegistry, Clock, Timer}
import scala.concurrent.{Promise, Future}
@@ -1,6 +1,6 @@
package com.twilio.shadow
-import akka.actor.{Props, ActorRef, Actor}
+import akka.actor.{Props, Actor}
import spray.routing._
import spray.http._
import spray.util.SprayActorLogging
@@ -17,7 +17,7 @@ import spray.httpx.RequestBuilding.Get
import scala.concurrent.Future
import java.util.concurrent.TimeUnit
import org.scalatest.concurrent.Futures
-import org.scalatest.time.{Span, SpanSugar}
+import org.scalatest.time.SpanSugar
import spray.io.SingletonHandler
import scala.util.Failure
import scala.util.Success

0 comments on commit 6bdbdb8

Please sign in to comment.