reactive programming met java 8 en java ee 7 - martijn blankestijn

Post on 02-Jul-2015

1.436 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

Java SE 8 is een grote stap in de evolutie van het Java Platform. Java 8 introduceerde lambda's, een nieuwe Date-Time API en nog veel meer. Completable Futures is een nieuwe Java 8 feature die vaak over het hoofd wordt gezien. Completable Futures (a.k.a. promises) borduren verder op de bestaande Future API en maakt een asynchroon, non-blocking event-driven programmeermodel mogelijk. Deze sessie geeft een inkijk in de Completable Future API en plaatst deze in de context van het toenemend gebruik en interesse voor asynchroniciteit en 'reactive programming'. De live-demo's demonstreren hoe een traditionele service met 'vanilla' Java EE 7 API's zoals JAX-RS en JSON wordt omgevormd tot een 'pipeline' van (parallel uitgevoerde) operaties.

TRANSCRIPT

Reactive programming met Java SE 8 en Java EE 7

Martijn Blankestijn

Agenda

● Context

● Sequence, zonder futures

● Futures

● CompletableFuture

● Round-up

Context

Our responsiblity

@Path("customers") public class DemoOverviewResource {

@GET @Path("{username}") @Produces(APPLICATION_JSON) public CustomerOverview retrieve( @PathParam("username") String username) {

Customer customer = getCustomerInfo(username);

Contract[] contracts = getContracts(customer); Communication[] communications = getCommunications(customer);

return createOverview( customer, contracts, communications); }

Customer

Contract

Communications

TIME

Sequential

A Future

represents

the result

of an

asynchronous computation

public interface Future<V> {

boolean isDone();

V get()

V get(long timeout, TimeUnit unit)

Customer

Contract

Communications

TIME

Sequential

Futures

Reactive programmingis a programming paradigm

oriented around

data flows

and the

propagation of change

CompletableFutureA Future that may be

explicitly completed

and may trigger actions

upon its completion.

Chaining methods

runthenAcceptthenApply

thenComposewhenComplete

Joining methods

runAfterBoththenAcceptBoththenCombine...

allOf

Model the flow

Customer

Contract

Communications

TIME

Sequential

Futures

Completable Futures

Links

● Demo: https://github.com/martijnblankestijn/reactive-rest-demo

● JAX-RS

● Completable Future

● ManagedExecutor: JSR 236 Concurrency Utilities for Java EE

● Reactive Manifesto

top related