SlideShare a Scribd company logo
JavaTWO專業技術大會
Play!Framework for JavaEE Developers
Who am IExp : JSP/Servlet , Tapestry , Spring/Hibernate/JavaEE , Wicket , Android , Grails , Play! Frameworkhttp://gplus.to/smallufohttp://twitter.com/smallufosmallufo@gmail.com
Web Framework ExperiencesJSP/Servlet
Too old , cumbersome
 Tapestry (old experience, T5 is very good)
Complicated , evolution/deprecation too fast
 Wicket
Too elaborate , fail to see the wood for the trees
May lead to over-engineered architecture for OO-purism
Spend too much time refactoring
Maybe web component reuse is just a myth
Grails (old experience, without Groovy++)
Slow
Too many inconsistent DSLs (URL-mapping , DB , logging...)
Not Java , IDE unfriendlyConventional JavaEE Stack
Conventional JavaEE StackWant standard page ?
Let's define JSP/JSTL (JSR-53)
And let Apache (or others) to implement Jakata Taglibs
 Want web components ?
Let's define Java Server Faces (JSR-127)
And let communities to implement MyFaces, PrimeFaces, ICEfaces...
Want restful ?
Let's define JAX-RS (JSR-311)
And let communities to implement CXF, Jersey, RESTEasy, Wink...Conventional JavaEE StackLots of ...
Specs
Implementations
Configurations
Tedious , Error-prone
Unless you use a full-fledged JavaEE Server (Glassfish or WebLogic ...)
Layered
Defined by Standards/Specs
Assembled by InterfacesOVER ARCHITECTED
Play! Framework for JavaEE Developers
Play’s App Looks Like ?conf/routesapp/App.javaGET    /hello    App.hellopublic class App extends Controller {  public static void hello() {    User user = User.findById(1L);    render(user);  }} views/App/hello.htmlHello World : ${user.name}http://localhost:9000/hello
And Play is ...A full stack framework (platform)
Totally independent of JavaEE environment
RESTful
No session
Stateless
Pure server side
Similar to Rails / Django
Rich domain model
Unlike JavaEE's anemic domain modelFull Stack Framework?Bundles compiler , embedded server , hibernate , logger , test runner , email , groovy template engine, scala...
Can be packaged as a WAR and deployed to servlet containersPlay! A Glued Pure Web FrameworkShallow!Most libs are directly exposed to Play! & replaceableWhere Magic Happens
Play! URLs are RESTful & SEO-friendlyUGLYGRACEFUL/car/1
/listcar/page1/count10
/listcar/page1?count=10
/listcar/page/1/count/10
/car.jsp?id=1
/listcars.jsp?page=1&count=10
http://www.facebook.com/ photo.php? fbid=2121715487568& set=o.172881386106136& type=1&theaterPlay is not based on ServletMany java server side frameworks (Spring MVC / Struts / Wicket / JSF / Tapestry ...) are based on servlets, but Play! is not!You cannot do such things :session.setAttribute("user" , user); 
Use HttpSessionListener to count sessions (online users)
ServletFilter
Servlet-related securities
 @ServletSecurity
 <auth-constraint /> , <security-role />Play! is StatelessPlay! shares nothing between each request!
The most important feature you have to keep in mind
No session!
Session is the source of all problems of the JavaEE platform!
Session replication 

More Related Content

PPTX
Legal research and article writing
Sundaramdhari
 
PPT
A Practical Approach to Australian Competition Issues
Martyn Taylor
 
PDF
Web application development using Play Framework (with Java)
Saeed Zarinfam
 
PPTX
Why Play Framework is fast
Legacy Typesafe (now Lightbend)
 
PDF
Using Play Framework 2 in production
Christian Papauschek
 
PDF
Play framework - Human Talks Grenoble - 12.02.2013
Xavier NOPRE
 
PDF
Enib cours c.a.i. web - séance #5 : scala play! framework
Horacio Gonzalez
 
PDF
Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam
Saeed Zarinfam
 
Legal research and article writing
Sundaramdhari
 
A Practical Approach to Australian Competition Issues
Martyn Taylor
 
Web application development using Play Framework (with Java)
Saeed Zarinfam
 
Why Play Framework is fast
Legacy Typesafe (now Lightbend)
 
Using Play Framework 2 in production
Christian Papauschek
 
Play framework - Human Talks Grenoble - 12.02.2013
Xavier NOPRE
 
Enib cours c.a.i. web - séance #5 : scala play! framework
Horacio Gonzalez
 
Vert.x - Tehran JUG meeting Aug-2014 - Saeed Zarinfam
Saeed Zarinfam
 

Viewers also liked (20)

PDF
Baromètre Apec Andrh Bilan 2013
Abaka Conseil
 
PDF
Scala and Play with Gradle
Wei Chen
 
PDF
Réseaux sociaux - Utilisation tout au long de d’un parcours professionnel
Abaka Conseil
 
PPTX
MOOC EcoDem - présentation du parcours professionnel par équipe
Marianne128
 
PDF
Auto-scaling your API: Insights and Tips from the Zalando Team
Zalando Technology
 
PDF
Zalando Tech: From Java to Scala in Less Than Three Months
Zalando Technology
 
PDF
How We Made our Tech Organization and Architecture Converge Towards Scalability
Zalando Technology
 
PDF
Flink in Zalando's World of Microservices
Zalando Technology
 
PDF
Powering Radical Agility with Docker
Zalando Technology
 
PDF
Akka http 2
Jean Detoeuf
 
PDF
Camunda BPM at Zalando: Order Processing at scale
camunda services GmbH
 
PDF
Stream Processing using Apache Flink in Zalando's World of Microservices - Re...
Zalando Technology
 
PDF
Radical Agility with Autonomous Teams and Microservices in the Cloud
Zalando Technology
 
ODP
An Introduction to Akka http
Knoldus Inc.
 
PDF
Securing Microservices using Play and Akka HTTP
Rafal Gancarz
 
PDF
Building scalable rest service using Akka HTTP
datamantra
 
PPTX
Vert.x vs akka
Chang-Hwan Han
 
PPTX
Building a Reactive RESTful API with Akka Http & Slick
Zalando Technology
 
PDF
Spring Boot Microservices vs Akka Actor Cluster
OpenCredo
 
PDF
JavaOne 2011: Migrating Spring Applications to Java EE 6
Bert Ertman
 
Baromètre Apec Andrh Bilan 2013
Abaka Conseil
 
Scala and Play with Gradle
Wei Chen
 
Réseaux sociaux - Utilisation tout au long de d’un parcours professionnel
Abaka Conseil
 
MOOC EcoDem - présentation du parcours professionnel par équipe
Marianne128
 
Auto-scaling your API: Insights and Tips from the Zalando Team
Zalando Technology
 
Zalando Tech: From Java to Scala in Less Than Three Months
Zalando Technology
 
How We Made our Tech Organization and Architecture Converge Towards Scalability
Zalando Technology
 
Flink in Zalando's World of Microservices
Zalando Technology
 
Powering Radical Agility with Docker
Zalando Technology
 
Akka http 2
Jean Detoeuf
 
Camunda BPM at Zalando: Order Processing at scale
camunda services GmbH
 
Stream Processing using Apache Flink in Zalando's World of Microservices - Re...
Zalando Technology
 
Radical Agility with Autonomous Teams and Microservices in the Cloud
Zalando Technology
 
An Introduction to Akka http
Knoldus Inc.
 
Securing Microservices using Play and Akka HTTP
Rafal Gancarz
 
Building scalable rest service using Akka HTTP
datamantra
 
Vert.x vs akka
Chang-Hwan Han
 
Building a Reactive RESTful API with Akka Http & Slick
Zalando Technology
 
Spring Boot Microservices vs Akka Actor Cluster
OpenCredo
 
JavaOne 2011: Migrating Spring Applications to Java EE 6
Bert Ertman
 
Ad

Similar to Play! Framework for JavaEE Developers (20)

PDF
soft-shake.ch - Hands on Node.js
soft-shake.ch
 
PDF
Nodejs and WebSockets
Gonzalo Ayuso
 
ODP
ActiveWeb: Chicago Java User Group Presentation
ipolevoy
 
PPT
Introducing to node.js
JeongHun Byeon
 
PPTX
A slightly advanced introduction to node.js
Sudar Muthu
 
PPTX
hacking with node.JS
Harsha Vashisht
 
KEY
Express Presentation
aaronheckmann
 
PDF
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
scalaconfjp
 
PDF
Xitrum @ Scala Matsuri Tokyo 2014
Ngoc Dao
 
KEY
node.js: Javascript's in your backend
David Padbury
 
PPT
Boston Computing Review - Java Server Pages
John Brunswick
 
PPT
I Feel Pretty
John Quaglia
 
PPTX
Java on Windows Azure
David Chou
 
PPTX
Resthub lyonjug
Sébastien Deleuze
 
PPTX
Moving applications to the cloud
Sergejus Barinovas
 
PPT
Jsp
DSKUMAR G
 
PPTX
Spine.js
wearefractal
 
KEY
Writing robust Node.js applications
Tom Croucher
 
PPT
GWT Extreme!
cromwellian
 
PPTX
Accelerated Adoption: HTML5 and CSS3 for ASP.NET Developers
Todd Anglin
 
soft-shake.ch - Hands on Node.js
soft-shake.ch
 
Nodejs and WebSockets
Gonzalo Ayuso
 
ActiveWeb: Chicago Java User Group Presentation
ipolevoy
 
Introducing to node.js
JeongHun Byeon
 
A slightly advanced introduction to node.js
Sudar Muthu
 
hacking with node.JS
Harsha Vashisht
 
Express Presentation
aaronheckmann
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
scalaconfjp
 
Xitrum @ Scala Matsuri Tokyo 2014
Ngoc Dao
 
node.js: Javascript's in your backend
David Padbury
 
Boston Computing Review - Java Server Pages
John Brunswick
 
I Feel Pretty
John Quaglia
 
Java on Windows Azure
David Chou
 
Resthub lyonjug
Sébastien Deleuze
 
Moving applications to the cloud
Sergejus Barinovas
 
Spine.js
wearefractal
 
Writing robust Node.js applications
Tom Croucher
 
GWT Extreme!
cromwellian
 
Accelerated Adoption: HTML5 and CSS3 for ASP.NET Developers
Todd Anglin
 
Ad

Recently uploaded (20)

PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
Coupa-Overview _Assumptions presentation
annapureddyn
 
PPT
L2 Rules of Netiquette in Empowerment technology
Archibal2
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Chapter 1 Introduction to CV and IP Lecture Note.pdf
Getnet Tigabie Askale -(GM)
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PDF
Doc9.....................................
SofiaCollazos
 
PPTX
Stamford - Community User Group Leaders_ Agentblazer Status, AI Sustainabilit...
Amol Dixit
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PPT
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Coupa-Overview _Assumptions presentation
annapureddyn
 
L2 Rules of Netiquette in Empowerment technology
Archibal2
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Chapter 1 Introduction to CV and IP Lecture Note.pdf
Getnet Tigabie Askale -(GM)
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
Doc9.....................................
SofiaCollazos
 
Stamford - Community User Group Leaders_ Agentblazer Status, AI Sustainabilit...
Amol Dixit
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 

Play! Framework for JavaEE Developers

  • 3. Who am IExp : JSP/Servlet , Tapestry , Spring/Hibernate/JavaEE , Wicket , Android , Grails , Play! Frameworkhttp://gplus.to/smallufohttp://twitter.com/[email protected]
  • 5. Too old , cumbersome
  • 6.  Tapestry (old experience, T5 is very good)
  • 9. Too elaborate , fail to see the wood for the trees
  • 10. May lead to over-engineered architecture for OO-purism
  • 11. Spend too much time refactoring
  • 12. Maybe web component reuse is just a myth
  • 13. Grails (old experience, without Groovy++)
  • 14. Slow
  • 15. Too many inconsistent DSLs (URL-mapping , DB , logging...)
  • 16. Not Java , IDE unfriendlyConventional JavaEE Stack
  • 19. And let Apache (or others) to implement Jakata Taglibs
  • 21. Let's define Java Server Faces (JSR-127)
  • 22. And let communities to implement MyFaces, PrimeFaces, ICEfaces...
  • 25. And let communities to implement CXF, Jersey, RESTEasy, Wink...Conventional JavaEE StackLots of ...
  • 26. Specs
  • 30. Unless you use a full-fledged JavaEE Server (Glassfish or WebLogic ...)
  • 35. Play’s App Looks Like ?conf/routesapp/App.javaGET /hello App.hellopublic class App extends Controller { public static void hello() { User user = User.findById(1L); render(user); }} views/App/hello.htmlHello World : ${user.name}http://localhost:9000/hello
  • 36. And Play is ...A full stack framework (platform)
  • 37. Totally independent of JavaEE environment
  • 42. Similar to Rails / Django
  • 44. Unlike JavaEE's anemic domain modelFull Stack Framework?Bundles compiler , embedded server , hibernate , logger , test runner , email , groovy template engine, scala...
  • 45. Can be packaged as a WAR and deployed to servlet containersPlay! A Glued Pure Web FrameworkShallow!Most libs are directly exposed to Play! & replaceableWhere Magic Happens
  • 46. Play! URLs are RESTful & SEO-friendlyUGLYGRACEFUL/car/1
  • 52. http://www.facebook.com/ photo.php? fbid=2121715487568& set=o.172881386106136& type=1&theaterPlay is not based on ServletMany java server side frameworks (Spring MVC / Struts / Wicket / JSF / Tapestry ...) are based on servlets, but Play! is not!You cannot do such things :session.setAttribute("user" , user); 
  • 53. Use HttpSessionListener to count sessions (online users)
  • 57.  <auth-constraint /> , <security-role />Play! is StatelessPlay! shares nothing between each request!
  • 58. The most important feature you have to keep in mind
  • 60. Session is the source of all problems of the JavaEE platform!
  • 63. Play uses (delegates to) memcached to eliminates such headachesPlay's Informative Error Page
  • 64. Play's Domain Objects Are RichPlay*Spring promoted JavaEEUser extends ModelUser extends ObjectUserDao.javasave(User u)User u = new User(...)u.save()UserDaoImpl implements UserDaovoid setEntityManager(...)
  • 65. save(User u)Client.java@Inject UserDao userDaoUser u = new User(...)userDao.save(u)VS*JPA advocates eliminating the DAO layer
  • 66. Play's Architecture$ play new myprojmyprojappcontrollersmodelsconfapplication.confviewsmessageslibfooroutesmodulesbarpublicimagesjavascriptssrcstylesheets
  • 68. Play's ArchitecturecontrollersappMyController.javapublic static void index()public static void show()modelsviewsMyControllerindex.htmlfooshow.htmlbar
  • 69. conf/routesHTTP methodURI PatternActionGET    /                      App.indexPOST   /login                 App.loginGET    /tag/{name}            App.tag(name)GET    /list/{page}           App.list(page)GET    /list/{<[0-9]+>page}   App.list(page)GET    /list/{page}/{count}   App.list(page,count)GET    /public/               staticDir:public*      /{controller}/{action} {controller}.{action}
  • 71. Controllers and Redirectionspublic class App extends play.mvc.Controller {  public static void index() {    render(); // views/App/index.html contains a login form  }  public static void login(String name,String passwd) {    if(...) // success      welcome();    else   // failed      index();  }  public static void welcome() {    render();  // renders views/App/welcome.html   }}
  • 72. Controller Interceptionspublic class App extends play.mvc.Controller {  @play.mvc.Before(unless={“index”, “login”})  public static void intercept() {    if (session.get("uid")==null)       index();  }  public static void index() {...}  public static void login(String name,Stringpasswd){..}  public static void welcome() {...}}
  • 73. Session : A Signed Cookiepublic static void login(String name , String passwd) {  User u = ...  if (...) {    session.put("uid" , u.id);  }}Only put index data to sessionNever store sensitive datasigned, uneditable!
  • 74. Controller Revisitedpublic static void show(Long uid, String type) {  User u = ...  if (type.equals("json") {    renderJSON(u);   // provided by GSON  }   else if (type.equals("xml") {    renderXml(u);    // provided by XStream  }     render(u);  }Why not continue rendering?play.mvc.Controllerthrow new RenderJson(jsonString);throw new RenderXml(xml);throw new RenderTemplate(...);
  • 75. Controller and Viewcontrollers/App.javapublic static void showUser(Long uid) {  User u = ...  List<Car> cars = ...  renderArgs.put("user",u);  render(cars, company, job, ...);  }public static void showCar(Long id) {...}renderArgs.put(“cars”,car);renderArgs.put(“company”,company);renderArgs.put(“job”,job);sameviews/App/showUser.htmlHello ${user.name} , these are your cars :#{list items:cars , as:'car'}  #{a @showCar(car.id)} ${car.name} #{/a}#{/list}template [email protected](car.id)
  • 76. How objects are passed to View !?controllers/App.javapublic static void showUser(Long uid) {  renderArgs.put("user",u);  render(cars , ...);  }!!??views/App/showUser.html${user.name}#{list items:cars , as:'car'}Let's decompile it...
  • 77. public static void showUser(Long uid){  play.classloading.enhancers.LocalvariablesNamesEnhancer.LocalVariablesNamesTracer.enter();  play.classloading.enhancers.LocalvariablesNamesEnhancer.LocalVariablesNamesTracer.addVariable("uid", uid);  if(!play.classloading.enhancers.ControllersEnhancer.ControllerInstrumentation.isActionCallAllowed())  {    Controller.redirect("controllers.App.showUser", new Object[] {      uid    });  } else  {    play.classloading.enhancers.ControllersEnhancer.ControllerInstrumentation.stopActionCall();    User u = (User)User.findById(uid);    play.classloading.enhancers.LocalvariablesNamesEnhancer.LocalVariablesNamesTracer.addVariable("u", u);    List cars = Car.all().fetch();    play.classloading.enhancers.LocalvariablesNamesEnhancer.LocalVariablesNamesTracer.addVariable("cars", cars);    Object obj = null;    play.mvc.Scope.RenderArgs renderargs = null;    renderargs = (play.mvc.Scope.RenderArgs)Java.invokeStatic(Desc.getType("Lplay/mvc/Scope$RenderArgs;"), "current");    renderargs.put("user", u);    render(new Object[] {      cars    });  }  break MISSING_BLOCK_LABEL_120;  Exception exception;  exception;  Object obj1 = null;  play.classloading.enhancers.LocalvariablesNamesEnhancer.LocalVariablesNamesTracer.exit();  throw exception;  Object obj2 = null;  play.classloading.enhancers.LocalvariablesNamesEnhancer.LocalVariablesNamesTracer.exit();  return;}
  • 78. Who Modifies My Code !?Who ?Play's custom classloader & JDT & javassistWhen ?DEV mode : When you modify the code and reload the page
  • 79. PROD mode : App's start timeHow ?At compile time , some classes are enhanced by play.classloading.enhancers.* (powered by javassist)
  • 83. LocalvariablesNamesEnhancer, ...Impact ?Rapid development time !View Templateobject path${objectname}${object.property}implicit objects${params.userId}${session.userId}${request.userId}built-in tags#{if} ... #{/if} #{else}... #{/else}#{list items:users , as:'user'}  ${user.name}#{/list}#{a @App.showUser(user.id)} show user #{/a}#{form @App.login() } ... #{/form}
  • 84. Rich Domain Object Modelpackage models;@javax.persistence.Entitypublic class User extends play.db.jpa.Model {  public String username;  public String password;}Support JPA's annotations : @Column , @ManyToOne , @OneToMany ...NO more getters & setters... Great !
  • 85. Rich Domain Object ModelBUT...The underlayer is hibernate & hibernate needs getter/setterAgain...Who modifies my model ?
  • 86. Rich Domain Object ModelIn Fact...    Your model still contains getter/setter , modified by Play's custom classloader & JDT & javassistUser.javapublic String getUsername() {  return "overridden";}${user.username} will be ??
  • 87. Rich Domain ObjectUser u = User.findById(1);User u = User.find("byUsernameAndPassword", username , password).first();User u = User.find("select u from User u where u.username = :username and u.password = :password")  .bind("username",username)  .bind("password",password)  .first();List<User> users = User.all().fetch();User.em().createQuery(...);
  • 88. Validations : Controller#{form @App.login()} <p>username <input type=“text” name=“username” value=“${flash.username}” /> <span class=“error”>#{error 'username'/}</span> </p> <p>password <input type=“password” name=“password” value=“${flash.password}” /> <span class=“error”>#{error 'password'/}</span> </p> <input type="submit" value=“Login" /> <span class=“error”>#{error ‘other'/}</span>#{/form}username請輸入帳號password請輸入密碼Login帳號或密碼輸入錯誤
  • 89. Validations : Controllerpublic static void login(@Required(message ="請輸入帳號")String username, @Required(message ="請輸入密碼")String password) { User user = User.login(username , password); if (validation.hasErrors()){ params.flash(); // add parameters to flash scope validation.keep(); // keeps the errors flash.error(validation.errors().get(0).toString()); render(“pleaseLogin.html”); } flash.success(“welcome : “ + user.username); render();}
  • 90. Validation : Modelpublic class User extends Model {@Required @MinSize(6) public username;@Required @MinSize(6) public password; public static User login(String username , String password) { Validation validation = Validation.current(); User user = ... validation.isTrue(user!=null) .key(“other”).message(“帳號或密碼輸入錯誤”); return user;}}Will @MinSize affect login() ?
  • 91. Validations@Required , @Min , @Max , @MinSize , @MaxSize , @Range , @Email , @URL ...Custom validation annotationextends AbstractAnnotationCheck & implements isSatisfied()i18n messages/conf/messages
  • 92. CacheConventional JavaEE's Waypublic User getUser(String name) {  Session s = (Session)em.getDelegate();  Criteria c = s.createCriteria(User.class);  c.add(Restrictions.eq("username",name);  c.setMaxResults(1);  c.setCacheable(true);  if (c.uniqueResult() == null)    return null;  return (User) c.uniqueResult();}
  • 93. CachePlay's Way : Not In Favor of 2nd Levelpublic static User getUser(String name) {  String key="username_"+name;  User user = Cache.get(key,User.class);  if (user != null)    return user;  user = User.find("byUsername",name).first();  Cache.set(key,user,"30mn");  return user;}
  • 94. Cache - Problem !User.java {  public static User getUser(Long id) {    String key = "userId_"+id;    ...  }  public static List<User> getUsers(Long page, int cnt) {    String key="users_"+page+"_"+cnt;    ...  }}public interface UserDao.java { public User getUser(Long id); public List<User> getUsers(Long page, int cnt);}
  • 95. Conventional JavaEE's WayUser u1 = userDao.getUsers(1,10).get(0);User u2 = userDao.get(1L);assertTrue(u1.equals(u2)); // PASSEDu2.modifySomething(...);userDao.save(u2);User u3 = userDao.getUsers(1,10).get(0);assertTrue(u3.equals(u2)); // PASSEDPlay's WayUser u1 = User.getUsers(1,10).get(0);User u2 = User.getUser(1L);assertTrue(u1.equals(u2)); // PASSEDu2.modifySomething(...);u2.save();User u3 = User.getUsers(1,10).get(0);assertTrue(u3.equals(u2)); // FAILED!
  • 96. Cache Problem : Reason users_1_10cache key :TIMEuuuuuuuuuuu1userId_1cache key :umodified / updatedu2users_1_10cache key :?uuuuuuuuuu3
  • 97. Cache - Problem! How to Solve It ?Ignore it , accept it
  • 99. Two phase list retrieval
  • 100. Cache object ids instead of objectspublic static List<User> getUsers(Long page, int cnt) {  String key="users_"+page+"_"+cnt;    List<Long> userIds =     User.find("select u.id from User u)    .fetch(page,cnt);  Cache.set(key, userIds, "1mn");  // iterate each id in result and query cache or fetch}
  • 101. Cache : Wait... I saw Model.em() ? How about get underlaying Hibernate’s session and setCacheable(true) ?Session s = (Session) User.em().getDelegate();Critieria c = s.createCriteria(...);c.add(... criterions ... );c.setCacheable(true);
  • 103. Module : CRUDpackage models;public class User extends Model { ... }package controllers;public class Users extends CRUD { ... }Cars , Photos , Logseven ...Boxs , Buss, Kisss
  • 104. Module GAE + Module Sienapublic class User extends siena.Model {   public String uid;  public static User getUser(String uid) {    return User.all(User.class).filter("uid",uid).get();  }  public static User getUsers(int page , int count) {    return User      .all(User.class)      .fetch(count,(page-1)*count);  }}Don't forget war/WEB-INF/appengine-web.xml$ play gae:deploy Done !
  • 105. Play on GAESimplest way to deploy Java Apps on GAE !
  • 107. Less than 10 seconds
  • 108. Cache is wrapped to GAE's memcache
  • 109. Mail is wrapped to GAE's mail serviceIssue : Portal-like PageMany blocks query DB in every page
  • 110. Passing these query results in every action is cumbersome
  • 111. Solution : @Before and renderArgs.put()@Beforestatic void addDefaults() {  renderArgs.put("brands", Brand.all().fetch());  renderArgs.put("forums", Forum.getAll());   renderArgs.put("tags" , Tag.getAll());}
  • 112. Issue : High Availability<VirtualHost *:80> ServerName myapp.com <Location /balancer-manager>  SetHandler balancer-manager  Order Deny,Allow  Deny from all  Allow from .myapp.com </Location> <Proxy balancer://mycluster>   BalancerMember http://localhost:9002   BalancerMember http://localhost:9003 status=+H </Proxy> <Proxy *>   Order Allow,Deny   Allow From All </Proxy> ProxyPreserveHost on ProxyPass /balancer-manager ! ProxyPass / balancer://mycluster/ ProxyPassReverse / http://localhost:9002/ ProxyPassReverse / http://localhost:9003/</VirtualHost>Apache Web Serverlocalhost:9002localhost:9003Same directory structures & application.secret , only different http.port
  • 113. Issue : Action Burstcontrollers/Appcontrollers/Applogin()logout()register()myaccount()mybooks()index()page()search()showbook()login()logout()register()myaccount()mybooks()index()page()search()showBook()listUsers()editUser()editBook()controllers/AdminlistUsers()editUser()editBook()
  • 114. Issues : Validation DilemmaValidation in controllers ?validation in models ?or hybrid ?
  • 115. Issue : DIDependency Injection is not so useful in Play’s Rich Domain Object environment
  • 116. Case Study : VAGTW.COMVW/Audi Car Problem Stats
  • 118. VAGTW.com developmentDev in one month (Since 2010/4/1)
  • 119. Modified from Play's YABE sample
  • 120. 10 days learning Play! & modeling & coding
  • 121. 20 days tuning HTML & CSS(3)
  • 123. Peak 4x users in 15 mins
  • 124. Indexed by Google in 2 days
  • 125. Indexed by Yahoo in 2 weeks
  • 126. Indexed by Bing after 2 monthsConclusionsIS ...A Glued Pure Web Framework
  • 127. Loose
  • 134. Strict
  • 137. Stateful (Session-aware)Conclusions : Use Play! If You...Have to prototype or build something quicklyDon’t want to buy high-priced Java application serversAre not so OO-purism, feel OK without interfacesMany Play’s “hook” are not enforced by abctract mathods or interfacesKnow JavaScript & other JS frameworksYou can build slick UIs without sluggish server-state implementation responses (Wicket/JSF...)Feel OK about object inconsistences in cacheWant to develop GAE appsYour team have a strong mendiatorBecause programming in play is too unrestrainedWant to learn Scala