SlideShare uma empresa Scribd logo
1 de 11
Baixar para ler offline
INTRODUCTION TO
                         PLAY 2


Monday, 4 February 13
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 Akka


Monday, 4 February 13
Scala

                    ‣ Created by Martin Odersky in 2004
                    ‣ Built on top of the JVM
                    ‣ Both functional and OO
                    ‣ Influenced by Haskell, Erlang, Smalltalk

Monday, 4 February 13
Play 2 core features
                    ‣ Hot reload
                    ‣ Testing frameworks: JUnit, Selenium
                    ‣ DB: Anorm, Ebean
                    ‣ Groovy: templates as simple functions
                    ‣ Sbt for dependency management
                    ‣ Akka
Monday, 4 February 13
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 2013



Monday, 4 February 13
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
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
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
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 promises

Monday, 4 February 13
JBoss Netty
                    ‣ Framework for writing async network
                        applications.

                    ‣ Support for:
                     ‣ SPDY
                     ‣ WebSockets
                    ‣ Different from Jetty (a servlet container)
Monday, 4 February 13
Thanks



Monday, 4 February 13

Mais conteúdo relacionado

Mais procurados

ReactiveCocoa in Practice
ReactiveCocoa in PracticeReactiveCocoa in Practice
ReactiveCocoa in PracticeOutware Mobile
 
An Introduction to Reactive Cocoa
An Introduction to Reactive CocoaAn Introduction to Reactive Cocoa
An Introduction to Reactive CocoaSmartLogic
 
Rxjava 介紹與 Android 中的 RxJava
Rxjava 介紹與 Android 中的 RxJavaRxjava 介紹與 Android 中的 RxJava
Rxjava 介紹與 Android 中的 RxJavaKros Huang
 
Reactive cocoa made Simple with Swift
Reactive cocoa made Simple with SwiftReactive cocoa made Simple with Swift
Reactive cocoa made Simple with SwiftColin Eberhardt
 
Reactive programming
Reactive programmingReactive programming
Reactive programmingJianbin LIN
 
Asynchronous JavaScript and Promises
Asynchronous JavaScript and Promises Asynchronous JavaScript and Promises
Asynchronous JavaScript and Promises Senthil Kumar
 
TDD - Test Driven Development in Swift (iOS) with Cuckoo, Quick and Nimble
TDD - Test Driven Development in Swift (iOS) with Cuckoo, Quick and NimbleTDD - Test Driven Development in Swift (iOS) with Cuckoo, Quick and Nimble
TDD - Test Driven Development in Swift (iOS) with Cuckoo, Quick and NimbleJianbin LIN
 
RxJava 2.0 介紹
RxJava 2.0 介紹RxJava 2.0 介紹
RxJava 2.0 介紹Kros Huang
 
Async JavaScript in ES7
Async JavaScript in ES7Async JavaScript in ES7
Async JavaScript in ES7Mike North
 
The Future of Futures - A Talk About Java 8 CompletableFutures
The Future of Futures - A Talk About Java 8 CompletableFuturesThe Future of Futures - A Talk About Java 8 CompletableFutures
The Future of Futures - A Talk About Java 8 CompletableFuturesHaim Yadid
 
ReactiveCocoa and Swift, Better Together
ReactiveCocoa and Swift, Better TogetherReactiveCocoa and Swift, Better Together
ReactiveCocoa and Swift, Better TogetherColin Eberhardt
 
jimmy hacking (at) Microsoft
jimmy hacking (at) Microsoftjimmy hacking (at) Microsoft
jimmy hacking (at) MicrosoftJimmy Schementi
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot CampTroy Miles
 
Ship your Scala code often and easy with Docker
Ship your Scala code often and easy with DockerShip your Scala code often and easy with Docker
Ship your Scala code often and easy with DockerMarcus Lönnberg
 
OB1K - New, Better, Faster, Devops Friendly Java container by Outbrain
OB1K - New, Better, Faster, Devops Friendly Java container by OutbrainOB1K - New, Better, Faster, Devops Friendly Java container by Outbrain
OB1K - New, Better, Faster, Devops Friendly Java container by OutbrainEran Harel
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at TwitterAlex Payne
 

Mais procurados (20)

ReactiveCocoa in Practice
ReactiveCocoa in PracticeReactiveCocoa in Practice
ReactiveCocoa in Practice
 
Rx java in action
Rx java in actionRx java in action
Rx java in action
 
An Introduction to Reactive Cocoa
An Introduction to Reactive CocoaAn Introduction to Reactive Cocoa
An Introduction to Reactive Cocoa
 
RxJava Applied
RxJava AppliedRxJava Applied
RxJava Applied
 
Kotlin workshop
Kotlin workshopKotlin workshop
Kotlin workshop
 
Rxjava 介紹與 Android 中的 RxJava
Rxjava 介紹與 Android 中的 RxJavaRxjava 介紹與 Android 中的 RxJava
Rxjava 介紹與 Android 中的 RxJava
 
Reactive cocoa made Simple with Swift
Reactive cocoa made Simple with SwiftReactive cocoa made Simple with Swift
Reactive cocoa made Simple with Swift
 
Reactive programming
Reactive programmingReactive programming
Reactive programming
 
Asynchronous JavaScript and Promises
Asynchronous JavaScript and Promises Asynchronous JavaScript and Promises
Asynchronous JavaScript and Promises
 
TDD - Test Driven Development in Swift (iOS) with Cuckoo, Quick and Nimble
TDD - Test Driven Development in Swift (iOS) with Cuckoo, Quick and NimbleTDD - Test Driven Development in Swift (iOS) with Cuckoo, Quick and Nimble
TDD - Test Driven Development in Swift (iOS) with Cuckoo, Quick and Nimble
 
RxJava 2.0 介紹
RxJava 2.0 介紹RxJava 2.0 介紹
RxJava 2.0 介紹
 
Async JavaScript in ES7
Async JavaScript in ES7Async JavaScript in ES7
Async JavaScript in ES7
 
The Future of Futures - A Talk About Java 8 CompletableFutures
The Future of Futures - A Talk About Java 8 CompletableFuturesThe Future of Futures - A Talk About Java 8 CompletableFutures
The Future of Futures - A Talk About Java 8 CompletableFutures
 
ReactiveCocoa and Swift, Better Together
ReactiveCocoa and Swift, Better TogetherReactiveCocoa and Swift, Better Together
ReactiveCocoa and Swift, Better Together
 
jimmy hacking (at) Microsoft
jimmy hacking (at) Microsoftjimmy hacking (at) Microsoft
jimmy hacking (at) Microsoft
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
 
Ship your Scala code often and easy with Docker
Ship your Scala code often and easy with DockerShip your Scala code often and easy with Docker
Ship your Scala code often and easy with Docker
 
OB1K - New, Better, Faster, Devops Friendly Java container by Outbrain
OB1K - New, Better, Faster, Devops Friendly Java container by OutbrainOB1K - New, Better, Faster, Devops Friendly Java container by Outbrain
OB1K - New, Better, Faster, Devops Friendly Java container by Outbrain
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
Atomic System Containers
Atomic System ContainersAtomic System Containers
Atomic System Containers
 

Destaque

Sim based mobile wallet
Sim based mobile walletSim based mobile wallet
Sim based mobile walletJobin Jose
 
From Here to the Dream
From Here to the DreamFrom Here to the Dream
From Here to the DreamKarl Banks
 
Renal cell carcinoma. 2015
Renal cell carcinoma. 2015Renal cell carcinoma. 2015
Renal cell carcinoma. 2015Montse Carrere
 

Destaque (6)

Sim based mobile wallet
Sim based mobile walletSim based mobile wallet
Sim based mobile wallet
 
Play 2 pip
Play 2 pipPlay 2 pip
Play 2 pip
 
From Here to the Dream
From Here to the DreamFrom Here to the Dream
From Here to the Dream
 
Renal cell carcinoma. 2015
Renal cell carcinoma. 2015Renal cell carcinoma. 2015
Renal cell carcinoma. 2015
 
Imf & world bank
Imf & world bankImf & world bank
Imf & world bank
 
Presentation1
Presentation1Presentation1
Presentation1
 

Semelhante a Introduction to Play 2

Akka Actor presentation
Akka Actor presentationAkka Actor presentation
Akka Actor presentationGene Chang
 
The dark side of Akka and the remedy - bp.scala meetup
The dark side of Akka and the remedy - bp.scala meetupThe dark side of Akka and the remedy - bp.scala meetup
The dark side of Akka and the remedy - bp.scala meetupkrivachy
 
JSUG - Java FX by Christoph Pickl
JSUG - Java FX by Christoph PicklJSUG - Java FX by Christoph Pickl
JSUG - Java FX by Christoph PicklChristoph Pickl
 
Akka Futures and Akka Remoting
Akka Futures  and Akka RemotingAkka Futures  and Akka Remoting
Akka Futures and Akka RemotingKnoldus Inc.
 
Pure Java RAD and Scaffolding Tools Race
Pure Java RAD and Scaffolding Tools RacePure Java RAD and Scaffolding Tools Race
Pure Java RAD and Scaffolding Tools RaceBaruch Sadogursky
 
Java Programming Must implement a storage manager that main.pdf
Java Programming Must implement a storage manager that main.pdfJava Programming Must implement a storage manager that main.pdf
Java Programming Must implement a storage manager that main.pdfadinathassociates
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7Deniz Oguz
 
Our challenge for Bulkload reliability improvement
Our challenge for Bulkload reliability  improvementOur challenge for Bulkload reliability  improvement
Our challenge for Bulkload reliability improvementSatoshi Akama
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevMattias Karlsson
 
Akka lsug skills matter
Akka lsug skills matterAkka lsug skills matter
Akka lsug skills matterSkills Matter
 
Scaling Web Apps with Akka
Scaling Web Apps with AkkaScaling Web Apps with Akka
Scaling Web Apps with AkkaMaciej Matyjas
 
Module design pattern i.e. express js
Module design pattern i.e. express jsModule design pattern i.e. express js
Module design pattern i.e. express jsAhmed Assaf
 
Advanced akka features
Advanced akka featuresAdvanced akka features
Advanced akka featuresGrzegorz Duda
 
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...Paul King
 
Concurrency and scalability with akka
Concurrency and scalability  with akkaConcurrency and scalability  with akka
Concurrency and scalability with akkaBardia Heydari
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvmIsaias Barroso
 

Semelhante a Introduction to Play 2 (20)

Akka Actor presentation
Akka Actor presentationAkka Actor presentation
Akka Actor presentation
 
How we're building Wercker
How we're building WerckerHow we're building Wercker
How we're building Wercker
 
The dark side of Akka and the remedy - bp.scala meetup
The dark side of Akka and the remedy - bp.scala meetupThe dark side of Akka and the remedy - bp.scala meetup
The dark side of Akka and the remedy - bp.scala meetup
 
Spock
SpockSpock
Spock
 
1_JavIntro
1_JavIntro1_JavIntro
1_JavIntro
 
JSUG - Java FX by Christoph Pickl
JSUG - Java FX by Christoph PicklJSUG - Java FX by Christoph Pickl
JSUG - Java FX by Christoph Pickl
 
Akka Futures and Akka Remoting
Akka Futures  and Akka RemotingAkka Futures  and Akka Remoting
Akka Futures and Akka Remoting
 
Pure Java RAD and Scaffolding Tools Race
Pure Java RAD and Scaffolding Tools RacePure Java RAD and Scaffolding Tools Race
Pure Java RAD and Scaffolding Tools Race
 
Java Programming Must implement a storage manager that main.pdf
Java Programming Must implement a storage manager that main.pdfJava Programming Must implement a storage manager that main.pdf
Java Programming Must implement a storage manager that main.pdf
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7
 
Our challenge for Bulkload reliability improvement
Our challenge for Bulkload reliability  improvementOur challenge for Bulkload reliability  improvement
Our challenge for Bulkload reliability improvement
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
 
Akka lsug skills matter
Akka lsug skills matterAkka lsug skills matter
Akka lsug skills matter
 
Scaling Web Apps with Akka
Scaling Web Apps with AkkaScaling Web Apps with Akka
Scaling Web Apps with Akka
 
Module design pattern i.e. express js
Module design pattern i.e. express jsModule design pattern i.e. express js
Module design pattern i.e. express js
 
Advanced akka features
Advanced akka featuresAdvanced akka features
Advanced akka features
 
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
 
Concurrency and scalability with akka
Concurrency and scalability  with akkaConcurrency and scalability  with akka
Concurrency and scalability with akka
 
Scala - core features
Scala - core featuresScala - core features
Scala - core features
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvm
 

Introduction to Play 2

  • 1. INTRODUCTION TO PLAY 2 Monday, 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 Akka Monday, 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, Smalltalk Monday, 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 ‣ Akka Monday, 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 2013 Monday, 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 promises Monday, 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