nl-jug jfall 2014: reactive programming met java 8 en java ee 7
Post on 07-Jul-2015
294 Views
Preview:
DESCRIPTION
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