MANAGE
STREAMS WITH
ITERATEE AND
PLAY
FRAMEWORK
BY @WAXZCE
TOKYO SCALA USER GROUP
WHO AM I ?
CEO of Clever Cloud
PaaS provider
@waxzce on twitter
www.clever-cloud.com
WHY WE
NEED
ITERATEE ?
SO,
ITERATEE
HANDLING
STREAMS, LET’S
FIND EXAMPLE
IN FACTS
WHAT IS INSIDE AN
HTTP REQUEST ?
Verb
• The action
Resource
• The object of the action
Headers
• The context of the action...
IN MANY CASE THE REQUEST IS
MANIPULATE ALL FROM MEMORY
File upload for example
BUT SOMETIMES THE BODY PART IS
FAT
THERE IS 3 WAY TO RESOLVE THE
PROBLEM
PUT ALL IN MEMORY
CREATE TEMP FILE
Built in on play with
ACTING DIRECTLY ON
STREAM
HTTP
REQUEST IS
STREAM
SO WE WILL
JUST MANAGE
THE BODY
STREAM
JUST DO NOT REWRITE HTTP PARSER
CLASSIC JAVA STREAM
MANAGEMENT
CLASSIC JAVA STREAM
MANAGEMENT
• Low performances if not buffered
• Not modular
• Thread blocking
• Code is ugly
SCALA WAY
: ITERATEE
Like a recipe
Consume the data
ITERATEE : HOW TO MANAGE A STREAM
Produce the data
ENUMERATOR : DATA STREAM
Set of tools to do cool things with Iteratee and Enumerator
ENUMERATEE
SIMPLE ITERATEE
EXAMPLE
BODY
PARSERS
REQUEST HEADERS -> ITERATEE[ARRAY[BYTE],
EITHER[RESULT, ?]]
EXAMPLE
MANAGING
BODY
GET FILE AND
CALCULATE HASH FROM
CHUNK
NOW LIVE CODE !
GIFT FROM CLEVER
CLOUD
Use tokyoscala as coupon
code for free hosting 
On clever-cloud.com
Upcoming SlideShare
Loading in...5
×

Iteratee and stream with Play2 scala

1,983

Published on

slides of my talk for tokyo scala user group

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,983
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
26
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Iteratee and stream with Play2 scala

  1. 1. MANAGE STREAMS WITH ITERATEE AND PLAY FRAMEWORK BY @WAXZCE TOKYO SCALA USER GROUP
  2. 2. WHO AM I ? CEO of Clever Cloud PaaS provider @waxzce on twitter www.clever-cloud.com
  3. 3. WHY WE NEED ITERATEE ? SO,
  4. 4. ITERATEE HANDLING STREAMS, LET’S FIND EXAMPLE IN FACTS
  5. 5. WHAT IS INSIDE AN HTTP REQUEST ? Verb • The action Resource • The object of the action Headers • The context of the action Body • Optional • The datas
  6. 6. IN MANY CASE THE REQUEST IS MANIPULATE ALL FROM MEMORY
  7. 7. File upload for example BUT SOMETIMES THE BODY PART IS FAT
  8. 8. THERE IS 3 WAY TO RESOLVE THE PROBLEM
  9. 9. PUT ALL IN MEMORY
  10. 10. CREATE TEMP FILE Built in on play with
  11. 11. ACTING DIRECTLY ON STREAM
  12. 12. HTTP REQUEST IS STREAM
  13. 13. SO WE WILL JUST MANAGE THE BODY STREAM JUST DO NOT REWRITE HTTP PARSER
  14. 14. CLASSIC JAVA STREAM MANAGEMENT
  15. 15. CLASSIC JAVA STREAM MANAGEMENT • Low performances if not buffered • Not modular • Thread blocking • Code is ugly
  16. 16. SCALA WAY : ITERATEE
  17. 17. Like a recipe Consume the data ITERATEE : HOW TO MANAGE A STREAM
  18. 18. Produce the data ENUMERATOR : DATA STREAM
  19. 19. Set of tools to do cool things with Iteratee and Enumerator ENUMERATEE
  20. 20. SIMPLE ITERATEE EXAMPLE
  21. 21. BODY PARSERS REQUEST HEADERS -> ITERATEE[ARRAY[BYTE], EITHER[RESULT, ?]]
  22. 22. EXAMPLE MANAGING BODY
  23. 23. GET FILE AND CALCULATE HASH FROM CHUNK
  24. 24. NOW LIVE CODE !
  25. 25. GIFT FROM CLEVER CLOUD Use tokyoscala as coupon code for free hosting  On clever-cloud.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×