I have an actor who starts with the application, works in the background, looking at certain changes, and if there are any messages about them. At the moment this is just println for the console. What I need to do is when a new message appears - send it to the forefront using Websocket.
This is my Play Global object, in which the monitoring / listening executor is launched:
object Global extends GlobalSettings { override def onStart(app: Application) { class Listener extends Actor { //This needs to be changed to pass messages to Websocket, how? def receive = { case Create(path) => println("CREATE " + path) case Delete(path) => println("DELETE " + path) case Modify(path) => println("MODIFY " + path) } } val listener = Akka.system.actorOf(Props[Listener], "listener") val swatch = Akka.system.actorOf(Props[SwatchActor], "swatch") swatch ! Watch("/folder/path", Seq(Create, Modify, Delete), true, Some(listener)) } }
This is my play controller:
object Application extends Controller { def test = WebSocket.using[String] { request => //This hopefully gets the listener actor reference? val listener = Akka.system.actorSelection("/user/listener") val (out, channel) = Concurrent.broadcast[String] val in = Iteratee.foreach[String] { msg => //Actor messages must be pushed here, how? channel push("RESPONSE: " + msg) } (in, out) } }
I understand that in order to establish a connection with websocket, there must be an initial "in".
So my problems are:
- How do I change the
Listener actor to type messages in Websocket? - What do I need to do to prepare an actor for clicking messages after establishing a connection to a web socket?
- How do I click messages from a listener on a website?
Caballero
source share