Permalink
Browse files

Updated to play 2.0 HEAD

You'll need to download and build this for yourself.
  • Loading branch information...
1 parent 5370cb7 commit 08d6a82f1e6376b475d9ea6e39f993b23332b24d @tackley committed Feb 9, 2012
@@ -25,7 +25,7 @@ object Api extends Controller {
def search(callback: Option[String], since: Long) = Action {
withCallback(callback) {
- val response = Backend.liveSearchTerms.get.filter(_.dt > since).sortBy(_.dt)
+ val response = Backend.liveSearchTerms.filter(_.dt > since).sortBy(_.dt)
Serialization.write(response)
}
}
@@ -35,7 +35,7 @@ object Api extends Controller {
def content(callback: Option[String], since: Long) = Action {
withCallback(callback) {
- val content = Backend.last24hoursOfContent.get.map { c =>
+ val content = Backend.last24hoursOfContent.map { c =>
ApiContent(
path = "/" + c.id,
title = c.webTitle,
@@ -22,7 +22,7 @@ object Application extends Controller {
private def publishedContent = {
val currentHits = Api.countsData
- Backend.last24hoursOfContent.get.map { c =>
+ Backend.last24hoursOfContent.map { c =>
PublishedContent(
c.webPublicationDate, c.webUrl, c.webTitle,
currentHits.get(c.webUrl).map(_.toString).getOrElse("0"),
View
@@ -1,26 +1,29 @@
package lib
-import akka.actor.Actor._
import java.util.concurrent.TimeUnit
-import akka.actor.{Supervisor, Scheduler}
-import akka.config.Supervision._
import com.gu.openplatform.contentapi.model.Content
import org.joda.time.{Duration, DateTime}
-
+import akka.actor._
+import akka.util.duration._
+import akka.dispatch.{Await, Future}
+import akka.util.Timeout
+import concurrent.ops
+import ops._
object Backend {
- val listener = actorOf[ClickStreamActor].start()
- val calculator = actorOf[Calculator].start()
- val searchTerms = actorOf[SearchTermActor].start()
- val latestContent = actorOf[LatestContentActor].start()
+ val system = ActorSystem("liveDashboard")
+ val listener = system.actorOf(Props[ClickStreamActor], name = "clickStreamListener")
+ val calculator = system.actorOf(Props[Calculator], name = "calculator")
+ val searchTerms = system.actorOf(Props[SearchTermActor], name = "searchTermProcessor")
+ val latestContent = system.actorOf(Props[LatestContentActor], name = "latestContent")
val mqReader = new MqReader(listener :: searchTerms :: Nil)
def start() {
- Scheduler.restart()
- Scheduler.schedule(listener, TruncateClickStream(), 1, 1, TimeUnit.MINUTES)
- Scheduler.schedule(listener, SendClickStreamTo(calculator), 5, 5, TimeUnit.SECONDS)
- Scheduler.schedule(latestContent, LatestContentActor.Refresh(), 5, 10, TimeUnit.SECONDS)
+ system.scheduler.schedule(1 minute, 1 minute, listener, TruncateClickStream())
+ system.scheduler.schedule(5 seconds, 5 seconds, listener, SendClickStreamTo(calculator))
+ system.scheduler.schedule(5 seconds, 10 seconds, latestContent, LatestContentActor.Refresh())
+
spawn {
mqReader.start()
}
@@ -30,23 +33,26 @@ object Backend {
}
def stop() {
- Scheduler.shutdown()
mqReader.stop()
- listener.stop()
+ system.shutdown()
}
// So this is a bad way to do this, should use akka Agents instead (which can read
// without sending a message.)
- def currentStats = (calculator ? GetStats()).as[(List[HitReport], ListsOfStuff)]
+ implicit val timeout = Timeout(5 seconds)
+
+ def currentStats = Await.result( (calculator ? GetStats()).mapTo[(List[HitReport], ListsOfStuff)], 5 seconds)
- def currentLists = currentStats.map(_._2).get
+ def currentLists = currentStats._2
- def currentHits = currentStats.map(_._1).get
+ def currentHits = currentStats._1
- def liveSearchTerms = (searchTerms ? GetSearchTerms()).as[List[GuSearchTerm]]
+ def liveSearchTermsFuture = (searchTerms ? GetSearchTerms()).mapTo[List[GuSearchTerm]]
+ def liveSearchTerms = Await.result(liveSearchTermsFuture, timeout.duration)
- def last24hoursOfContent = (latestContent ? LatestContentActor.Get()).as[List[Content]]
+ def last24hoursOfContentFuture = (latestContent ? LatestContentActor.Get()).mapTo[List[Content]]
+ def last24hoursOfContent = Await.result(last24hoursOfContentFuture, timeout.duration)
def minutesOfData = {
val currentData = currentLists
@@ -23,7 +23,7 @@ class Calculator extends Actor {
listsOfStuff = listsOfStuff.diff(currentTopPaths, cs)
log.info("Done")
- case GetStats() => self.channel ! (currentTopPaths, listsOfStuff)
+ case GetStats() => sender ! (currentTopPaths, listsOfStuff)
}
@@ -1,7 +1,6 @@
package lib
import akka.actor._
-import akka.event.EventHandler
import collection.GenSeq
import org.scala_tools.time.Imports._
@@ -32,7 +31,7 @@ case class ClickStream(allClicks: GenSeq[Event], lastUpdated: DateTime, firstUpd
}
-class ClickStreamActor extends Actor {
+class ClickStreamActor extends Actor with ActorLogging {
var clickStream = ClickStream(Nil.par, DateTime.now, DateTime.now)
protected def receive = {
@@ -41,12 +40,12 @@ class ClickStreamActor extends Actor {
}
case TruncateClickStream() => {
- EventHandler.info(this, "Truncating click stream (size=%d)" format clickStream.allClicks.size)
+ log.info("Truncating click stream (size=%d)" format clickStream.allClicks.size)
clickStream = clickStream.removeEventsBefore(DateTime.now - 15.minutes)
- EventHandler.info(this, "Truncated click stream (size=%d)" format clickStream.allClicks.size)
+ log.info("Truncated click stream (size=%d)" format clickStream.allClicks.size)
}
- case GetClickStream() => self.channel ! clickStream
+ case GetClickStream() => sender ! clickStream
case SendClickStreamTo(actor) => actor ! clickStream
@@ -41,7 +41,7 @@ class LatestContentActor extends Actor {
log("Content list is now " + latestContent.size + " entries")
case LatestContentActor.Get() =>
- self.channel ! latestContent
+ sender ! latestContent
}
@@ -28,8 +28,7 @@ class SearchTermActor extends Actor {
}
}
- case GetSearchTerms() =>
- self.channel ! terms
+ case GetSearchTerms() => sender ! terms
}
}
@@ -1,11 +1,15 @@
# This is the main configuration file for the application.
# ~~~~~
+akka {
+ logConfigOnStart = on
+}
+
# Secret key
# ~~~~~
# The secret key is used to secure cryptographics functions.
# If you deploy your application to several instances be sure to use the same key!
-application.secret=Cc0eVK<CaTIWUm2`Y7lM23Cpp11dRiM[ZbZCSg9UZaVuxeLI^7I=vUDnuNr9:U:y
+application.secret="Cc0eVK<CaTIWUm2`Y7lM23Cpp11dRiM[ZbZCSg9UZaVuxeLI^7I=vUDnuNr9:U:y"
# Logger
# ~~~~~
View
@@ -9,7 +9,6 @@ object ApplicationBuild extends Build {
val appDependencies = Seq(
"org.zeromq" %% "zeromq-scala-binding" % "0.0.3",
- "se.scalablesolutions.akka" % "akka-actor" % "1.2",
"org.scala-tools.time" %% "time" % "0.5",
"com.gu.openplatform" %% "content-api-client" % "1.13",
"org.joda" % "joda-convert" % "1.1" % "provided",
@@ -1 +1 @@
-sbt.version=0.11.0
+sbt.version=0.11.2
View
@@ -4,4 +4,5 @@ resolvers ++= Seq(
"Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
)
-libraryDependencies += "play" %% "play" % "2.0-beta"
+addSbtPlugin("play" % "sbt-plugin" % "2.0-RC1-SNAPSHOT")
+

0 comments on commit 08d6a82

Please sign in to comment.