play with-the-framework
DESCRIPTION
A presentation about play framework that was presented at Java user group meetingTRANSCRIPT
with the frameworkK.Gautam
About Play!Launched in 2008Open SourceJava
About play!Stateless server side architecture
Bonus points if you guess relation between the picture and this slide
No servlet API !
About play !
Naan Appadiye Shock Aaiten
About play !Full stack web framework
About play !Inspired by
PhilosophySimpleEfficientDRYConvention over configurationShare nothing
Why no servlets ?
Database
Session
Session
Thread Pool
requests
In play !
Database
Worker Threads
Play is stateless in the server
Browser
STATEPlay server
Play server
Database
Encrypted cookie
Sessions and CacheSession is play! can store only 4KTo store objects use Cache
Getting startedModelsControllersViews
ModelsSupports JPA
@Entitypublic class Product { public String name; public Integer price;}
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(); } }
ViewsGroovy template engineExpressions: ${…}
<h1>Client ${client.name}</h1>
Scripts: %{…}%
%{ fullName = client.name.toUpperCase()+' '+client.forname;}% <h1>Client ${fullName}</h1>
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>
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
Resulting Jobspackage jobs; import play.jobs.*; public class MyJob extends Job<String> { public String doJobWithResult() { // execute some application logic here ... return result; } }
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); } }}
Asynchronous HTTPpublic static void generatePDF(Long reportId) { Promise<InputStream> pdf =
new ReportAsPDFJob(report).now();
InputStream pdfStream = await(pdf); renderBinary(pdfStream);}
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!"); } }}
Dependency Managementdependencies.yml# Application dependenciesrequire: - play 1.2 - com.google.guava -> guava r07
play dependencies --sync
Deployment optionsplay start mysuperwebapp
JEE Application servers
play war myapp -o myapp.war
Cloud based hosting● AWS elastic Beanstalk● Google appEngine● Heroku● Cloud Foundry● Openshift DIY
● May be even Windows Azure
Copyright NoticeI do not own any of the images.All images are copyright of the respective owners.
I just found them on the internet
If you are the owner of any of the images thank you for your permission.
Thank you !