diff --git a/app/Global.scala b/app/Global.scala index 55b1d0f..27091b7 100644 --- a/app/Global.scala +++ b/app/Global.scala @@ -3,9 +3,9 @@ import model._ object Global extends GlobalSettings { override def onStart(app: Application) { - LookupApplication.startup() + // LookupApplication.startup() } override def onStop(app: Application) { - LookupApplication.shutdown() + // LookupApplication.shutdown() } } \ No newline at end of file diff --git a/app/controllers/Application.scala b/app/controllers/Application.scala index 4a21241..e08678d 100644 --- a/app/controllers/Application.scala +++ b/app/controllers/Application.scala @@ -2,13 +2,47 @@ package controllers import play.api._ import play.api.mvc._ +import play.api.libs.json._ + +import play.api.libs.iteratee._ +import play.api.libs.iteratee.Concurrent + +import scala.concurrent._ +import ExecutionContext.Implicits.global + +import scala.concurrent.duration._ +import akka.util.Timeout +import akka.pattern.ask import model._ -import ca.polymtl.log4900.eval._ + +import ca.polymtl.log4900.eval.Add +import ca.polymtl.log4900.eval.MathResult +import ca.polymtl.log4900.eval.AddResult object Application extends Controller { - def index = Action { - LookupApplication.doSomething(Add(100, 100)) - Ok(views.html.index("Your new application is ready.")) - } + implicit val timeout = Timeout(5 seconds) + + def index = Action { implicit request => + Ok(views.html.index(request)) + } + + def eval = WebSocket.using[JsValue] { implicit request => + val (enumerator, channel) = Concurrent.broadcast[JsValue] + + val in = Iteratee.foreach[JsValue](content => { + val op1 = (content \ "op1").as[Int] + val op2 = (content \ "op2").as[Int] + + (LookupApplication.actor ? Add(1, 1)).mapTo[MathResult] onComplete { + case(e) => println("fail") + } +// } onSuccess { +// case AddResult(o1,o2,res) => println(s"$o1 + $o2 = $res") +// } + }) + + (in, enumerator) + } + } \ No newline at end of file diff --git a/app/model/Calculator.scala b/app/model/Calculator.scala index f7b692f..e118860 100644 --- a/app/model/Calculator.scala +++ b/app/model/Calculator.scala @@ -12,9 +12,9 @@ import akka.actor.ReceiveTimeout import ca.polymtl.log4900.eval._ object LookupApplication extends Bootable { - val system = ActorSystem("LookupApplication", ConfigFactory.load.getConfig("remotelookup")) - val remotePath = "akka.tcp://CalculatorApplication@127.0.0.1:2552/user/simpleCalculator" - val actor = system.actorOf(Props(classOf[LookupActor], remotePath), "lookupActor") + lazy val system = ActorSystem("LookupApplication", ConfigFactory.load.getConfig("remotelookup")) + lazy val remotePath = "akka.tcp://CalculatorApplication@127.0.0.1:2552/user/simpleCalculator" + lazy val actor = system.actorOf(Props(classOf[LookupActor], remotePath), "lookupActor") def doSomething(op: MathOp): Unit = actor ! op diff --git a/app/views/index.scala.html b/app/views/index.scala.html index bd36568..ea2136f 100644 --- a/app/views/index.scala.html +++ b/app/views/index.scala.html @@ -1,5 +1,11 @@ -@(message: String) +@(implicit request: RequestHeader) -@main("Welcome") { -