INTRODUCTION TO                         PLAY 2Monday, 4 February 13
Play Framework                    ‣ Play 1 released 2008 only with Java support                    ‣ Play 2 released March...
Scala                    ‣ Created by Martin Odersky in 2004                    ‣ Built on top of the JVM                 ...
Play 2 core features                    ‣ Hot reload                    ‣ Testing frameworks: JUnit, Selenium             ...
Akka                    ‣ Actor library for Java and Scala                    ‣ Inspired by the Erlang actors model       ...
Actors                        import akka.actor.Actor                        import akka.actor.Props                      ...
Futures                                            With actors                    import scala.concurrent.Future          ...
Promises                        import scala.concurrent.{ future, promise }                        import scala.concurrent...
Usage in Play 2.0.4            def index = Action {              val promiseOfInt: Promise[Int] = Akka.future {           ...
JBoss Netty                    ‣ Framework for writing async network                        applications.                 ...
ThanksMonday, 4 February 13
Upcoming SlideShare
Loading in...5
×

Introduction to Play 2

443

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
443
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Introduction to Play 2

  1. 1. INTRODUCTION TO PLAY 2Monday, 4 February 13
  2. 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. 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. 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. 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. 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. 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. 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. 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. 10. JBoss Netty ‣ Framework for writing async network applications. ‣ Support for: ‣ SPDY ‣ WebSockets ‣ Different from Jetty (a servlet container)Monday, 4 February 13
  11. 11. ThanksMonday, 4 February 13
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×