board and CTO at Accso – Accelerated Solutions GmbH in Darmstadt, www.accso.de Since end of the 90s working in several projects with scope on individual software development, focussing mainly on technical architecture Java, SW architecture, SW Engineering, Distributed Systems Active member of iSAQB and IASA # who am i
times, low latency, high throughput Requirements on Scalability: growing numbers of named/concurrent users, multi-core Requirements on Availability: 24x7, failover, fault-tolerancy What are the Requirements? Reactive Manifesto: Responsive, Resilient, Elastic, Message-Driven Event based Many parallel requests Lots of subscribers Pipelining, Data chains
too low-level, too complex, too error-prone! Another Requirement: Control the Complexity Traditional concurrent programming model does not get the optimum out of available resources. Actor Model Reactor Pattern
Model for concurrent programming Actors as the executables in the system Shared-Nothing architecture (no global state) Asynchronous messaging Actor Actor Actor State State State
Reactor = Dispatcher (of events to callback handlers) Decouples application logic from execution logic Reactor Pattern: 1 Event-Loop-Thread Multi-Reactor Pattern: Scale to n ELTs Handler has to avoid to block the ELT at all cost! (Multi-)Reactor Pattern Douglas Schmidt et al, 1996f Client Client Client Event Loop
MVC: routes Configuration and Controller in Java 13 # Routes GET /presents controllers.XMasController.getPresentList() GET /daysToXMas controllers.XMasController.howManyDaysUntilXMas() Route: URL to Controller method Call the View public class XMasController extends Controller { @Inject Initialize init; public Result getPresentList() { List<Present> presents = Present.list(); return ok(showPresentList.render(presents)); } public Result howManyDaysUntilXMas() { LocalDate xMasDay = LocalDate.of(2015, Month.DECEMBER, 24); LocalDate now = LocalDate.now(); … int days = (Period.between(now, xMasDay)).getDays(); return ok(daysToGo.render(days)); } } Controller-Methode (public, static) Controller method
{ <h1>List of XMas presents</h1> <p> <ul> @for(present <- presents) { <li>@present.name is for @present.presentee</li> } </ul> } Play Web Applications are based on MVC: View Templates in HTML & Scala Main elements: for loop, iterator, if-then-else and Template composition 13 Parameter from Controller Scala-Code Starts with @
MVC: Persistence with ORM via EBeans (or Hibernate/JPA) 15 import javax.persistence.*; @Entity public class Present extends Model { @Id @GeneratedValue @Column(nullable = false) private Long id; @Column(nullable = false) public String name; @Column(nullable = false) public String presentee; ... private static Model.Find<Long, Present> finder = new Model.Find<Long, Present>(){}; public static List<Present> list() { return finder.findList(); } } EBeans-Model super class plus enhancement Annotations from javax.persistence Finder methods, Query API EBeans is pretty simple. No session. Attention: Still usable though Ebeans seems (is?) kind of dead meanwhile.
Chain? • Integration with Eclipse / Scala IDE easy • Hot-Deployment and Debugging straight forward • Tests with JUnit and Selenium • Build with sbt, Ivy • Integration with Maven possible but tricky • Templates, routes etc are compiled, too • Eclipse 4.4.2 (Luna) • Scala IDE 4.2.0 • Scala 2.11.7 and Scala 2.10.5 • Sbt 0.13.8 • Scala Worksheet 0.4.0 • Play Framework support 0.5.0 • ScalaTest support 2.9.3 • Scala Refactoring 0.7.0 • Scala Search 0.2.5 • access to the full Scala IDE ecosystem
Huehnken, Typesafe, JAX 2015: „Von Enterprise zu Reactive“ http://de.slideshare.net/lutzh/von-enterprise-zu-reactive Traditional Servlet Model: Thread per Request Dispatching (n Threads per m Requests) Attention Don‘t rely on ThreadLocal! Blocking IO (e.g. JDBC) blocks the thread! Play standalone or via Plugin in Servlet Container? Plugin see https://github.com/play2war/play2-war-plugin/