play2
play

Play2 Non blocking, composable reactive web programming with - PowerPoint PPT Presentation

Play2 Non blocking, composable reactive web programming with Iteratees and Promises in Play2 Monday, June 18, 12 @sadache @hguergachi @guillaumebort Monday, June 18, 12 www.zenexity.com Web Oriented Architectures Monday, June 18, 12 What


  1. Play2 Non blocking, composable reactive web programming with Iteratees and Promises in Play2 Monday, June 18, 12

  2. @sadache @hguergachi @guillaumebort Monday, June 18, 12

  3. www.zenexity.com Web Oriented Architectures Monday, June 18, 12

  4. What is Play? • The Play framework makes it easier to build web applications with Java & Scala. • Play is based on a lightweight, stateless, web- friendly architecture for highly-scalable applications - thanks to its reactive model, based on Futures and Iteratee IO. Monday, June 18, 12

  5. The Web Evolved Monday, June 18, 12

  6. The Web Evolved • Data distribution and Information Systems Partitioning • Streams of Data Monday, June 18, 12

  7. Execution Thread get x get y Execution Thread get x get y Problem Execution Thread get x get y Execution Thread get x get y Execution Thread get x get y Monday, June 18, 12

  8. Opportunity get x get x get x get x get x Execution Thread Execution Thread Execution Thread Execution Thread Execution Thread get y get y get y get y get y Monday, June 18, 12

  9. Opportunity • What if the callee can notify me on completeness of his task • A callback Monday, June 18, 12

  10. Callback Hell! Monday, June 18, 12

  11. An Opportunity and a Model • The service we are calling should support the Non Blocking Style (ex: NIO) • A model of programming: Reactive with Futures and Promises Monday, June 18, 12

  12. Futures and Promises • val f : Future[A] = ... • f.map( a => getB(a)) // Eventually transforming A to B • f.flatMap( a => eventuallyGetB(a)) Monday, June 18, 12

  13. Play2’s Action takes the future! Action { rq => AsyncResult(f.map(a => Ok(a)) } Monday, June 18, 12

  14. Play2’s Action takes the future! Monday, June 18, 12

  15. Play2’s Action takes the future! • The service we are calling should support the Non Blocking Style (ex: NIO) • Webcalls (WS), network, filesystem, datastores (MongoDb), SQL (async MySQL), disruptor, actors, …) Monday, June 18, 12

  16. Streams of Data • Streams of data are everywhere • File uploads, tweets, finance data streams, ... Monday, June 18, 12

  17. InputStream is outdated/too low level public abstract int read () throws IOException Reads the next byte of data from the input stream. [...] This method blocks until input data is available Monday, June 18, 12

  18. Problem of classic model • Blocking read and blocking write • Resources consumption (memory, threads, disk). • Pro-active waiting. • Input/Output Stream Monday, June 18, 12

  19. Going Reactive • Inversion of control. • Without loosing control. • Iteratee/Enumerator IO. Monday, June 18, 12

  20. Iteratee Enumerator[E] Iteratee[E,A] Input[E] is either El[E] or EOF Step[E,A] ? Enumeratee[EIn,EOut] is an adapter Done[E,A] Error[E] Cont[E,A] Input[E] => Iteratee[E,A] Step[E,A] ? Done[E,A] Cont[E,A] Error[E] Monday, June 18, 12

  21. What if the Iteratee’s Input processing is reactive? an opportunity! Iteratee[E,A] Promise [Step[E,A]] ? Done[E,A] Error[E] Cont[E,A] Monday, June 18, 12

  22. Reactive File Upload Monday, June 18, 12

  23. A programming model • Tools for creating, consuming and adapting streams • map, filter, fold, unfold, collect, group, scan, foreach, ... • All in a reactive manner. • Iteratee, Enumerator and Enumeratee. Monday, June 18, 12

  24. Parsing CSV like file upload https://gist.github.com/2939230 Monday, June 18, 12

  25. How to construct Enumerators (Streams)? • Pure (from a list of elements) • generateM and unfoldM • Push Monday, June 18, 12

  26. Streams Monday, June 18, 12

  27. More • www.playframework.com • Check and play with the provided samples • Ask • Thanks to @sgodbillon for the MongoDb example Monday, June 18, 12

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend