Play framework

5,037 views
4,469 views

Published on

1 Comment
10 Likes
Statistics
Notes
No Downloads
Views
Total views
5,037
On SlideShare
0
From Embeds
0
Number of Embeds
305
Actions
Shares
0
Downloads
94
Comments
1
Likes
10
Embeds 0
No embeds

No notes for slide

Play framework

  1. PLAY FRAMEWORK Introduction & highlights of v2.1
  2. WHO AM I? Andrew SkibaI work in Tikal as the leader of Java group.With over 50 Java experts, we meet, share, contribute, andcode together on a monthly basis.
  3. YES! WE START A NEW PROJECT!
  4. NEW PROJECT DILEMMA
  5. WITH RISK OF ENDING UP WITH POLYGLOT PROJECT WITH MIX OF LANGUAGES AND TECHNOLOGIES - OR EVEN REWRITING PARTS OF YOUR APPLICATION LATER...
  6. WHAT HAPPENED, TWITTER?• Bill Venners: I’m curious, and the Ruby folks will want it spelled out: Can you elaborate on what you felt the Ruby language lacked in the area of reliable, high performance code?• Steve Jenson: One of the things that I’ve found throughout my career is the need to have long-lived processes. And Ruby, like many scripting languages, has trouble being an environment for long lived processes. But the JVM is very good at that, because it’s been optimized for that over the last ten years.
  7. JAVA IS A SAFE CHOICEExcept the risk of dying while waiting for builds & redeployments, or maintaining XML configurations...
  8. CAN YOU HAVE YOUR CAKE AND EAT IT, TOO?
  9. PLAY FRAMEWORK Combine them all!
  10. STRONG & FASTFast turnaround - just save and refresh browser
  11. Text REACTIVEEvent driven non blocking IO
  12. SCALABLEStateless, non blocking, web-friendly architecture
  13. COMPLETEEasy things are easy, complicated things are possible
  14. DEMO OF А NEW PROJECT
  15. IT LOOKS LIKE A MAGIC!
  16. SO JAVA OR SCALA?
  17. FUNCTIONAL/OO BLEND
  18. val qsort: List[Int] => List[Int] = { case Nil => Nil case pivot :: tail => val (smaller, rest) = tail.partition(_ < pivot) qsort(smaller) ::: pivot :: qsort(rest) } EXPRESSIVENESS
  19. JAVA COMPATIBILITY
  20. UNPRECEDENTED TYPE SAFETY
  21. DSLS
  22. COMMUNITY
  23. NOUGH SAID!• Charles Nutter, creator of JRuby: "Scala, it must be stated, is the current heir apparent to the Java throne. No other language on the JVM seems as capable of being a "replacement for Java" as Scala, and the momentum behind Scala is now unquestionable."• James Strachan, creator of Groovy: "I can honestly say if someone had shown me the Programming in Scala book by by Martin Odersky, Lex Spoon & Bill Venners back in 2003 Id probably have never created Groovy."
  24. def index = Action { import play.api.libs.json._ val json = Json.obj( "status" -> "OK", "message" -> "Hello", "framework" -> Json.obj( "name" -> "Play")) val jsonTransformer = ( __ framework).json.update( __.read[JsObject].map { o => o ++ Json.obj("version" -> "2.1.0") }) Ok( json.transform(jsonTransformer).get ) } DEMO OF SCALA POWER New JSON API with REPL
  25. ORDER OF THINGS
  26. app → Application sources └ assets → Compiled asset sources └ stylesheets → Typically LESS CSS sources └ javascripts → Typically CoffeeScript sources └ controllers → Application controllers └ models → Application business layer └ views → Templatesconf → Configurationurations files and other non-compiledresources └ application.conf → Main configuration file └ routes → Routes definitionpublic → Public assets └ stylesheets → CSS files └ javascripts → Javascript files └ images → Image filesproject → sbt configuration files └ build.properties → Marker for sbt project └ Build.scala → Application build script └ plugins.sbt → sbt pluginsANATOMY OF A PLAY APPLICATION
  27. # The home pageGET / controllers.Projects.index# AuthenticationGET /login controllers.Application.loginPOST /login controllers.Application.authenticateGET /logout controllers.Application.logout# ...# TasksGET /projects/:project/tasks controllers.Tasks.index(project: Long)POST /projects/:project/tasks controllers.Tasks.add(project: Long, folder: String)PUT /tasks/:task controllers.Tasks.update(task: Long)DELETE /tasks/:task controllers.Tasks.delete(task: Long)# ...# Javascript routingGET /assets/javascripts/routes controllers.Application.javascriptRoutes# Map static resources from the /public folder to the /assets pathGET /assets/*file controllers.Assets.at(path="/public", file) POWERFUL URL ROUTING
  28. POWERFUL TEMPLATE ENGINE
  29. UNIFIED ERROR REPORTING
  30. TASTING MENU
  31. @org.springframework.stereotype.Servicepublic class HelloService { public String hello() { return "Hello world!"; }}//////////////////@org.springframework.stereotype.Controllerpublic class Application extends Controller { @Autowired private HelloService helloService; public Result index() { return ok(index.render(helloService.hello())); }} SPRING WITH PLAY
  32. DEMO OF REQUIREJS
  33. TESTINGincluding a browser simulator!
  34. in main project# The home pageGET / controllers.Application.index# Include a sub-project-> /my-subproject my.subproject.Routesin conf/my.subproject.routesGET / my.subproject.controllers.Application.indexnow just surf to /my-subproject and get calledmy.subproject.controllers.Application.index DEMO OF SUBROUTES
  35. val query = BSONDocument("firstName" -> BSONString("Jack"))// get a Cursor[DefaultBSONIterator]val cursor = collection.find(query)// lets enumerate this cursor and print a readable// representation of each document in the responsecursor.enumerate.apply(Iteratee.foreach { doc => println("found document: " + BSONDocument.pretty(doc))})// or, the same with getting a listval cursor2 = collection.find(query)val futurelist = cursor2.toListfuturelist.onSuccess { case list => val names = list.map(_.getAs[BSONString]("lastName").get.value) println("got names: " + names)}DEMO OF REACTIVE MONGO
  36. LINKS• http://www.playframework.com/ (Doh!)• http://typesafe.com/stack• http://blog.typesafe.com/scala-akka-and-play-framework-at-devoxx-2012• http://typesafe.com/public/case-studies/LinkedInCase_v8.pdf• http://docs.cloudfoundry.com/frameworks/play/java-mongodb.html• https://github.com/wsargent/play-2.0-spring-module• http://jonasboner.com/2008/10/06/real-world-scala-dependency-injection-di/

×