Play 2 pip

13
INTRODUCTION TO PLAY 2.1 Thursday, 7 February 13

Transcript of Play 2 pip

Page 1: Play 2 pip

INTRODUCTION TO PLAY 2.1

Thursday, 7 February 13

Page 2: Play 2 pip

Matteo DepaloCTO and Co-Founder @ Responsa

Twitter: @matteodepaloGithub: matteodepalo

Thursday, 7 February 13

Page 3: Play 2 pip

Play Framework

• Play 1 released 2008 only with Java support

• Play 2 released March 2012, totally rebuilt with Scala

• Inspired by Rails and Django

• Now part of the Typesafe Framework including Scala and Akka

Thursday, 7 February 13

Page 4: Play 2 pip

Scala

• Created by Martin Odersky in 2004

• Built on top of the JVM

• Both functional and OO

• Influenced by Haskell, Erlang, Smalltalk

Thursday, 7 February 13

Page 5: Play 2 pip

Play 2 vs Rails defaultsPlay 2.1 Rails

Testing JUnit, Selenium TestUnit

ORM Anorm ActiveRecord

Templates Groovy ERB

Dependency management

SBT Bundler

Thursday, 7 February 13

Page 6: Play 2 pip

Folder structureRailsPlay

Thursday, 7 February 13

Page 7: Play 2 pip

ControllersRails Play

package controllers

import ...

object Posts extends Controller {

def index = Action { implicit request => Ok(views.html.rounds.index(Post.all())) }

}

class PostsController < ApplicationController def index @posts = Post.all

respond_to do |format| format.html end end

Thursday, 7 February 13

Page 8: Play 2 pip

Play 2.1 async features

• Asynchronous Results

• Streaming

• WebSockets

• Comet

Thursday, 7 February 13

Page 9: Play 2 pip

Asynchronous Results

def index = Action { val futureInt = scala.concurrent.Future { intensiveComputation() }

Async { futureInt.map(i => Ok("Got result: " + i)) }}

Thursday, 7 February 13

Page 10: Play 2 pip

Comet Socketsdef comet = Action { val events = Enumerator( """<script>console.log('kiki')</script>""", """<script>console.log('foo')</script>""", """<script>console.log('bar')</script>""" )

Ok.stream(events >>> Enumerator.eof).as(HTML)}

def comet = Action { val events = Enumerator("kiki", "foo", "bar") Ok.stream(events &> Comet(callback = "console.log"))}

Same thing with Play helpers

Thursday, 7 February 13

Page 11: Play 2 pip

Schedule tasks

import play.api.libs.concurrent.Execution.Implicits._

Akka.system.scheduler.schedule(0.seconds, 30.minutes, testActor, "tick"

)

Akka.system.scheduler.scheduleOnce(10.seconds) { file.delete()}

Thursday, 7 February 13

Page 12: Play 2 pip

JBoss Netty

• Framework for writing async network applications.

• Support for:

• SPDY

• WebSockets

Thursday, 7 February 13

Page 13: Play 2 pip

Thanks

Thursday, 7 February 13