Top Banner
Play! Framework Eduard Tudenhöfner
30

Play Framework

Jul 07, 2015

Download

Technology

Nas Tra

This presentation gives a basic overview over the features of the Play framework
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Play Framework

Play! FrameworkEduard Tudenhöfner

Page 2: Play Framework

Outline

● Getting Started● Error Handling● Threaded vs Evented● Async Features● Demo● Summary

Page 3: Play Framework

Outline

● Getting Started● Error Handling● Threaded vs Evented● Async Features● Demo● Summary

Page 4: Play Framework

Overview

● MVC Pattern● Java & Scala API● Stateless● Built on Akka

Page 5: Play Framework

Play Console

● play new my-app

● play compile | run | test | debug

● play clean-all

● play eclipse | idea

Page 6: Play Framework

Application Layout

Page 7: Play Framework

HTTP Routing

● URI to Controller mapping

GET /projects/:projectId/tasks controllers.Tasks.index(projectId: Long)

POST /projects/:projectId/tasks controllers.Tasks.add(projectId: Long, folder: String)

PUT /tasks/:task controllers.Tasks.update(task: Long)

DELETE /tasks/:task controllers.Tasks.delete(task: Long)

● pattern: <HTTP Method> <URI> <Controller>

Page 8: Play Framework

State in Play!

● server is stateless● state is stored on client● session and flash scopes

○ for data that is required between subsequent HTTP requests

○ cookie (max 4KB per User / only string values)

Important: The flash scope should only be used to transport success/error messages on simple non-Ajax applications. As the data are just kept for the next request and because there are no guarantees to ensure the request order in a complex Web application, the Flash scope is subject to race conditions.

Page 9: Play Framework

Model

● POJOs with generated getters/setters● Play uses Active Record pattern● EBean -> default ORM (JPA without

container)

Page 10: Play Framework

Testing Support

● play test● Helper classes to mock and fake almost

everything● provides support for Selenium &

FluentLenium

Page 11: Play Framework

Testing Support

Page 12: Play Framework

Testing Support

Page 13: Play Framework

Outline

● Getting Started● Error Handling● Threaded vs Evented● Async Features● Demo● Summary

Page 14: Play Framework

Error Handling

Page 15: Play Framework

Error Handling

● Big Plus: detailed error messages shown in browser -> no need to search log files

● errors can be in ○ Java/Scala class○ Routes config○ template code○ ….

Page 16: Play Framework

Error Handling

Page 17: Play Framework

Error Handling

Page 18: Play Framework

Outline

● Getting Started● Error Handling● Threaded vs Evented● Async Features● Demo● Summary

Page 19: Play Framework

Threaded

Page 20: Play Framework

Threaded

● one thread assigned to each request● any I/O is typically synchronous● problems that might arise?

○ thread pool sizing -> too many/too few?!○ Thread stack size with 64 Bit JVMs -> 1MB○ thread might get blocked, waiting for another

service to complete

Page 21: Play Framework

Evented

Page 22: Play Framework

Evented

● one thread per CPU core● basic idea: ensure that these scarce

resources are never blocked● I/O is asynchronous● blocking I/O mostly when talking to DBs

Page 23: Play Framework

Outline

● Getting Started● Error Handling● Threaded vs Evented● Async Features● Demo● Summary

Page 24: Play Framework

Async Features

● idea: never block● Play actions are async by default!● Controllers return Result objects● when async, return Promise<Result>

○ client is blocked - server is not blocked and serves result when it’s computed

Note: Whether the action code returns a Result or a Promise<Result>, both kinds of returned object are handled internally in the same way. There is a single kind of Action, which is asynchronous, and not two kinds (a synchronous one and an asynchronous one). Returning a Promise is a technique for writing non-blocking code.

Page 25: Play Framework

Async Features

Page 26: Play Framework

Outline

● Getting Started● Error Handling● Threaded vs Evented● Async Features● Demo● Summary

Page 27: Play Framework

Outline

● Getting Started● Error Handling● Threaded vs Evented● Async Features● Demo● Summary

Page 28: Play Framework

Summary

● High Developer Productivity○ make a change -> refresh -> see the change○ hot reload for all resources

● Built-in testing support

● Predictable Scalability○ adheres to HTTP principles○ non-blocking I/O support

● Commercial Support available through Typesafe & Zenexity

● Typesafe○ makes it easier for large code bases

Page 29: Play Framework

Summary

● Immature○ Best Practices aren’t well defined○ API is changing○ Play 2 was entirely rewritten

● Not a Servlet○ breaks away from the Servlet spec

● Build System (SBT)○ hard to understand (even for Scala experts)○ very powerful & flexible, but very steep learning curve

Page 30: Play Framework

Thank you! - Questions?