forked from callistaenterprise/akka-cadec-2013
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
51 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,17 +10,24 @@ import akka.util.duration._ | |
|
||
object LogAgentApplication extends App { | ||
|
||
// ladda in konfiguration (agent/src/main/resources/application.conf) | ||
val config = ConfigFactory.load() | ||
|
||
// sätt hostname till det hostname som anges i konfigurationen för Akka Remote | ||
val hostname = config.getString("akka.remote.netty.hostname") | ||
|
||
// skapa och starta ett nytt actor system för agenten | ||
val system = ActorSystem("LogAgentActorSystem", config) | ||
|
||
// peka ut server-actorn som kör på ett annat remote actor system | ||
val server = system.actorFor("akka://[email protected]:2553/user/logServer") | ||
|
||
// skapa och starta LogAgent-actorn | ||
val agent = system.actorOf(Props(new LogAgent(hostname, server)), "logAgent") | ||
|
||
// skapa och starta reader-actorn som läser loggfilen | ||
// (läsningen simuleras och en slumpad logg skapas en gång i sekunden) | ||
val reader = system.actorOf(Props(new LogReaderSimulator(agent, 25)), "logReader") | ||
|
||
val scheduler = system.scheduler.schedule(1 seconds, 1 seconds, reader, Tick) | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 25 additions & 3 deletions
28
server/src/main/scala/se/callista/loganalyzer/server/WebSocketPresenter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,34 @@ | ||
package se.callista.loganalyzer.server | ||
|
||
import scala.collection.mutable.Map | ||
import akka.actor.Actor | ||
import se.callista.loganalyzer.Count | ||
import se.callista.loganalyzer.HttpStatus | ||
import unfiltered.netty.websockets.WebSocket | ||
|
||
class WebSocketPresenter (send: String => Unit) extends Actor { | ||
/** | ||
* Skickar ut Count-objekt till aktiva websockets | ||
*/ | ||
class WebSocketPresenter extends Actor { | ||
|
||
val counts = Map[HttpStatus, Count]() | ||
|
||
val sockets = Map[String, WebSocket]() | ||
|
||
def receive = { | ||
case c: Count => send(c.toJson) | ||
case c: Count => { | ||
counts += c.status -> c | ||
sockets.foreach{ case (_, s) => s.send(c.toJson)} | ||
} | ||
case StartSocket(id, s) => { | ||
sockets += id -> s | ||
counts.foreach{ case (_, c) => s.send(c.toJson)} | ||
} | ||
case StopSocket(id) => sockets -= id | ||
} | ||
|
||
} | ||
} | ||
|
||
case class StartSocket (id: String, webSocket: WebSocket) | ||
|
||
case class StopSocket (id: String) |