SlideShare a Scribd company logo
1 of 13
Download to read offline
INTRODUCTION TO
                         PLAY 2.1


Thursday, 7 February 13
Matteo Depalo
                          CTO and Co-Founder @ Responsa

                              Twitter: @matteodepalo
                               Github: 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 defaults
                                         Play 2.1          Rails

                           Testing    JUnit, Selenium     TestUnit

                            ORM          Anorm          ActiveRecord

                          Templates      Groovy             ERB

                   Dependency
                                           SBT            Bundler
                   management


Thursday, 7 February 13
Folder structure
                           Play       Rails




Thursday, 7 February 13
Controllers
                          Rails                                               Play

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

           respond_to do |format|                      object Posts extends Controller {
            format.html
           end                                             def index = Action { implicit request =>
          end                                                Ok(views.html.rounds.index(Post.all()))
                                                           }

                                                       }




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 Sockets
                          def 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)
                          }



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



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

More Related Content

What's hot

Automating with ansible (Part A)
Automating with ansible (Part A)Automating with ansible (Part A)
Automating with ansible (Part A)iman darabi
 
Puppet Availability and Performance at 100K Nodes - PuppetConf 2014
Puppet Availability and Performance at 100K Nodes - PuppetConf 2014Puppet Availability and Performance at 100K Nodes - PuppetConf 2014
Puppet Availability and Performance at 100K Nodes - PuppetConf 2014Puppet
 
Apache Provisionr (incubating) - Bucharest JUG 10
Apache Provisionr (incubating) - Bucharest JUG 10Apache Provisionr (incubating) - Bucharest JUG 10
Apache Provisionr (incubating) - Bucharest JUG 10Andrei Savu
 
Foreman in your datacenter
Foreman in your datacenterForeman in your datacenter
Foreman in your datacenterlzap
 
Jenkins and ansible reference
Jenkins and ansible referenceJenkins and ansible reference
Jenkins and ansible referencelaonap166
 
Managing your SaltStack Minions with Foreman
Managing your SaltStack Minions with ForemanManaging your SaltStack Minions with Foreman
Managing your SaltStack Minions with ForemanStephen Benjamin
 
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017Jumping Bean
 

What's hot (7)

Automating with ansible (Part A)
Automating with ansible (Part A)Automating with ansible (Part A)
Automating with ansible (Part A)
 
Puppet Availability and Performance at 100K Nodes - PuppetConf 2014
Puppet Availability and Performance at 100K Nodes - PuppetConf 2014Puppet Availability and Performance at 100K Nodes - PuppetConf 2014
Puppet Availability and Performance at 100K Nodes - PuppetConf 2014
 
Apache Provisionr (incubating) - Bucharest JUG 10
Apache Provisionr (incubating) - Bucharest JUG 10Apache Provisionr (incubating) - Bucharest JUG 10
Apache Provisionr (incubating) - Bucharest JUG 10
 
Foreman in your datacenter
Foreman in your datacenterForeman in your datacenter
Foreman in your datacenter
 
Jenkins and ansible reference
Jenkins and ansible referenceJenkins and ansible reference
Jenkins and ansible reference
 
Managing your SaltStack Minions with Foreman
Managing your SaltStack Minions with ForemanManaging your SaltStack Minions with Foreman
Managing your SaltStack Minions with Foreman
 
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
 

Viewers also liked

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

Viewers also liked (6)

From Here to the Dream
From Here to the DreamFrom Here to the Dream
From Here to the Dream
 
Introduction to Play 2
Introduction to Play 2Introduction to Play 2
Introduction to Play 2
 
Sim based mobile wallet
Sim based mobile walletSim based mobile wallet
Sim based mobile wallet
 
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
 

Similar to Introduction to Play 2.1 Framework Under 40 Characters

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
 
Riak intro with azure
Riak   intro with azureRiak   intro with azure
Riak intro with azureAdron Hall
 
TorqueBox - When Java meets Ruby
TorqueBox - When Java meets RubyTorqueBox - When Java meets Ruby
TorqueBox - When Java meets RubyBruno Oliveira
 
Using Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBUsing Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBHiro Asari
 
Improving Your Heroku App Performance with Asset CDN and Unicorn
Improving Your Heroku App Performance with Asset CDN and UnicornImproving Your Heroku App Performance with Asset CDN and Unicorn
Improving Your Heroku App Performance with Asset CDN and UnicornSimon Bagreev
 
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
 
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013Arun Gupta
 
Javascript in the cloud
Javascript in the cloudJavascript in the cloud
Javascript in the cloudMostafa Eweda
 
Frozen Rails Slides
Frozen Rails SlidesFrozen Rails Slides
Frozen Rails Slidescarllerche
 
Introduction to node.js by Ran Mizrahi @ Reversim Summit
Introduction to node.js by Ran Mizrahi @ Reversim SummitIntroduction to node.js by Ran Mizrahi @ Reversim Summit
Introduction to node.js by Ran Mizrahi @ Reversim SummitRan Mizrahi
 
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
 
Intro to JavaScript Testing
Intro to JavaScript TestingIntro to JavaScript Testing
Intro to JavaScript TestingRan Mizrahi
 
An introduction to OSGi
An introduction to OSGi An introduction to OSGi
An introduction to OSGi Andrea Chiodoni
 
JSUG - Java FX by Christoph Pickl
JSUG - Java FX by Christoph PicklJSUG - Java FX by Christoph Pickl
JSUG - Java FX by Christoph PicklChristoph Pickl
 

Similar to Introduction to Play 2.1 Framework Under 40 Characters (20)

RubyConf 2009
RubyConf 2009RubyConf 2009
RubyConf 2009
 
Java 7 workshop
Java 7 workshopJava 7 workshop
Java 7 workshop
 
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
 
Riak intro with azure
Riak   intro with azureRiak   intro with azure
Riak intro with azure
 
TorqueBox - When Java meets Ruby
TorqueBox - When Java meets RubyTorqueBox - When Java meets Ruby
TorqueBox - When Java meets Ruby
 
Using Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBUsing Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRB
 
Improving Your Heroku App Performance with Asset CDN and Unicorn
Improving Your Heroku App Performance with Asset CDN and UnicornImproving Your Heroku App Performance with Asset CDN and Unicorn
Improving Your Heroku App Performance with Asset CDN and Unicorn
 
Devignition 2011
Devignition 2011Devignition 2011
Devignition 2011
 
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
 
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013
 
Javascript in the cloud
Javascript in the cloudJavascript in the cloud
Javascript in the cloud
 
Frozen Rails Slides
Frozen Rails SlidesFrozen Rails Slides
Frozen Rails Slides
 
Introduction to node.js by Ran Mizrahi @ Reversim Summit
Introduction to node.js by Ran Mizrahi @ Reversim SummitIntroduction to node.js by Ran Mizrahi @ Reversim Summit
Introduction to node.js by Ran Mizrahi @ Reversim Summit
 
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...
 
Railsconf 2010
Railsconf 2010Railsconf 2010
Railsconf 2010
 
Rails Intro & Tutorial
Rails Intro & TutorialRails Intro & Tutorial
Rails Intro & Tutorial
 
Intro to JavaScript Testing
Intro to JavaScript TestingIntro to JavaScript Testing
Intro to JavaScript Testing
 
An introduction to OSGi
An introduction to OSGi An introduction to OSGi
An introduction to OSGi
 
JSUG - Java FX by Christoph Pickl
JSUG - Java FX by Christoph PicklJSUG - Java FX by Christoph Pickl
JSUG - Java FX by Christoph Pickl
 

Introduction to Play 2.1 Framework Under 40 Characters

  • 1. INTRODUCTION TO PLAY 2.1 Thursday, 7 February 13
  • 2. Matteo Depalo CTO and Co-Founder @ Responsa Twitter: @matteodepalo Github: matteodepalo Thursday, 7 February 13
  • 3. 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
  • 4. 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
  • 5. Play 2 vs Rails defaults Play 2.1 Rails Testing JUnit, Selenium TestUnit ORM Anorm ActiveRecord Templates Groovy ERB Dependency SBT Bundler management Thursday, 7 February 13
  • 6. Folder structure Play Rails Thursday, 7 February 13
  • 7. Controllers Rails Play class PostsController < ApplicationController package controllers def index @posts = Post.all import ... respond_to do |format| object Posts extends Controller { format.html end def index = Action { implicit request => end Ok(views.html.rounds.index(Post.all())) } } Thursday, 7 February 13
  • 8. Play 2.1 async features • Asynchronous Results • Streaming • WebSockets • Comet Thursday, 7 February 13
  • 9. Asynchronous Results def index = Action { val futureInt = scala.concurrent.Future { intensiveComputation() } Async { futureInt.map(i => Ok("Got result: " + i)) } } Thursday, 7 February 13
  • 10. Comet Sockets def 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) } Same thing with Play helpers def comet = Action { val events = Enumerator("kiki", "foo", "bar") Ok.stream(events &> Comet(callback = "console.log")) } Thursday, 7 February 13
  • 11. 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
  • 12. JBoss Netty • Framework for writing async network applications. • Support for: • SPDY • WebSockets Thursday, 7 February 13