SlideShare ist ein Scribd-Unternehmen logo
1 von 40
Downloaden Sie, um offline zu lesen
Play Framework
Mahmut Karakaya
Agenda
- Theory
- What Play Solves
- Architecture
- Play History
- Web Evolution
Agenda
- Practice
- Simple MVC operations
- NIO
- Scala
Waiting...
Threads
Factory classes
Play is not based on Java EE
MVC
Play
- full stack web framework for JVM
- fun and high productive
- change code hit reload ( forget jRebel )
- browser error reporting
- easy cloud deployment (e.g. Heroku)
- stateless
Play 0.x - 05.2007
Play 1.0 - 05.2008
Play 1.2 - 04.2011
Play 2.0 - 03.2012
Notable websites using Play
The Web Evolved
- Static (just html)
- Dynamic (get date from server on page :) )
* Structured (mvc, jsp, jsf )
- Realtime (ajax)
Realtime Web
- Polling (req - res)
- Long polling (req - res when changed)
- Server sent events (req - res -res -res)
- Websocket (req - res - res - req -res
whatever)
1 request = 1 thread
NIO 1 request != 1 thread
Demo
- Create new application
- Download latest activator
https://www.playframework.com/download
play new demo
play ~run
http://localhost:9000
IDE support
play eclipse
play idea
Application Layout
Controller
public class HelloWorld extends Controller{
public static Result index(){
return ok("Hello World");
}
}
conf / routes
GET /hello
controllers.HelloWorld.index()
Controller - add a parameter
public static Result helloName(String name){
return ok("Hello World: "+ name);
}
conf / routes - add a parameter
GET /helloName
controllers.HelloWorld.helloName(name)
http://localhost:9000/helloName?
name=TestUser
conf / routes - add a parameter to URL
GET /helloName/:name
controllers.HelloWorld.helloName(name)
http://localhost:9000/hello/TestUser
Controller - parameter type check
public class HelloWorld extends Controller{
public static Result helloNameAge(String name, int
age){
return ok("Hello World "+name +” you are ”
+age);
}
}
conf / routes - parameter type check
GET /hello/:name/:age
controllers.HelloWorld.helloNameAge(name:String,age:Int)
http://localhost:9000/hello/TestUser/10
Add a view
@(name: String, age:Int)
@main("Welcome to Play") {
<html>
<head></head>
<body>
<p>
Hello <b> @name</b>, you are <b>@age</b> years old
</p>
</body>
</html>
}
Controller - call view
public class HelloWorld extends Controller{
public static Result index(String name, int age){
return ok(views.html.helloWorld.render(name,age));
}
}
Error handling
WS lib for non-blocking http call
public static Result callGoogle() {
play.libs.F.Promise<play.libs.WS.Response> response=WS.url("http://google.com" ).get();
Promise<Result> result= response.map(toResult);
return async(result);
}
NIO parallel call example - non blocking call
public static Promise<Timing> timedRequest( final String url){
final long start = System.currentTimeMillis();
Promise<Response> res= WS.url(url).get();
return res.map(new Function<Response,Timing> (){
public Timing apply (Response response){
long latency=System.currentTimeMillis() -start;
return new Timing(url,latency,start);
}
});
}
NIO parallel call example - non blocking call
public static Result index(){
Promise<List<Timing>> all= Promise.waitAll(
Timing.timedRequest("http://www.yahoo.com"),
Timing.timedRequest("http://www.google.com"),
Timing.timedRequest("http://www.bing.com")
);
return async(all.map(new play.libs.F.Function<List<Timing>,Result>(){
public Result apply(List<Timing> timings){
return ok (play.libs.Json.toJson(timings));
}
}));}
NIO parallel call example - result
[{"url":"http://www.yahoo.com" ,"latency":1542,"start":1408296474891},
{"url":"http://www.google.com" ,"latency":366,"start":1408296474912},
{"url":"http://www.bing.com" ,"latency":437,"start":1408296474913}]
Scala
object HelloWorldScala extends Controller {
def index = Action {
Ok("Hello World Scala")
}
}
Scala Console
play console
import controllers.HelloWorld
HelloWorld.hello
Heroku supports Play
heroku create
heroku git:remote -a playAppForHeroku
git push heroku master
Reference
- https://www.playframework.com/
- Play For Scala (Manning)
- Learning Play! Framework 2 (Andy Petrella)
- Play For Java (Manning)
- People like Sadek Drobi, Yevgeniy Brikman,
James Ward :)
Thank you
Codes are available at;
https://github.com/mkarakaya/playDemo.git

Weitere ähnliche Inhalte

Was ist angesagt?

Design & Performance - Steve Souders at Fastly Altitude 2015
Design & Performance - Steve Souders at Fastly Altitude 2015Design & Performance - Steve Souders at Fastly Altitude 2015
Design & Performance - Steve Souders at Fastly Altitude 2015Fastly
 
VCL template abstraction model and automated deployments to Fastly
VCL template abstraction model and automated deployments to FastlyVCL template abstraction model and automated deployments to Fastly
VCL template abstraction model and automated deployments to FastlyFastly
 
Groovy example in mule
Groovy example in muleGroovy example in mule
Groovy example in muleMohammed246
 
Netty - anfix tech&beers
Netty - anfix tech&beersNetty - anfix tech&beers
Netty - anfix tech&beersjorgecarabias
 
Advanced VCL: how to use restart
Advanced VCL: how to use restartAdvanced VCL: how to use restart
Advanced VCL: how to use restartFastly
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js ExpressEyal Vardi
 
Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}.toster
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to NodejsGabriele Lana
 
Performance and stability testing \w Gatling
Performance and stability testing \w GatlingPerformance and stability testing \w Gatling
Performance and stability testing \w GatlingDmitry Vrublevsky
 
Automating OSD and Post-OSD Configuration with Powershell and Orchestrator
Automating OSD and Post-OSD Configuration with Powershell and OrchestratorAutomating OSD and Post-OSD Configuration with Powershell and Orchestrator
Automating OSD and Post-OSD Configuration with Powershell and OrchestratorDigicomp Academy AG
 
Java Play RESTful ebean
Java Play RESTful ebeanJava Play RESTful ebean
Java Play RESTful ebeanFaren faren
 
Java Play Restful JPA
Java Play Restful JPAJava Play Restful JPA
Java Play Restful JPAFaren faren
 
Service worker: discover the next web game changer
Service worker: discover the next web game changerService worker: discover the next web game changer
Service worker: discover the next web game changerSandro Paganotti
 
Network Automation: Ansible 102
Network Automation: Ansible 102Network Automation: Ansible 102
Network Automation: Ansible 102APNIC
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsMarcus Frödin
 

Was ist angesagt? (20)

Design & Performance - Steve Souders at Fastly Altitude 2015
Design & Performance - Steve Souders at Fastly Altitude 2015Design & Performance - Steve Souders at Fastly Altitude 2015
Design & Performance - Steve Souders at Fastly Altitude 2015
 
VCL template abstraction model and automated deployments to Fastly
VCL template abstraction model and automated deployments to FastlyVCL template abstraction model and automated deployments to Fastly
VCL template abstraction model and automated deployments to Fastly
 
Groovy example in mule
Groovy example in muleGroovy example in mule
Groovy example in mule
 
Netty - anfix tech&beers
Netty - anfix tech&beersNetty - anfix tech&beers
Netty - anfix tech&beers
 
Advanced VCL: how to use restart
Advanced VCL: how to use restartAdvanced VCL: how to use restart
Advanced VCL: how to use restart
 
Express js
Express jsExpress js
Express js
 
Node.js - A Quick Tour
Node.js - A Quick TourNode.js - A Quick Tour
Node.js - A Quick Tour
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to Nodejs
 
Ansible - Introduction
Ansible - IntroductionAnsible - Introduction
Ansible - Introduction
 
Process file one after another
Process file one after anotherProcess file one after another
Process file one after another
 
Performance and stability testing \w Gatling
Performance and stability testing \w GatlingPerformance and stability testing \w Gatling
Performance and stability testing \w Gatling
 
Mule esb :Data Weave
Mule esb :Data WeaveMule esb :Data Weave
Mule esb :Data Weave
 
Automating OSD and Post-OSD Configuration with Powershell and Orchestrator
Automating OSD and Post-OSD Configuration with Powershell and OrchestratorAutomating OSD and Post-OSD Configuration with Powershell and Orchestrator
Automating OSD and Post-OSD Configuration with Powershell and Orchestrator
 
Java Play RESTful ebean
Java Play RESTful ebeanJava Play RESTful ebean
Java Play RESTful ebean
 
Java Play Restful JPA
Java Play Restful JPAJava Play Restful JPA
Java Play Restful JPA
 
Service worker: discover the next web game changer
Service worker: discover the next web game changerService worker: discover the next web game changer
Service worker: discover the next web game changer
 
Network Automation: Ansible 102
Network Automation: Ansible 102Network Automation: Ansible 102
Network Automation: Ansible 102
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.js
 

Ähnlich wie Play Framework

Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSocketsGonzalo Ayuso
 
Data models in Angular 1 & 2
Data models in Angular 1 & 2Data models in Angular 1 & 2
Data models in Angular 1 & 2Adam Klein
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaYevgeniy Brikman
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsAdrien Guéret
 
Let's Play- Overview
Let's Play- OverviewLet's Play- Overview
Let's Play- Overviewbenewu
 
Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)Yevgeniy Brikman
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch
 
Basic testing with selenium
Basic testing with seleniumBasic testing with selenium
Basic testing with seleniumSøren Lund
 
Play! Framework for JavaEE Developers
Play! Framework for JavaEE DevelopersPlay! Framework for JavaEE Developers
Play! Framework for JavaEE DevelopersTeng Shiu Huang
 
Networking and Data Access with Eqela
Networking and Data Access with EqelaNetworking and Data Access with Eqela
Networking and Data Access with Eqelajobandesther
 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSCosmin Mereuta
 

Ähnlich wie Play Framework (20)

Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
 
Server Side Swift: Vapor
Server Side Swift: VaporServer Side Swift: Vapor
Server Side Swift: Vapor
 
5.node js
5.node js5.node js
5.node js
 
Socket.IO
Socket.IOSocket.IO
Socket.IO
 
Intro to Sail.js
Intro to Sail.jsIntro to Sail.js
Intro to Sail.js
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 
Data models in Angular 1 & 2
Data models in Angular 1 & 2Data models in Angular 1 & 2
Data models in Angular 1 & 2
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
Let's Play- Overview
Let's Play- OverviewLet's Play- Overview
Let's Play- Overview
 
Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)
 
Exploring Kotlin
Exploring KotlinExploring Kotlin
Exploring Kotlin
 
Play 2.0
Play 2.0Play 2.0
Play 2.0
 
Socket.io
Socket.ioSocket.io
Socket.io
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
Basic testing with selenium
Basic testing with seleniumBasic testing with selenium
Basic testing with selenium
 
Play! Framework for JavaEE Developers
Play! Framework for JavaEE DevelopersPlay! Framework for JavaEE Developers
Play! Framework for JavaEE Developers
 
Networking and Data Access with Eqela
Networking and Data Access with EqelaNetworking and Data Access with Eqela
Networking and Data Access with Eqela
 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JS
 

Kürzlich hochgeladen

Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROmotivationalword821
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 

Kürzlich hochgeladen (20)

Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTRO
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 

Play Framework

  • 2. Agenda - Theory - What Play Solves - Architecture - Play History - Web Evolution
  • 3. Agenda - Practice - Simple MVC operations - NIO - Scala
  • 7. Play is not based on Java EE
  • 8. MVC
  • 9. Play - full stack web framework for JVM - fun and high productive - change code hit reload ( forget jRebel ) - browser error reporting - easy cloud deployment (e.g. Heroku) - stateless
  • 10. Play 0.x - 05.2007
  • 11. Play 1.0 - 05.2008
  • 12. Play 1.2 - 04.2011
  • 13. Play 2.0 - 03.2012
  • 15. The Web Evolved - Static (just html) - Dynamic (get date from server on page :) ) * Structured (mvc, jsp, jsf ) - Realtime (ajax)
  • 16. Realtime Web - Polling (req - res) - Long polling (req - res when changed) - Server sent events (req - res -res -res) - Websocket (req - res - res - req -res whatever)
  • 17. 1 request = 1 thread
  • 18. NIO 1 request != 1 thread
  • 19. Demo - Create new application - Download latest activator https://www.playframework.com/download play new demo play ~run http://localhost:9000
  • 22. Controller public class HelloWorld extends Controller{ public static Result index(){ return ok("Hello World"); } }
  • 23. conf / routes GET /hello controllers.HelloWorld.index()
  • 24. Controller - add a parameter public static Result helloName(String name){ return ok("Hello World: "+ name); }
  • 25. conf / routes - add a parameter GET /helloName controllers.HelloWorld.helloName(name) http://localhost:9000/helloName? name=TestUser
  • 26. conf / routes - add a parameter to URL GET /helloName/:name controllers.HelloWorld.helloName(name) http://localhost:9000/hello/TestUser
  • 27. Controller - parameter type check public class HelloWorld extends Controller{ public static Result helloNameAge(String name, int age){ return ok("Hello World "+name +” you are ” +age); } }
  • 28. conf / routes - parameter type check GET /hello/:name/:age controllers.HelloWorld.helloNameAge(name:String,age:Int) http://localhost:9000/hello/TestUser/10
  • 29. Add a view @(name: String, age:Int) @main("Welcome to Play") { <html> <head></head> <body> <p> Hello <b> @name</b>, you are <b>@age</b> years old </p> </body> </html> }
  • 30. Controller - call view public class HelloWorld extends Controller{ public static Result index(String name, int age){ return ok(views.html.helloWorld.render(name,age)); } }
  • 32. WS lib for non-blocking http call public static Result callGoogle() { play.libs.F.Promise<play.libs.WS.Response> response=WS.url("http://google.com" ).get(); Promise<Result> result= response.map(toResult); return async(result); }
  • 33. NIO parallel call example - non blocking call public static Promise<Timing> timedRequest( final String url){ final long start = System.currentTimeMillis(); Promise<Response> res= WS.url(url).get(); return res.map(new Function<Response,Timing> (){ public Timing apply (Response response){ long latency=System.currentTimeMillis() -start; return new Timing(url,latency,start); } }); }
  • 34. NIO parallel call example - non blocking call public static Result index(){ Promise<List<Timing>> all= Promise.waitAll( Timing.timedRequest("http://www.yahoo.com"), Timing.timedRequest("http://www.google.com"), Timing.timedRequest("http://www.bing.com") ); return async(all.map(new play.libs.F.Function<List<Timing>,Result>(){ public Result apply(List<Timing> timings){ return ok (play.libs.Json.toJson(timings)); } }));}
  • 35. NIO parallel call example - result [{"url":"http://www.yahoo.com" ,"latency":1542,"start":1408296474891}, {"url":"http://www.google.com" ,"latency":366,"start":1408296474912}, {"url":"http://www.bing.com" ,"latency":437,"start":1408296474913}]
  • 36. Scala object HelloWorldScala extends Controller { def index = Action { Ok("Hello World Scala") } }
  • 37. Scala Console play console import controllers.HelloWorld HelloWorld.hello
  • 38. Heroku supports Play heroku create heroku git:remote -a playAppForHeroku git push heroku master
  • 39. Reference - https://www.playframework.com/ - Play For Scala (Manning) - Learning Play! Framework 2 (Andy Petrella) - Play For Java (Manning) - People like Sadek Drobi, Yevgeniy Brikman, James Ward :)
  • 40. Thank you Codes are available at; https://github.com/mkarakaya/playDemo.git