Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Play 2.3 から 2.4 へアップデートした話
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
tsuyoshi yoshizawa
July 05, 2015
Technology
3.1k
7
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Play 2.3 から 2.4 へアップデートした話
Play meetup 2 で発表した内容です。
https://playframeworkja.doorkeeper.jp/events/27023
tsuyoshi yoshizawa
July 05, 2015
More Decks by tsuyoshi yoshizawa
See All by tsuyoshi yoshizawa
Scala Fukuoka Play 25 2016
tsuyoshizawa
2
2.4k
seasar_conf_2015.pdf
tsuyoshizawa
3
2.8k
Other Decks in Technology
See All in Technology
OSC2026on_the-world-is-waiting-for-your-voice.pdf
naruoga
0
350
あなたの知らないAmazon VPC Route Server/Amazon VPC Route Server you don't know about
masakiokuda
2
220
SREでアラート疲れを 解決しよう!
kairim0
1
200
ログラスのマルチプロダクトを 支える認証基盤 〜テナントごとに異なる統制とどう向き合うか〜
dada4386
3
400
Lambda MicroVMsが分からなすぎたので使い所を1から考えてみた
tsukuboshi
2
400
転んだ話が背中を預ける理由になる / A_story_about_falling_down_gives_you_a_reason_to_watch_each_other_s_backs.pdf
pauli
3
230
『GOエコノミー 』(相乗りサービス) におけるスペック駆動開発
mot_techtalk
1
310
Deep Data Security 機能解説
oracle4engineer
PRO
2
710
私の推しは「聞いてから進む」AIです -AI-DLCに一人でアプリを作らせた話
yama3133
1
180
freeeらしさをAIとともに作る / Creating the freee Experience with AI
ymrl
0
200
検証フェーズはAIの回答を判断するための学習機会
toru_kubota
2
500
ミイダス株式会社 テックチームのご紹介 / MIIDAS Tech Team
miidas
0
160
Featured
See All Featured
How to make the Groovebox
asonas
2
2.5k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
380
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
690
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
450
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Accessibility Awareness
sabderemane
1
230
Are puppies a ranking factor?
jonoalderson
2
4k
Building the Perfect Custom Keyboard
takai
2
890
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.7k
Transcript
Play 2.3 ͔Β Play 2.4 ʹ্͛ͨ - Play meetup 2
-
ࣗݾհ Tsuyoshi Yoshizawa ussy00 tsuyoshizawa scala-oauth2-provider ϝϯςͯ͠·͢ גࣜձࣾψʔϥϘͰ Typetalk ͱ͍͏
chat αʔ ϏεΛ Play Ͱͭͬͯ͘·͢
Play 2.4 ʹͯ͠ ຊ൪ڥͰͳ͘Քಇ ࡉ͔͍όάग़͍ͯͯɺطʹ 2.4.2 ·ͰϦϦʔε [2.4] Still a
thread leak in development environment https://github.com/playframework/playframework/issues/4649
2.4 ͰԿ͕มΘͬͨͷ͔ • Dependency Injection ͷαϙʔτ • Plugin ͔Β Module
• i18n ͷΈ͕มߋ • ઃఆΩʔͷมߋ What’s new in Play 2.4 https://playframework.com/documentation/2.4.x/Highlights24 Play 2.4 Migration Guide https://playframework.com/documentation/2.4.x/Migration24
Dependency Injection Controller ʹίϯϙʔωϯτΛ DI ͢ΔʹɺΠϯε λϯελΠϓΛ object ͔Β class
ʹมߋ͢Δඞཁ͋Γ Guice Λͬͯ DI ʢJSR 330 ϕʔεʣ import javax.inject._ import play.api.libs.ws._ class MyComponent @Inject() (ws: WSClient) { // ... }
Module Plugin ඇਪʹͳΓɺ DI ϕʔεͳ Module ʹ Ҡߦ͍ͯ͘͠ඞཁ͋Γ Play 2.4
ͷ Module ͷ࡞Γํͱ Plugin ͔ΒͷҠߦ ʹ͍ͭͯ http://tototoshi.hatenablog.com/entry/2014/12/14/170745
i18n Messages ʹ͢ܕ͕ Lang ͔Β Messages ࠃࡍԽରԠͯ͠ΔͱόʔδϣϯΞοϓ͕໘ case class Messages(lang:
Lang, messages: MessagesApi) object Messages { def apply(key: String, args: Any*)(implicit messages: Messages): String
ઃఆΩʔͷมߋ • ઃఆ͕ແࢹ͞ΕΔΘ͚Ͱͳ͍ • ࣮ߦ࣌ʹܯࠂ͕ग़ྗ͞Εͯؾ͚ͮΔΈ͋Γ • ৽͍͠ͷʹஔ͖͍͑ͯ͘ application.secret session.*
play.crypto.secret play.http.session.*
ΞοϓάϨʔυ
ݱঢ়ͷ֬ೝ • ෳਓͰ Git Λͬͯฒߦ։ൃΛ͍ͯ͠Δ • ͋Δఔେ͖͍ϒϥϯν͋Δ • ϓϩδΣΫτதنఔ •
ͦΕͳΓʹमਖ਼ൣғେ͖͘ͳΓͦ͏ • Play 2.4 ఆҠߦͰ͖ΔͷΛఏڙ͍ͯ͠Δ
ஈ֊తΞοϓάϨʔυ 1. Play 2.3 ελΠϧͰɺ·ͣίϯύΠϧΛ௨͢ 2. ςετΛ௨͠ಈ࡞֬ೝͯ͠ίϛοτ 3. Play 2.4
ελΠϧʹগͣͭ͠Ҡߦ͍ͯ͘͠ ΞοϓάϨʔυ ා͘ͳ͍
ࣗ࡞ϓϥάΠϯͷҠߦ Redis ΛΩϟογϡʹ͏ͨΊʹ Plugin Λࣗ࡞ (scala-redis Λར༻) class RedisModule extends
Module { def bindings(environment: Environment, configuration: Configuration) = Seq( bind[CacheApi].to[RedisCacheApi] ) } play.modules.enabled += "modules.RedisModule" play.modules.disabled += "play.api.cache.EhCacheModule" build.sbt
ScalikeJDBC Play Support play.modules.enabled += "scalikejdbc.PlayDBApiAdapterModule" db {
default { driver = org.postgresql.Driver url = "jdbc:postgresql://localhost/test" username = test password = test hikaricp { poolName = "play" registerMbeans = true } } } HikariCP ͷઃఆΛར༻͔ͨͬͨ͠ͷͰ scalikejdbc-play-dbapi-adapter Λར༻ 2.4 ͔Β HikariCP
application.conf
Thread pool configuration akka { actor {
default-‐dispatcher { fork-‐join-‐executor { parallelism-‐min = 300 parallelism-‐max = 300 } } } } play { akka { actor { default-‐dispatcher = { fork-‐join-‐executor { parallelism-‐min = 300 parallelism-‐max = 300 } } } } } 2.3 2.4 Akka ͱಉ͡هड़ʹͳͬͨ http://doc.akka.io/docs/akka/2.3.11/general/configuration.html
Remote address औಘ trustxforwarded=true 2.3 ·ͰϦόʔεϓϩΩγΛհ͢Δͱ͖ʹɺҎ ԼͷઃఆΛ͢Δඞཁ͕͕͋ͬͨෆཁʹ 2.4 ͔Β x-forwarded
ʹՃ͑ͯ RFC7239 αϙʔ τɻ play.http.forwarded.version ͰΓସ͑Մೳ https://www.playframework.com/documentation/2.4.x/HTTPServer
i18n
i18n ରԠ Controller ͷΠϯελϯελΠϓ͕ object ͷ߹ s/implicit lang: Lang/implicit messages:
Messages/g import play.api.play.current import play.api.i18n.Messages.Implicits._ Lang ͔Β Messages ʹ҉తมΛߦͬͯ͘ΕΔ Controller ʹҎԼͷ 2 ߦΛՃ͢Δ
withLang/clearingLang object FooController extends Controller with LegacyI18nSupport val lang =
user.toLang Ok(Messages("hello.world")).withLang(lang) trait LegacyI18nSupport { implicit class ResultWithLang(result: Result)(implicit messagesApi: MessagesApi) { def withLang(lang: Lang): Result = messagesApi.setLang(result, lang) def clearingLang: Result = messagesApi.clearLang(result) } } ҉తʹ messagesApi Λݺͼग़ͯ͘͠ΕΔ Result ͔Β MessagesApi ʹҠಈ͍ͯ͠Δ
ࢦ͖͢ 2.4 style import javax.inject.Inject import play.api.i18n.{MessagesApi, I18nSupport}
import play.api.mvc.Controller class FooController @Inject() (val messagesApi: MessagesApi) extends Controller with I18nSupport { } Controller ʹ MessagesApi Λ DI ͯ͠ i18nSupport Λ mixin RequestHeader Λ Messages ʹ҉తʹม͢Δ
class Controller GET /
@controllers.Application.index 2.3 ํࣜͰ @ Λ͚ͭΔ͜ͱͰಛఆͷ Controller ͔ Β class Խ͍ͯ͘͜͠ͱ͕Մೳ routesGenerator := InjectedRoutesGenerator routes build.sbt 2.4 ඪ४ͷΓํɻ Controller ͯ͢ class
2.4 style ʹ͚ͯ
Removing GlobalSettings GlobalSettings HttpErrorHandler HttpRequestHandler HttpFilter ApplicationLifecycle GlobalSettings 2.4
Ͱ Ҿ͖ଓ͖ར༻Ͱ͖Δ͕ɾɾɾ
ApplicationLifecyle @Singleton class IntervalJobs @Inject() ( system:
ActorSystem, lifecycle: ApplicationLifecycle) { val minuteJob = system.scheduler.schedule(1.minutes, 1.minutes) { // … } lifecycle.addStopHook { () => Future.successful(minuteJob.cancel()) } } • GlobalSettings#onStart • DI ରΫϥεͷίϯετϥΫλ • GlobalSettings#onStop • ApplicationLifecycle#addStopHook
HttpErrorHandler class ErrorHandler @Inject() ( env: Environment,
config: Configuration, sourceMapper: OptionalSourceMapper, router: Provider[Router], val messagesApi: MessagesApi ) extends DefaultHttpErrorHandler(env, config, sourceMapper, router) with I18nSupport { def onBadRequest(request: RequestHeader, message: String) = ??? def onForbidden(request: RequestHeader, message: String) = ??? def onNotFound(request: RequestHeader, message: String) = ??? def onOtherClientError(request: RequestHeader, statusCode: Int, message: String) = ??? def onServerError(request: RequestHeader, exception: Throwable) = ??? } DefaultHttpErrorHandler Λܧঝ͢ΔͱҠߦ͍͢͠ I18nSupport ΛͬͯΤϥʔը໘ͷࠃࡍԽରԠՄ
͍ͭ·ͰʹҠߦͨ͠Β͍͍ͷ͔ʁ
Play Roadmap 3.0 Play 3 Implementation Plan https://docs.google.com/document/d/1OejviUX5TDlRVeKg1JD9L4qh2Tn21giItmyxRXCydN0/edit Play 3.0.0
1st June 2016 Remove global state Play 2.5.0 1st October 2015 Deprecate every API that relies on global state for which there exists a DI alternative.
·ͱΊ • վળ͞Ε͍ͯ͘ Play • Play 2.4 3.0 ʹ͚ͨελʔτ
• Play νʔϜҠߦΛߟྀͯ͘͠Ε͓ͯΓɺஈ֊ తʹΞοϓάϨʔυՄೳ • Play 2.4 ͔Β࢝ΊΔਓݹ͍ใʹΘ͞Εͳ͍ Α͏ʹ