Play with-the-framework

1,328 views

Published on

A presentation about play framework that was presented at Java user group meeting

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,328
On SlideShare
0
From Embeds
0
Number of Embeds
438
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Play with-the-framework

  1. 1. with the frameworkK.Gautam
  2. 2. About Play!Launched in 2008Open SourceJava
  3. 3. About play!Stateless server side architectureBonus points if you guess relation between thepicture and this slide
  4. 4. About play !No servlet API ! Naan Appadiye Shock Aaiten
  5. 5. About play !Full stack web framework
  6. 6. About play !Inspired by
  7. 7. PhilosophySimpleEfficientDRYConvention over configurationShare nothing
  8. 8. Why no servlets ? Sessionrequests Database Session Thread Pool
  9. 9. In play ! Database Worker Threads
  10. 10. Play is stateless in the server STATE Play serverBrowser Database Play server Encrypted cookie
  11. 11. Sessions and CacheSession is play! can store only 4KTo store objects use Cache
  12. 12. Getting startedModelsControllersViews
  13. 13. ModelsSupports JPA @Entity public class Product { public String name; public Integer price; }
  14. 14. Controllerspackage controllers;import models.Client;import play.mvc.Controller;public class Clients extends Controller { public static void show(Long id) { Client client = Client.findById(id); render(client); } public static void delete(Long id) { Client client = Client.findById(id); client.delete(); }}
  15. 15. ViewsGroovy template engineExpressions: ${…}<h1>Client ${client.name}</h1>Scripts: %{…}%%{ fullName = client.name.toUpperCase()+ +client.forname;}%<h1>Client ${fullName}</h1>
  16. 16. Views contd..Actions: @{…}<h1>Client ${client.name}</h1><p> <a href="@{Clients.showAccounts(client.id)}">All accounts</a></p><hr /><a href="@{Clients.index()}">Back</a>
  17. 17. JobsPlaying with Jobspackage jobs;import play.jobs.*;public class MyJob extends Job { public void doJob() { // execute some application logic here ... }}Image courtesy http://static.themetapicture.com/media/funny-Steve-Jobs-cool-photo.jpg
  18. 18. Resulting Jobspackage jobs;import play.jobs.*;public class MyJob extends Job<String> { public String doJobWithResult() { // execute some application logic here ... return result; }}
  19. 19. Timed Jobsimport play.jobs.*;@Every("1h")public class Bootstrap extends Job { public void doJob() { List<User> newUsers = User.find("newAccount = true") .fetch(); for(User user : newUsers) { Notifier.sayWelcome(user); } }}
  20. 20. Asynchronous HTTPpublic static void generatePDF(Long reportId) { Promise<InputStream> pdf = new ReportAsPDFJob(report).now(); InputStream pdfStream = await(pdf); renderBinary(pdfStream);}
  21. 21. Websocketspublic static void echo() { while(inbound.isOpen()) { WebSocketEvent e = await(inbound.nextEvent()); for(String quit: TextFrame.and(Equals("quit")).match(e)) { outbound.send("Bye!"); disconnect(); } for(String msg: TextFrame.match(e)) { outbound.send("Echo: %s", frame.textData); } for(WebSocketClose closed: SocketClosed.match(e)) { Logger.info("Socket closed!"); } }}
  22. 22. Dependency Managementdependencies.yml# Application dependenciesrequire: - play 1.2 - com.google.guava -> guava r07play dependencies --sync
  23. 23. Deployment optionsplay start mysuperwebapp
  24. 24. JEE Application serversplay war myapp -o myapp.war
  25. 25. Cloud based hosting● AWS elastic Beanstalk● Google appEngine● Heroku● Cloud Foundry● Openshift DIY● May be even Windows Azure
  26. 26. Copyright NoticeI do not own any of the images.All images are copyright of the respectiveowners.I just found them on the internetIf you are the owner of any of the imagesthank you for your permission.
  27. 27. Thank you !

×