Play 2 pip
-
Upload
matteo-depalo -
Category
Documents
-
view
141 -
download
3
Transcript of Play 2 pip
INTRODUCTION TO PLAY 2.1
Thursday, 7 February 13
Matteo DepaloCTO and Co-Founder @ Responsa
Twitter: @matteodepaloGithub: matteodepalo
Thursday, 7 February 13
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
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
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
Folder structureRailsPlay
Thursday, 7 February 13
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
Play 2.1 async features
• Asynchronous Results
• Streaming
• WebSockets
• Comet
Thursday, 7 February 13
Asynchronous Results
def index = Action { val futureInt = scala.concurrent.Future { intensiveComputation() }
Async { futureInt.map(i => Ok("Got result: " + i)) }}
Thursday, 7 February 13
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
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
JBoss Netty
• Framework for writing async network applications.
• Support for:
• SPDY
• WebSockets
Thursday, 7 February 13
Thanks
Thursday, 7 February 13