title: Play framework, Akka: actor communication with controller
body: <p>In short - I'm building a Scala/Play application which will monitor certain files/folders for changes and use Server Sent Events to push data to the browser.</p>
  
  <p>I'm using <a href="https://github.com/mcaserta/swatch" rel="nofollow noreferrer">Swatch</a> library to do the monitoring which launches with application. This is my <code>Global</code> object. It starts the monitoring by launching a worker actor (as far as I understand) and reports if there are any changes - it's working just fine:</p>
  
  <pre><code>import akka.actor.{Props, ActorSystem}
  import play.api._
  import play.api.libs.concurrent.Akka
  import play.api.Play.current
  import include.Swatch._
  import include.SwatchActor
  
  object Global extends GlobalSettings {
  
      override def onStart(app: Application) {
          Logger.info("Application has started")
          val swatch = Akka.system.actorOf(Props[SwatchActor])
          swatch ! Watch("/folder/path", Seq(Create, Modify, Delete), true)
      }
  
  }
  </code></pre>
  
  <p>At the moment whenever a change happens the <code>swatch</code> actor just outputs this to the console:</p>
  
  <pre><code>[INFO] [02/14/2014 11:45:04.377] [application-akka.actor.default-dispatcher-3] [akka://application/deadLetters] Message [include.Swatch$Create] from Actor[akka://application/deadLetters] to Actor[akka://application/deadLetters] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
  </code></pre>
  
  <p>This is my controller (so far it's not doing much):</p>
  
  <pre><code>package controllers
  
  import play.api._
  import play.api.mvc._
  
  object Application extends Controller {
  
      def index = Action {
          Ok("index")
      }
  
  }
  </code></pre>
  
  <p>The browser should establish a connection with the controller and then whenever my worker actor detects a change, server push to the browser happens. My problem so far is: how do I get my worker actor to send messages to my <code>index</code> action in the controller? Would the approach I've described above work at all?</p>
  
  <p><strong>UPDATE:</strong> I'll be using websockets to communicate with the browser. Another important thing - the worker actor must be running all the time despite of if there is an established communication with the browser or not.</p>
  
  <p><strong>UPDATE2:</strong> Thanks to drexin and others I've managed to scrape together a <a href="https://stackoverflow.com/questions/21851444/scala-play-akka-websocket-how-to-pass-actor-messages-through-websocket/21859404#21859404">solution</a>.</p>