Introduction to Play 2

2,663
-1

Published on

Introduction to Play 2 framework made on JUG.fi on 3rd of May 2012

Published in: Technology, Design
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,663
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
81
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Introduction to Play 2

  1. 1. INTRODUCTION TO PLAY FRAMEWORK 2.0 Luciano Fiandesio Founder and Architect @ Aestas IT http://aestasit.com @koevetFriday, May 4, 12
  2. 2. HISTORY • The Play! framework project by Zenexity started in 2007, release 1.0 was out in 2008. • Play! started to allow Scala development since version 1.1. • Version 2.0, released on March 2012, was completely rewritten in Scala. Uses the Akka framework as backend. • Version 2 is part of the Typesafe framework, which includes Scala and Akka. http://aestasit.comFriday, May 4, 12
  3. 3. WHAT IS PLAY ? • Play! is a stateless full web development stack that works with Scala and Java • Built and focused around HTTP - no need to hide it! • Allows an asynchronous HTTP programming model (comet, websocket, streams) • Scalable and high performance (Akka!) • Type safe and everything gets compiled (code, js, css, routes) http://aestasit.comFriday, May 4, 12
  4. 4. PLAY IS STATELESS • Statelessness promotes horizontal scalability • No session, only cache. Memcache for scalability • No need to replicate the state, just use a load balancer • The web is stateless, so Play! just matches the web architecture http://aestasit.comFriday, May 4, 12
  5. 5. DEVELOPING WITH PLAY • Probably the biggest “selling point” of the Play! framework. • No need to redeploy, just click “refresh” on your browser (Rails anyone?) • What can be reloaded? • Java/Scala classes • configuration files • templates http://aestasit.comFriday, May 4, 12
  6. 6. URLS MATTERS! • Play! handles URLs in a REST-like manner: resources! • http://localhost:9000/user/100 • http//localhost:9000/users • The app’s url can be easily bookmarked, mailed and tweeted • All app’s url are configured in one file: conf/routes http://aestasit.comFriday, May 4, 12
  7. 7. SHOW ME THE ERROR http://aestasit.comFriday, May 4, 12
  8. 8. SHOW ME ALL ERRORS! • The compilers also shows compilation errors for • Templates • Javascript/Coffee script • CSS (when using the Less framework) http://aestasit.comFriday, May 4, 12
  9. 9. ACTIONS AND TEMPLATES http://aestasit.comFriday, May 4, 12
  10. 10. ACTIONS AND TEMPLATES • Play! templates get compiled to Scala classes, therefore they share a lot with Scala. • Templates are type safe. They are like giant functions with parameters. Calling a template! http://aestasit.comFriday, May 4, 12
  11. 11. ACTIONS AND TEMPLATES products.scala.html http://aestasit.comFriday, May 4, 12
  12. 12. ACTIONS AND TEMPLATES http://aestasit.comFriday, May 4, 12
  13. 13. FLASH & SESSION • Play! has a Session, but as it’s based on Cookie and can only contain String (up to 4K) • There is also a request-scope session, called flash good for displaying messages upon a successful request. http://aestasit.comFriday, May 4, 12
  14. 14. BEAN FOREVER • Play! supports multiple datasources and it is possible to use a Connection object (if you are old school). • ORM is supported too, with Ebean (http://www.avaje.org/) and JPA. • Ebean has great support through the Model superclass. Define your entity and you are good to go. http://aestasit.comFriday, May 4, 12
  15. 15. BEAN FOREVER A model class http://aestasit.comFriday, May 4, 12
  16. 16. BEAN FOREVER http://aestasit.comFriday, May 4, 12
  17. 17. CACHE • Play! has a default cache mechanism based on EHCache - but is pluggable. • Cache can be accessed via API and even from the templates. • Basic Annotation based caching supported: http://aestasit.comFriday, May 4, 12
  18. 18. SWEDISH DELIGHT • Play! and Akka are totally integrated. • You can access an Actor system and run code asynchronously • Akka can also be used when dealing with asynchronous request/response (like Websocket). • Bottom line: it is very easy to create asynchronous applications with Play 2 http://aestasit.comFriday, May 4, 12
  19. 19. GET THINGS STRAIGHT • Deploy of a Play! 2 app on Tomcat or any other container doesn’t work (so far). • Many people on the newsgroup are complaining about the Scala syntax for templates • Scala compilation time is 3X slower than Java (some say 5X) • ORM has less features than Play 1 • No plugin eco-system (yet - is coming) http://aestasit.comFriday, May 4, 12

×