46
Playframework, Realtime Web Sadek Drobi Earle Casteldine

Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Playframework, Realtime Web

Sadek DrobiEarle Casteldine

Page 2: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Web Oriented Architectures

Page 3: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Where are we now?

Exciting time to be in software development

Cloud, Distributed Computing, Data, Bigger Data, Big Data, Infinite Data, Functional Programming ...

Page 4: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Object/Entity Oriented Programming

An object represents a business entity

Using getters and setter on that object manipulates database rows automatically

Enough to learn an ORM/Active Record to make a living

Very little problem solving

Page 5: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Object/Entity Oriented Programming

Page 6: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Then we rediscovered the importance of Data!

Page 7: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Object/Entity Oriented Programming

Page 8: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Object/Entity Oriented Programming

Page 9: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Object/Entity Oriented Programming

Page 10: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Object/Entity Oriented Programming

Page 11: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

New Era with new challenges

Analyzing big sets of data

Using several machines for computing and analyzing data

Integrating different sets of data in different formats

Handling lots of users requests

Page 12: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Playframework

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 and realtime web applications

- thanks to its reactive model, based on Futures and Iteratee IO.

Play was born to live in the clouds.

Page 13: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Demo

Page 14: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Why another web framework?

1 User = 1 Thread

Page 15: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Why another web framework?

Connections

Page 16: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

New Era with new challenges

Analyzing big sets of data

Using several machines for computing and analyzing data

Integrating different sets of data in different formats

Handling lots of users requests

Page 17: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Playframework, for a new era with new challenges

Analyze big sets of data: Functional Programming, Collections, Data Structures

Using several machines for computing and analyzing data

Integrating different sets of data in different formats: Parsers, APIs and FP

Handling lots of users requests: Stateless Reactive Architecture

Page 18: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Web apps integrating Distributed Computing

Use distributed computing

Aggregate results back as a single response to the user

Programming Model

Page 19: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Scheduled Computations, Computations in the Future

How do we talk about these computations?How do we manipulate them?

Page 20: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Scheduled Computations, Computations in the Future

Future[T]

Page 21: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Scheduled Computations, Computations in the Future

Page 22: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

A Future

Represents a value that will be available in the Future (or a Failure)

Provides a way to be notified whenever the value is available (onComplete)

Has some nice composition properties

Page 23: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

A Future, nice properties

Future[Future[A]] => Future[A]

List[Future[A]] => Future[List[A]]

Future[A] => (A => B) => Future[B]

And a nice api with map, flatMap, filter, collect, recover, either and other higher order functions

Page 24: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Using Futures for aggregating distributed computations

Context: Productivity tool used for discovery through data visualization

Page 25: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Using Futures for aggregating distributed computations

Browser

Backend

Graph Service Data Service

Page 26: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Demo

Page 27: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Using Futures for aggregating distributed computations

waitAll kind of composition

We can do waitAny, waitEither, timeout, ...etc

You can compose all of these

Page 28: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Using Futures for aggregating distributed computations

Context: Productivity tool used for discovery through data visualization

Page 29: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Aggregating and streaming distributed computations

Browser

Backend

Graph Service Data Service

Page 30: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Aggregating and streaming distributed computations

We need a protocol to send messages to the browser

We need a way to talk about Streams

How can we transform our list of computations into a Stream?

Page 31: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

On the browser

Comet, Server Sent Events, Websockets.

Page 32: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

How can we talk about Streams at the server side?

Page 33: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Is this what we really need to deal with Streams?

}); // Send a single 'Hello!' message

out.write("Hello!"); }

Page 34: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

How can we talk about Streams on the server side?

Programming model

With nice properties

Compositional

Page 35: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

InputStream / OutputStream

But they lack composition properties, and they are blocking.

Did the industry move backwards?

Page 36: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Iteratee[E,R]

Consumes chunks of type E

Eventually computes a value of type R

Fancy fold, you can pause!

Page 37: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Iteratee[E,R]

Immutable state machine

Done(E,R)

Cont(E => Iteratee[E,R])

Error

Page 38: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Iteratee[E,R], nice properties

Iteratee[E,Iteratee[E,R]] => Iteratee[E,R]

Future[Iteratee[E,R]] => Iteratee[E,R]

Iteratee[E,R] => (R => U) => Iteratee[E,U]

Page 39: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Enumerator[E]

Iteratee[E,R] => Iteratee[E,R]

Page 40: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Enumerator[E], nice properties

Enumerator[Enumerator[E]] => Enumerator[E]

Future[Enumerator[E]] => Enumerator[E]

and some nice functions

map, flatMap, interleave, compose, ...

Page 41: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Aggregating and streaming distributed computations

Browser

Backend

Graph Service Data Service

Page 42: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Demo

Page 43: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Enumerator[E], Iteratee[E,R]

take, takeWhile, drop, dropWhile, buffer, collect, filter, map, scan, ...

Page 44: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Infinite Data

Live streams of realtime Data

Queues, Storm, ...

With Iteratees, Enumerators, and Enumeratees

Page 45: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Demo

Page 46: Playframework, Realtime Web...Playframework The Play framework makes it easier to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly

Questions?

● www.playframework.com

● Check and play with the provided samples

● Ask