Introduction to Play 2

  • 342 views
Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
342
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
4
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. INTRODUCTION TO PLAY 2Monday, 4 February 13
  • 2. Play Framework ‣ Play 1 released 2008 only with Java support ‣ Play 2 released March 2012 ‣ Totally rebuilt with Scala ‣ Inspired by Rails ‣ Now part of the Typesafe Framework including Scala and AkkaMonday, 4 February 13
  • 3. Scala ‣ Created by Martin Odersky in 2004 ‣ Built on top of the JVM ‣ Both functional and OO ‣ Influenced by Haskell, Erlang, SmalltalkMonday, 4 February 13
  • 4. Play 2 core features ‣ Hot reload ‣ Testing frameworks: JUnit, Selenium ‣ DB: Anorm, Ebean ‣ Groovy: templates as simple functions ‣ Sbt for dependency management ‣ AkkaMonday, 4 February 13
  • 5. Akka ‣ Actor library for Java and Scala ‣ Inspired by the Erlang actors model ‣ Defines also Future and Promises now part of the Scala language as of v2.10 released Jan 4 2013Monday, 4 February 13
  • 6. Actors import akka.actor.Actor import akka.actor.Props import akka.event.Logging class MyActor extends Actor { val log = Logging(context.system, this) def receive = { case "test" => log.info("received test") case _ => log.info("received unknown message") } } object Main extends App { val system = ActorSystem("MySystem") val myActor = system.actorOf(Props[MyActor], name = "myactor") myActor ! "test" }Monday, 4 February 13
  • 7. Futures With actors import scala.concurrent.Future import akka.pattern.ask val future: Future[String] = ask(actor, msg).mapTo[String] Directly val f: Future[List[String]] = future { session.getRecentPosts } f onComplete { case Success(posts) => for (post <- posts) println(post) case Failure(t) => println("An error has occured: " + t.getMessage) }Monday, 4 February 13
  • 8. Promises import scala.concurrent.{ future, promise } import scala.concurrent.ExecutionContext.Implicits.global val p = promise[T] val f = p.future val producer = future { val r = produceSomething() p success r continueDoingSomethingUnrelated() } val consumer = future { startDoingSomething() f onSuccess { case r => doSomethingWithResult() } }Monday, 4 February 13
  • 9. Usage in Play 2.0.4 def index = Action { val promiseOfInt: Promise[Int] = Akka.future { intensiveComputation() } Async { promiseOfInt.map(i => Ok("Got result: " + i)) } } Play 2.1 will use Scala promisesMonday, 4 February 13
  • 10. JBoss Netty ‣ Framework for writing async network applications. ‣ Support for: ‣ SPDY ‣ WebSockets ‣ Different from Jetty (a servlet container)Monday, 4 February 13
  • 11. ThanksMonday, 4 February 13