Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Play Support in Cloud Foundry

1,815 views

Published on

Play Support in Cloud Foundry

  • Be the first to comment

Play Support in Cloud Foundry

  1. 1. Building Play 2.0Applications onCloudFoundryRajdeep DuaDirector, DevRel VMware India@rajdeepdua
  2. 2. Why Play?
  3. 3. For years PHP, Ruby developers have been laughing at Java developersevery time they change and refresh the page
  4. 4. ..and all of us evolve GrailsJVM Servlets JEE Spring Play
  5. 5. ..and all of us evolve GrailsJVM Servlets JEE Spring Play
  6. 6. Play doesn’t fight HTTP or the Browser
  7. 7. Play doesn’t fight HTTP or the Browser Stateless, HTTP Centric, Easier development lifecycle
  8. 8. Play 2.0 Overview
  9. 9. Play 2.0 Overview• Web framework written in Java and Scala
  10. 10. Play 2.0 Overview• Web framework written in Java and Scala• Not built on top of Servlet APIs
  11. 11. Play 2.0 Overview• Web framework written in Java and Scala• Not built on top of Servlet APIs• Statically typed MVC Architecture
  12. 12. Play 2.0 Overview• Web framework written in Java and Scala• Not built on top of Servlet APIs• Statically typed MVC Architecture• Asynchronous HTTP Programming Model
  13. 13. Play 2.0 Overview• Web framework written in Java and Scala• Not built on top of Servlet APIs• Statically typed MVC Architecture• Asynchronous HTTP Programming Model• Client side templating in Scala
  14. 14. Play 2.0 Overview• Web framework written in Java and Scala• Not built on top of Servlet APIs• Statically typed MVC Architecture• Asynchronous HTTP Programming Model• Client side templating in Scala• Server side code in Java or Scala
  15. 15. Anatomy of a Play 2.0 Application -app App sources -conf Configuration files -dist Zip file deployed to Cloud Foundry -logs Logs -project sbt project files -public public assets( js, css) -target Generated sources
  16. 16. MVC• Model : Domain Object Models map to a persistence store• Views :Rendered content using templates• Controller : Routes Http requests using ActionS
  17. 17. Play Architecture• Built as an extension of JBoss Netty Server• All the requests are Asynch -- using nio• Core Play is a pure Scala app which runs in a JVM• Stateless on the Server side
  18. 18. Play Application at Runtime
  19. 19. Play App Support in Cloud Foundry• Supports Play as one of the frameworks• Auto-detected by vmc• Support mysql and Postgres databases
  20. 20. Lifecycle of a Play app in CloudFoundry Install Play
  21. 21. Lifecycle of a Play app in CloudFoundry Install PlayDevelop/Test Locally
  22. 22. Lifecycle of a Play app in CloudFoundry Install Play $play new myappDevelop/Test Locally [myapp]$run
  23. 23. Lifecycle of a Play app in CloudFoundry Install Play $play new myappDevelop/Test Locally [myapp]$run Deploy on Cloud Foundry
  24. 24. Lifecycle of a Play app in CloudFoundry Install Play $play new myappDevelop/Test Locally [myapp]$run Deploy on Cloud $vmc push --path=dist/ myapp.zip Foundry
  25. 25. Sample App
  26. 26. Todo List
  27. 27. App Structure : Router # Home page GET / controllers.Application.index() # Map static resources from the /public folder to the /assets URL path GET /assets/*file controllers.Assets.at(path="/public", file) # Tasks GET /tasks controllers.Application.tasks() POST /tasks controllers.Application.newTask() POST /tasks/:id/delete controllers.Application.deleteTask(id: Long)
  28. 28. App Structure : Controller public class Application extends Controller { public static Result index() {} public static Result tasks() {} public static Result newTask() {} public static Result deleteTask( Long id) {} }
  29. 29. App Structure : Model @Entity public class Task extends Model { @Id public Long id; @Required public String label; public static Finder<Long,Task> find = new Finder(...); public static void create(Task task) { task.save(); } }
  30. 30. AppStructure :View • Scala based template • Compiled into a scala function with render method@(tasks: List[Task], taskForm: Form[Task])@import helper._@main("Todo list") { <h1>@tasks.size() task(s)</h1> ....
  31. 31. Create a Task
  32. 32. List all the Tasks
  33. 33. Delete a Task
  34. 34. Demo
  35. 35. Summary
  36. 36. Summary• Play 2.0 takes a new approach to Web app development in Java world
  37. 37. Summary• Play 2.0 takes a new approach to Web app development in Java world• Simplifies the development cycle
  38. 38. Summary• Play 2.0 takes a new approach to Web app development in Java world• Simplifies the development cycle• Frameworks should not fight HTTP but embrace it
  39. 39. Questions

×