iteratee and stream with play2 scala

25
MANAGE STREAMS WITH ITERATEE AND PLAY FRAMEWORK BY @WAXZCE TOKYO SCALA USER GROUP

Upload: quentin-adam

Post on 08-May-2015

1.700 views

Category:

Technology


0 download

DESCRIPTION

slides of my talk for tokyo scala user group

TRANSCRIPT

Page 1: Iteratee and stream with Play2 scala

MANAGE STREAMS WITH ITERATEE AND PLAY FRAMEWORKBY @WAXZCE

TOKYO SCALA USER GROUP

Page 2: Iteratee and stream with Play2 scala

WHO AM I ?CEO of Clever Cloud

PaaS provider

@waxzce on twitter

www.clever-cloud.com

Page 3: Iteratee and stream with Play2 scala

WHY WE NEED ITERATEE ?

SO,

Page 4: Iteratee and stream with Play2 scala

ITERATEE HANDLING STREAMS, LET’S FIND EXAMPLE

IN FACTS

Page 5: Iteratee and stream with Play2 scala

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

Page 6: Iteratee and stream with Play2 scala

IN MANY CASE THE REQUEST IS MANIPULATE ALL FROM MEMORY

Page 7: Iteratee and stream with Play2 scala

File upload for example

BUT SOMETIMES THE BODY PART IS FAT

Page 8: Iteratee and stream with Play2 scala

THERE IS 3 WAY TO RESOLVE THE PROBLEM

Page 9: Iteratee and stream with Play2 scala

PUT ALL IN MEMORY

Page 10: Iteratee and stream with Play2 scala

CREATE TEMP FILE

Built in on play with

Page 11: Iteratee and stream with Play2 scala

ACTING DIRECTLY ON STREAM

Page 12: Iteratee and stream with Play2 scala

HTTP REQUEST IS STREAM

Page 13: Iteratee and stream with Play2 scala

SO WE WILL JUST MANAGE THE BODY STREAM

JUST DO NOT REWRITE HTTP PARSER

Page 14: Iteratee and stream with Play2 scala

CLASSIC JAVA STREAM MANAGEMENT

Page 15: Iteratee and stream with Play2 scala

CLASSIC JAVA STREAM MANAGEMENT • Low performances if not buffered

• Not modular

• Thread blocking

• Code is ugly

Page 16: Iteratee and stream with Play2 scala

SCALA WAY : ITERATEE

Page 17: Iteratee and stream with Play2 scala

Like a recipe

Consume the data

ITERATEE : HOW TO MANAGE A STREAM

Page 18: Iteratee and stream with Play2 scala

Produce the data

ENUMERATOR : DATA STREAM

Page 19: Iteratee and stream with Play2 scala

Set of tools to do cool things with Iteratee and Enumerator

ENUMERATEE

Page 20: Iteratee and stream with Play2 scala

SIMPLE ITERATEE EXAMPLE

Page 21: Iteratee and stream with Play2 scala

BODY PARSERSREQUEST HEADERS -> ITERATEE[ARRAY[BYTE], EITHER[RESULT, ?]]

Page 22: Iteratee and stream with Play2 scala

EXAMPLE MANAGING BODY

Page 23: Iteratee and stream with Play2 scala

GET FILE AND CALCULATE HASH FROM CHUNK

Page 24: Iteratee and stream with Play2 scala

NOW LIVE CODE !

Page 25: Iteratee and stream with Play2 scala

GIFT FROM CLEVER CLOUD

Use tokyoscala as coupon code for free hosting

On clever-cloud.com