SlideShare une entreprise Scribd logo
1  sur  67
Télécharger pour lire hors ligne
June 2, 2017
IPT – Intellectual
Products & Technologies
Asynchronous
Data Stream
Processing Using
CompletableFuture
and Flow in Java 9
Trayan Iliev
tiliev@iproduct.org
http://iproduct.org
Copyright © 2003-2017 IPT - Intellectual
Products & Technologies
2
Trademarks
Oracle®, Java™ and JavaScript™ are trademarks or registered
trademarks of Oracle and/or its affiliates.
Other names may be trademarks of their respective owners.
3
Disclaimer
All information presented in this document and all supplementary
materials and programming code represent only my personal opinion
and current understanding and has not received any endorsement or
approval by IPT - Intellectual Products and Technologies or any third
party. It should not be taken as any kind of advice, and should not be
used for making any kind of decisions with potential commercial impact.
The information and code presented may be incorrect or incomplete. It is
provided "as is", without warranty of any kind, express or implied,
including but not limited to the warranties of merchantability, fitness for a
particular purpose and non-infringement. In no event shall the author or
copyright holders be liable for any claim, damages or other liability,
whether in an action of contract, tort or otherwise, arising from, out of or
in connection with the information, materials or code presented or the
use or other dealings with this information or programming code.
IPT - Intellectual Products & Technologies
4
Since 2003 we provide trainings and share skills in
JS/ TypeScript/ Node/ Express/ Socket.IO/ NoSQL/
Angular/ React / Java SE/ EE/ Web/ REST SOA:
 Node.js + Express/ hapi + React.js + Redux + GraphQL
 Angular + TypeScript + Redux (ngrx)
 Java EE6/7, Spring, JSF, Portals: Liferay, GateIn
 Reactive IoT with Reactor / RxJava / RxJS
 SOA & Distributed Hypermedia APIs (REST)
 Domain Driven Design & Reactive Microservices
5
Stream Processing with JAVA 9
 Stream based data / event / message processing for
real-time distributed SOA / microservice / database
architectures.
 PUSH (hot) and PULL (cold) event streams in Java
 CompletableFuture & CompletionStage non-blocking,
asynchronous hot event stream composition
 Reactive programming. Design patterns. Reactive
Streams (java.util.concurrent.Flow)
 Novelties in Java 9 CompletableFuture
 Examples for (reactive) hot event streams processing
Where to Find the Demo Code?
6
CompletableFuture and Flow demos are available
@ GitHub:
https://github.com/iproduct/reactive-demos-java-9
Data / Event / Message Streams
7
“Conceptually, a stream is a (potentially never-ending)
flow of data records, and a transformation is an
operation that takes one or more streams as input,
and produces one or more output streams as a
result.”
Apache Flink: Dataflow Programming Model
Data Stream Programming
8
The idea of abstracting logic from execution is hardly
new -- it was the dream of SOA. And the recent
emergence of microservices and containers shows that
the dream still lives on.
For developers, the question is whether they want to
learn yet one more layer of abstraction to their coding.
On one hand, there's the elusive promise of a common
API to streaming engines that in theory should let you
mix and match, or swap in and swap out.
Tony Baer (Ovum) @ ZDNet - Apache Beam and Spark:
New coopetition for squashing the Lambda Architecture?
Lambda Architecture - I
9
https://commons.wikimedia.org/w/index.php?curid=34963986, By Textractor - Own work, CC BY-SA 4
Lambda Architecture - II
10
https://commons.wikimedia.org/w/index.php?curid=34963987, By Textractor - Own work, CC BY-SA 4
Lambda Architecture - III
11
 Data-processing architecture designed to handle
massive quantities of data by using both batch- and
stream-processing methods
 Balances latency, throughput, fault-tolerance, big data,
real-time analytics, mitigates the latencies of map-
reduce
 Data model with an append-only, immutable data
source that serves as a system of record
 Ingesting and processing timestamped events that are
appended to existing events. State is determined from
the natural time-based ordering of the data.
Druid Distributed Data Store (Java)
12
https://commons.wikimedia.org/w/index.php?curid=33899448 By Fangjin Yang - sent to me personally, GFDL
Apache
ZooKeeper
MySQL /
PostgreSQL
HDFS /
Amazon S3
Lambda Architecture: Projects - I
13
 Apache Spark is an open-source
cluster-computing framework. Spark
Streaming leverages Spark Core's
fast scheduling capability to perform
streaming analytics. Spark MLlib - a
distributed machine learning lib.
 Apache Storm is a distributed
stream processing computation
framework – uses streams as DAG
 Apache Apex™ unified stream and
batch processing engine.
Lambda Architecture: Projects - II
14
 Apache Flink - open source stream
processing framework – Java, Scala
 Apache Beam – unified batch and
streaming, portable, extensible
 Apache Kafka - open-source stream
processing, real-time, low-latency,
unified, high-throughput, massively
scalable pub/sub message queue
architecture as distributed transaction
log - Kafka Streams, a Java library
Direct Acyclic Graphs - DAG
15
Synchronous vs. Asynchronous IO
16
DB
Synchronous
A
A
B
B
DB
Asynchronous
A
B
C
D
A
B
C
D
Example: Internet of Things (IoT)
17
CC BY 2.0, Source:
https://www.flickr.com/photos/wilgengebroed/8249565455/
Radar, GPS, lidar for navigation and obstacle
avoidance ( 2007 DARPA Urban Challenge )
IoT Services Architecture
18
Devices: Hardware + Embedded Software + Firmware
UART/ I2C/ 2G/ 3G/ LTE/ ZigBee/ 6LowPan/ BLE
Aggregation/ Bus: ESB, Message Broker
Device Gateway: Local Coordination and Event Aggregation
M2M: HTTP(/2) / WS / MQTT / CoAP
Management: TR-069 / OMA-DM / OMA LWM2M
HTTP, AMQP
Cloud (Micro)Service Mng.
Docker, Kubernetes/
Apache Brooklyn
Web/ Mobile
Portal
PaaSDashboard
PaaS API: Event Processing Services, Analytics
All Sensors Provide Hot Streams
19
20
 Performance is about 2 things (Martin Thompson –
http://www.infoq.com/articles/low-latency-vp ):
– Throughput – units per second, and
– Latency – response time
 Real-time – time constraint from input to response
regardless of system load.
 Hard real-time system if this constraint is not honored then
a total system failure can occur.
 Soft real-time system – low latency response with little
deviation in response time
 100 nano-seconds to 100 milli-seconds. [Peter Lawrey]
What's High Performance?
21
 Low garbage by reusing existing objects + infrequent GC
when application not busy – can improve app 2 - 5x
 JVM generational GC startegy – ideal for objects living very
shortly (garbage collected next minor sweep) or be immortal
 Non-blocking, lockless coding or CAS
 Critical data structures – direct memory access using
DirectByteBuffers or Unsafe => predictable memory layout
and cache misses avoidance
 Busy waiting – giving the CPU to OS kernel slows program
2-5x => avoid context switches
 Amortize the effect of expensive IO - blocking
Low Latency: Things to Remember
22
 Non-blocking (synchronous) implementation is 2 orders of
magnitude better then synchronized
 We should try to avoid blocking and especially contended
blocking if want to achieve low latency
 If blocking is a must we have to prefer CAS and optimistic
concurrency over blocking (but have in mind it always
depends on concurrent problem at hand and how much
contention do we experience – test early, test often,
microbenchmarks are unreliable and highly platform dependent
– test real application with typical load patterns)
 The real question is: HOW is is possible to build concurrency
without blocking?
Mutex Comparison => Conclusions
23
 Queues typically use either linked-lists or arrays for the
underlying storage of elements. Linked lists are not
„mechanically sympathetic” – there is no predictable
caching “stride” (should be less than 2048 bytes in each
direction).
 Bounded queues often experience write contention on
head, tail, and size variables. Even if head and tail
separated using CAS, they usually are in the same cache-
line.
 Queues produce much garbage.
 Typical queues conflate a number of different concerns –
producer and consumer synchronization and data storage
Blocking Queues Disadvantages
[http://lmax-exchange.github.com/disruptor/files/Disruptor-1.0.pdf]
24
CPU Cache – False Sharing
Core 2 Core NCore 1 ...
Registers
Execution Units
L1 Cache A | | B |
L2 Cache A | | B |
L3 Cache A | | B |
DRAM Memory
A | | B |
Registers
Execution Units
L1 Cache A | | B |
L2 Cache A | | B |
Tracking Complexity
25
We need tools to cope with all that complexity inherent in
robotics and IoT domains.
Simple solutions are needed – cope with problems through
divide and concur on different levels of abstraction:
Domain Driven Design (DDD) – back to basics:
domain objects, data and logic.
Described by Eric Evans in his book:
Domain Driven Design: Tackling Complexity in the Heart of
Software, 2004
Domain Driven Design
26
Main concepts:
 Entities, value objects and modules
 Aggregates and Aggregate Roots [Haywood]:
value < entity < aggregate < module < BC
 Aggregate Roots are exposed as Open Host Services
 Repositories, Factories and Services:
application services <-> domain services
 Separating interface from implementation
Microservices and DDD
27
Actually DDD require additional efforts (as most other
divide and concur modeling approaches :)
 Ubiquitous language and Bounded Contexts
 DDD Application Layers:
Infrastructure, Domain, Application, Presentation
 Hexagonal architecture :
OUTSIDE <-> transformer <->
( application <-> domain )
[A. Cockburn]
Imperative and Reactive
28
We live in a Connected Universe
... there is hypothesis that all
the things in the Universe are
intimately connected, and you
can not change a bit without
changing all.
Action – Reaction principle is
the essence of how Universe
behaves.
Imperative and Reactive
 Reactive Programming: using static or dynamic data
flows and propagation of change
Example: a := b + c
 Functional Programming: evaluation of mathematical
functions,
➢ Avoids changing-state and mutable data, declarative
programming
➢ Side effects free => much easier to understand and
predict the program behavior.
Example: books.stream().filter(book -> book.getYear() > 2010)
.forEach( System.out::println )
Functional Reactive (FRP)
30
According to Connal Elliot's (ground-breaking paper @
Conference on Functional Programming, 1997), FRP is:
(a) Denotative
(b) Temporally continuous
Reactive Manifesto
31
[http://www.reactivemanifesto.org]
32
 Message Driven – asynchronous message-passing allows
to establish a boundary between components that ensures
loose coupling, isolation, location transparency, and
provides the means to delegate errors as messages
[Reactive Manifesto].
 The main idea is to separate concurrent producer and
consumer workers by using message queues.
 Message queues can be unbounded or bounded (limited
max number of messages)
 Unbounded message queues can present memory
allocation problem in case the producers outrun the
consumers for a long period → OutOfMemoryError
Scalable, Massively Concurrent
Reactive Programming
33
 Microsoft®
opens source polyglot project ReactiveX
(Reactive Extensions) [http://reactivex.io]:
Rx = Observables + LINQ + Schedulers :)
Java: RxJava, JavaScript: RxJS, C#: Rx.NET, Scala: RxScala,
Clojure: RxClojure, C++: RxCpp, Ruby: Rx.rb, Python: RxPY,
Groovy: RxGroovy, JRuby: RxJRuby, Kotlin: RxKotlin ...
 Reactive Streams Specification
[http://www.reactive-streams.org/] used by:
 (Spring) Project Reactor [http://projectreactor.io/]
 Actor Model – Akka (Java, Scala) [http://akka.io/]
Trayan Iliev
IPT – Intellectual Products & Technologies
Ltd.
Multi-Agent
Systems & Social
Robotics
15/01/2015 Slide 34Copyright © 2003-2015 IPT – Intellectual Products & Technologies Ltd. All rights
reserved.
Подход на интелигентните агенти при
моделиране на знания и системи
Reactive Streams Spec.
35
 Reactive Streams – provides standard for
asynchronous stream processing with non-blocking
back pressure.
 Minimal set of interfaces, methods and protocols for
asynchronous data streams
 April 30, 2015: has been released version 1.0.0 of
Reactive Streams for the JVM (Java API,
Specification, TCK and implementation examples)
 Java 9: java.util.concurrent.Flow
Reactive Streams Spec.
36
 Publisher – provider of potentially unbounded number
of sequenced elements, according to Subscriber(s)
demand.
Publisher.subscribe(Subscriber) => onSubscribe onNext*
(onError | onComplete)?
 Subscriber – calls Subscription.request(long) to
receive notifications
 Subscription – one-to-one Subscriber ↔ Publisher,
request data and cancel demand (allow cleanup).
 Processor = Subscriber + Publisher
FRP = Async Data Streams
37
 FRP is asynchronous data-flow programming using the
building blocks of functional programming (e.g. map,
reduce, filter) and explicitly modeling time
 Used for GUIs, robotics, and music. Example (RxJava):
Observable.from(
new String[]{"Reactive", "Extensions", "Java"})
.take(2).map(s -> s + " : on " + new Date())
.subscribe(s -> System.out.println(s));
Result:
Reactive : on Wed Jun 17 21:54:02 GMT+02:00 2015
Extensions : on Wed Jun 17 21:54:02 GMT+02:00 2015
Project Reactor
38
 Reactor project allows building high-performance (low
latency high throughput) non-blocking asynchronous
applications on JVM.
 Reactor is designed to be extraordinarily fast and can
sustain throughput rates on order of 10's of millions of
operations per second.
 Reactor has powerful API for declaring data
transformations and functional composition.
 Makes use of the concept of Mechanical Sympathy
built on top of Disruptor / RingBuffer.
Reactor Projects
39
https://github.com/reactor/reactor, Apache Software License 2.0
IPC – Netty, Kafka, Aeron
Reactor Flux
40
https://github.com/reactor/reactor-core, Apache Software License 2.0
Example: Flux.combineLatest()
41
https://projectreactor.io/core/docs/api/, Apache Software License 2.0
Flux Design Pattern
Source: Flux in GitHub, https://github.com/facebook/flux, License: BSD 3-clause "New" License
Linear flow:
Source: @ngrx/store in GitHub, https://gist.github.com/btroncone/a6e4347326749f938510
Redux Design Pattern
Source: RxJava 2 API documentation, http://reactivex.io/RxJava/2.x/javadoc/
Redux == Rx Scan Opearator
Hot and Cold Event Streams
45
 PULL-based (Cold Event Streams) – Cold streams (e.g.
RxJava Observable / Flowable or Reactor Flow / Mono)
are streams that run their sequence when and if they
are subscribed to. They present the sequence from the
start to each subscriber.
 PUSH-based (Hot Event Streams) – Hot streams emit
values independent of individual subscriptions. They
have their own timeline and events occur whether
someone is listening or not. An example of this is
mouse events. A mouse is generating events regardless
of whether there is a subscription. When subscription is
made observer receives current events as they happen.
Cold RxJava 2 Flowable Example
46
Flowable<String> cold = Flowable.just("Hello",
"Reactive", "World", "from", "RxJava", "!");
cold.subscribe(i -> System.out.println("First: " + i));
Thread.sleep(500);
cold.subscribe(i -> System.out.println("Second: " + i));
Results:
First: Hello
First: Reactive
First: World
First: from
First: RxJava
First: !
Second: Hello
Second: Reactive
Second: World
Second: from
Second: RxJava
Second: !
Cold RxJava Example 2
47
Flowable<Long> cold = Flowable.intervalRange(1,10,0,200,
TimeUnit.MILLISECONDS);
cold.subscribe(i -> System.out.println("First: " + i));
Thread.sleep(500);
cold.subscribe(i -> System.out.println("Second: " + i));
Thread.sleep(3000);
Results:
First: 1
First: 2
First: 3
Second: 1
First: 4
Second: 2
First: 5
Second: 3
First: 6
Second: 4
First: 7
Second: 5
First: 8
Second: 6
First: 9
Second: 7
First: 10
Second: 8
Second: 9
Second: 10
Hot Stream RxJava 2 Example
48
ConnectableFlowable<Long> hot =
Flowable.intervalRange(1,10,0,200,TimeUnit.MILLISECONDS)
.publish();;
hot.connect(); // start emmiting Flowable -> Subscribers
hot.subscribe(i -> System.out.println("First: " + i));
Thread.sleep(500);
hot.subscribe(i -> System.out.println("Second: " + i));
Thread.sleep(3000);
Results:
First: 2
First: 3
First: 4
Second: 4
First: 5
Second: 5
First: 6
Second: 6
First: 7
Second: 7
First: 8
Second: 8
First: 9
Second: 9
First: 10
Second: 10
Converting Cold to Hot Stream
49
Cold Stream Example – Reactor
50
Flux.fromIterable(getSomeLongList())
.mergeWith(Flux.interval(100))
.doOnNext(serviceA::someObserver)
.map(d -> d * 2)
.take(3)
.onErrorResumeWith(errorHandler::fallback)
.doAfterTerminate(serviceM::incrementTerminate)
.subscribe(System.out::println);
https://github.com/reactor/reactor-core, Apache Software License 2.0
Hot Stream Example - Reactor
51
public static void main(String... args) throws
InterruptedException {
EmitterProcessor<String> emitter =
EmitterProcessor.create();
BlockingSink<String> sink = emitter.connectSink();
emitter.publishOn(Schedulers.single())
.map(String::toUpperCase)
.filter(s → s.startsWith("HELLO"))
.delayMillis(1000).subscribe(System.out::println);
sink.submit("Hello World!"); // emit - non blocking
sink.submit("Goodbye World!");
sink.submit("Hello Trayan!");
Thread.sleep(3000);
}
Example: IPTPI - RPi + Ardunio Robot
52
 Raspberry Pi 2 (quad-core ARMv7
@ 900MHz) + Arduino Leonardo
cloneA-Star 32U4 Micro
 Optical encoders (custom), IR
optical array, 3D accelerometers,
gyros, and compass MinIMU-9 v2
 IPTPI is programmed in Java
using Pi4J, Reactor, RxJava, Akka
 More information about IPTPI:
http://robolearn.org/iptpi-robot/
IPTPI Hot Event Streams Example
53
Encoder
Readings
ArduinoData
Flux
Arduino
SerialData
Position
Flux
Robot
Positions
Command
Movement
Subscriber
RobotWSService
(using Reactor)
Angular 2 /
TypeScript
MovementCommands
Futures in Java 8 - I
54
 Future (implemented by FutureTask) – represents the
result of an cancelable asynchronous computation.
Methods are provided to check if the computation is
complete, to wait for its completion, and to retrieve the
result of the computation (blocking till its ready).
 RunnableFuture – a Future that is Runnable.
Successful execution of the run method causes Future
completion, and allows access to its results.
 ScheduledFuture – delayed cancelable action that
returns result. Usually a scheduled future is the result
of scheduling a task with a ScheduledExecutorService
Future Use Example
55
Future<String> future = executor.submit(
new Callable<String>() {
public String call() {
return searchService.findByTags(tags);
}
}
);
DoSomethingOther();
try {
showResult(future.get()); // use future result
} catch (ExecutionException ex) { cleanup(); }
Futures in Java 8 - II
56
 CompletableFuture – a Future that may be explicitly
completed (by setting its value and status), and may
be used as a CompletionStage, supporting dependent
functions and actions that trigger upon its completion.
 CompletionStage – a stage of possibly asynchronous
computation, that is triggered by completion of
previous stage or stages (CompletionStages form
Direct Acyclic Graph – DAG). A stage performs an
action or computes value and completes upon
termination of its computation, which in turn triggers
next dependent stages. Computation may be Function
(apply), Consumer (accept), or Runnable (run).
CompletableFuture Example - I
57
private CompletableFuture<String>
longCompletableFutureTask(int i, Executor executor) {
return CompletableFuture.supplyAsync(() -> {
try {
Thread.sleep(1000); // long computation :)
} catch (InterruptedException e) {
e.printStackTrace();
}
return i + "-" + "test";
}, executor);
}
CompletableFuture Example - II
58
ExecutorService executor = ForkJoinPool.commonPool();
//ExecutorService executor = Executors.newCachedThreadPool();
public void testlCompletableFutureSequence() {
List<CompletableFuture<String>> futuresList =
IntStream.range(0, 20).boxed()
.map(i -> longCompletableFutureTask(i, executor)
.exceptionally(t -> t.getMessage()))
.collect(Collectors.toList());
CompletableFuture<List<String>> results =
CompletableFuture.allOf(
futuresList.toArray(new CompletableFuture[0]))
.thenApply(v -> futuresList.stream()
.map(CompletableFuture::join)
.collect(Collectors.toList())
);
CompletableFuture Example - III
59
try {
System.out.println(results.get(10, TimeUnit.SECONDS));
} catch (ExecutionException | TimeoutException
| InterruptedException e) {
e.printStackTrace();
}
executor.shutdown();
}
// OR just:
System.out.println(results.join());
executor.shutdown();
Which is better?
CompletionStage
60
 Computation may be Function (apply), Consumer
(accept), or Runnable (run) – e.g.:
completionStage.thenApply( x -> x * x )
.thenAccept(System.out::print )
.thenRun( System.out::println )
 Stage computation can be triggered by completion of
1 (then), 2 (combine), or either 1 of 2 (either)
 Functional composition can be applied to stages
themselves instead to their results using compose
 handle & whenComplete – support unconditional
computation – both normal or exceptional triggering
CompletionStages Composition
61
public void testlCompletableFutureComposition() throws
InterruptedException, ExecutionException {
Double priceInEuro = CompletableFuture.supplyAsync(()
-> getStockPrice("GOOGL"))
.thenCombine(CompletableFuture.supplyAsync(() ->
getExchangeRate(USD, EUR)), this::convertPrice)
.exceptionally(throwable -> {
System.out.println("Error: " +
throwable.getMessage());
return -1d;
}).get();
System.out.println("GOOGL stock price in Euro: " +
priceInEuro );
}
New in Java 9: CompletableFuture
62
 Executor defaultExecutor()
 CompletableFuture<U> newIncompleteFuture()
 CompletableFuture<T> copy()
 CompletionStage<T> minimalCompletionStage()
 CompletableFuture<T> completeAsync(
Supplier<? extends T> supplier[, Executor executor])
 CompletableFuture<T> orTimeout(
long timeout, TimeUnit unit)
 CompletableFuture<T> completeOnTimeout(
T value, long timeout, TimeUnit unit)
More Demos ...
63
CompletableFuture, Flow & RxJava2 @ GitHub:
https://github.com/iproduct/reactive-demos-java-9
 completable-future-demo – composition, delayed, ...
 flow-demo – custom Flow implementations using CFs
 rxjava2-demo – RxJava2 intro to reactive composition
 completable-future-jaxrs-cdi-cxf – async observers, ...
 completable-future-jaxrs-cdi-jersey
 completable-future-jaxrs-cdi-jersey-client
Ex.1: Async CDI Events with CF
64
@Inject @CpuProfiling private Event<CpuLoad> event; ...
IntervalPublisher.getDefaultIntervalPublisher(
500, TimeUnit.MILLISECONDS) // Custom CF Flow Publisher
.subscribe(new Subscriber<Integer>() {
@Override public void onComplete() {}
@Override public void onError(Throwable t) {}
@Override public void onNext(Integer i) {
event.fireAsync(new CpuLoad(
System.currentTimeMillis(), getJavaCPULoad(),
areProcessesChanged()))
.thenAccept(event -> {
logger.info("CPU load event fired: " + event);
}); } //firing CDI async event returns CF
@Override public void onSubscribe(Subscription
subscription) {subscription.request(Long.MAX_VALUE);} });
Ex.2: Reactive JAX-RS Client - CF
65
CompletionStage<List<ProcessInfo>> processesStage =
processes.request().rx()
.get(new GenericType<List<ProcessInfo>>() {})
.exceptionally(throwable -> {
logger.error("Error: " + throwable.getMessage());
return Collections.emptyList();
});
CompletionStage<Void> printProcessesStage =
processesStage.thenApply(proc -> {
System.out.println("Active JAVA Processes: " + proc);
return null;
});
Ex.2: Reactive JAX-RS Client - CF
66
(- continues -)
printProcessesStage.thenRun( () -> {
try (SseEventSource source =
SseEventSource.target(stats).build()) {
source.register(System.out::println);
source.open();
Thread.sleep(20000); // Consume events for 20 sec
} catch (InterruptedException e) {
logger.info("SSE consumer interrupted: " + e);
}
})
.thenRun(() -> {System.exit(0);});
Thank’s for Your Attention!
67
Trayan Iliev
CEO of IPT – Intellectual Products
& Technologies
http://iproduct.org/
http://robolearn.org/
https://github.com/iproduct
https://twitter.com/trayaniliev
https://www.facebook.com/IPT.EACAD
https://plus.google.com/+IproductOrg

Contenu connexe

Tendances

Rapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and KtorRapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and KtorTrayan Iliev
 
Reactive Java Robotics IoT - jPrime 2016
Reactive Java Robotics IoT - jPrime 2016Reactive Java Robotics IoT - jPrime 2016
Reactive Java Robotics IoT - jPrime 2016Trayan Iliev
 
IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016Trayan Iliev
 
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016Trayan Iliev
 
OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...
OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...
OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...Pôle Systematic Paris-Region
 
Productionizing Machine Learning - Bigdata meetup 5-06-2019
Productionizing Machine Learning - Bigdata meetup 5-06-2019Productionizing Machine Learning - Bigdata meetup 5-06-2019
Productionizing Machine Learning - Bigdata meetup 5-06-2019Iulian Pintoiu
 
Indiana University's Advanced Science Gateway Support
Indiana University's Advanced Science Gateway SupportIndiana University's Advanced Science Gateway Support
Indiana University's Advanced Science Gateway Supportmarpierc
 
OGCE Project Overview
OGCE Project OverviewOGCE Project Overview
OGCE Project Overviewmarpierc
 
Project Hydrogen: State-of-the-Art Deep Learning on Apache Spark
Project Hydrogen: State-of-the-Art Deep Learning on Apache SparkProject Hydrogen: State-of-the-Art Deep Learning on Apache Spark
Project Hydrogen: State-of-the-Art Deep Learning on Apache SparkDatabricks
 
OREChem Services and Workflows
OREChem Services and WorkflowsOREChem Services and Workflows
OREChem Services and Workflowsmarpierc
 
Data Streaming Technology Overview
Data Streaming Technology OverviewData Streaming Technology Overview
Data Streaming Technology OverviewDan Lynn
 
Strata EU 2014: Spark Streaming Case Studies
Strata EU 2014: Spark Streaming Case StudiesStrata EU 2014: Spark Streaming Case Studies
Strata EU 2014: Spark Streaming Case StudiesPaco Nathan
 
ACES QuakeSim 2011
ACES QuakeSim 2011ACES QuakeSim 2011
ACES QuakeSim 2011marpierc
 
Updates from Project Hydrogen: Unifying State-of-the-Art AI and Big Data in A...
Updates from Project Hydrogen: Unifying State-of-the-Art AI and Big Data in A...Updates from Project Hydrogen: Unifying State-of-the-Art AI and Big Data in A...
Updates from Project Hydrogen: Unifying State-of-the-Art AI and Big Data in A...Databricks
 
A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...
A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...
A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...Databricks
 
7 New Tools Java Developers Should Know
7 New Tools Java Developers Should Know7 New Tools Java Developers Should Know
7 New Tools Java Developers Should KnowTakipi
 
20120907 microbiome-intro
20120907 microbiome-intro20120907 microbiome-intro
20120907 microbiome-introLeo Lahti
 
Real world machine learning with Java for Fumankaitori.com
Real world machine learning with Java for Fumankaitori.comReal world machine learning with Java for Fumankaitori.com
Real world machine learning with Java for Fumankaitori.comMathieu Dumoulin
 
Paris Data Geek - Spark Streaming
Paris Data Geek - Spark Streaming Paris Data Geek - Spark Streaming
Paris Data Geek - Spark Streaming Djamel Zouaoui
 
On-Prem Solution for the Selection of Wind Energy Models
On-Prem Solution for the Selection of Wind Energy ModelsOn-Prem Solution for the Selection of Wind Energy Models
On-Prem Solution for the Selection of Wind Energy ModelsDatabricks
 

Tendances (20)

Rapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and KtorRapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and Ktor
 
Reactive Java Robotics IoT - jPrime 2016
Reactive Java Robotics IoT - jPrime 2016Reactive Java Robotics IoT - jPrime 2016
Reactive Java Robotics IoT - jPrime 2016
 
IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016
 
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016
 
OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...
OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...
OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...
 
Productionizing Machine Learning - Bigdata meetup 5-06-2019
Productionizing Machine Learning - Bigdata meetup 5-06-2019Productionizing Machine Learning - Bigdata meetup 5-06-2019
Productionizing Machine Learning - Bigdata meetup 5-06-2019
 
Indiana University's Advanced Science Gateway Support
Indiana University's Advanced Science Gateway SupportIndiana University's Advanced Science Gateway Support
Indiana University's Advanced Science Gateway Support
 
OGCE Project Overview
OGCE Project OverviewOGCE Project Overview
OGCE Project Overview
 
Project Hydrogen: State-of-the-Art Deep Learning on Apache Spark
Project Hydrogen: State-of-the-Art Deep Learning on Apache SparkProject Hydrogen: State-of-the-Art Deep Learning on Apache Spark
Project Hydrogen: State-of-the-Art Deep Learning on Apache Spark
 
OREChem Services and Workflows
OREChem Services and WorkflowsOREChem Services and Workflows
OREChem Services and Workflows
 
Data Streaming Technology Overview
Data Streaming Technology OverviewData Streaming Technology Overview
Data Streaming Technology Overview
 
Strata EU 2014: Spark Streaming Case Studies
Strata EU 2014: Spark Streaming Case StudiesStrata EU 2014: Spark Streaming Case Studies
Strata EU 2014: Spark Streaming Case Studies
 
ACES QuakeSim 2011
ACES QuakeSim 2011ACES QuakeSim 2011
ACES QuakeSim 2011
 
Updates from Project Hydrogen: Unifying State-of-the-Art AI and Big Data in A...
Updates from Project Hydrogen: Unifying State-of-the-Art AI and Big Data in A...Updates from Project Hydrogen: Unifying State-of-the-Art AI and Big Data in A...
Updates from Project Hydrogen: Unifying State-of-the-Art AI and Big Data in A...
 
A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...
A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...
A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...
 
7 New Tools Java Developers Should Know
7 New Tools Java Developers Should Know7 New Tools Java Developers Should Know
7 New Tools Java Developers Should Know
 
20120907 microbiome-intro
20120907 microbiome-intro20120907 microbiome-intro
20120907 microbiome-intro
 
Real world machine learning with Java for Fumankaitori.com
Real world machine learning with Java for Fumankaitori.comReal world machine learning with Java for Fumankaitori.com
Real world machine learning with Java for Fumankaitori.com
 
Paris Data Geek - Spark Streaming
Paris Data Geek - Spark Streaming Paris Data Geek - Spark Streaming
Paris Data Geek - Spark Streaming
 
On-Prem Solution for the Selection of Wind Energy Models
On-Prem Solution for the Selection of Wind Energy ModelsOn-Prem Solution for the Selection of Wind Energy Models
On-Prem Solution for the Selection of Wind Energy Models
 

Similaire à Stream Processing with CompletableFuture and Flow in Java 9

Apache Kafka - Scalable Message-Processing and more !
Apache Kafka - Scalable Message-Processing and more !Apache Kafka - Scalable Message-Processing and more !
Apache Kafka - Scalable Message-Processing and more !Guido Schmutz
 
Reactive Java Robotics & IoT with Spring Reactor
Reactive Java Robotics & IoT with Spring ReactorReactive Java Robotics & IoT with Spring Reactor
Reactive Java Robotics & IoT with Spring ReactorTrayan Iliev
 
Anomaly Detection at Scale
Anomaly Detection at ScaleAnomaly Detection at Scale
Anomaly Detection at ScaleJeff Henrikson
 
Apache Kafka® and the Data Mesh
Apache Kafka® and the Data MeshApache Kafka® and the Data Mesh
Apache Kafka® and the Data MeshConfluentInc1
 
OS for AI: Elastic Microservices & the Next Gen of ML
OS for AI: Elastic Microservices & the Next Gen of MLOS for AI: Elastic Microservices & the Next Gen of ML
OS for AI: Elastic Microservices & the Next Gen of MLNordic APIs
 
Scaling Security on 100s of Millions of Mobile Devices Using Apache Kafka® an...
Scaling Security on 100s of Millions of Mobile Devices Using Apache Kafka® an...Scaling Security on 100s of Millions of Mobile Devices Using Apache Kafka® an...
Scaling Security on 100s of Millions of Mobile Devices Using Apache Kafka® an...confluent
 
Big Data Streams Architectures. Why? What? How?
Big Data Streams Architectures. Why? What? How?Big Data Streams Architectures. Why? What? How?
Big Data Streams Architectures. Why? What? How?Anton Nazaruk
 
Building and deploying LLM applications with Apache Airflow
Building and deploying LLM applications with Apache AirflowBuilding and deploying LLM applications with Apache Airflow
Building and deploying LLM applications with Apache AirflowKaxil Naik
 
Slim Baltagi – Flink vs. Spark
Slim Baltagi – Flink vs. SparkSlim Baltagi – Flink vs. Spark
Slim Baltagi – Flink vs. SparkFlink Forward
 
Data Applications and Infrastructure at LinkedIn__HadoopSummit2010
Data Applications and Infrastructure at LinkedIn__HadoopSummit2010Data Applications and Infrastructure at LinkedIn__HadoopSummit2010
Data Applications and Infrastructure at LinkedIn__HadoopSummit2010Yahoo Developer Network
 
UnConference for Georgia Southern Computer Science March 31, 2015
UnConference for Georgia Southern Computer Science March 31, 2015UnConference for Georgia Southern Computer Science March 31, 2015
UnConference for Georgia Southern Computer Science March 31, 2015Christopher Curtin
 
AI&BigData Lab 2016. Сарапин Виктор: Размер имеет значение: анализ по требова...
AI&BigData Lab 2016. Сарапин Виктор: Размер имеет значение: анализ по требова...AI&BigData Lab 2016. Сарапин Виктор: Размер имеет значение: анализ по требова...
AI&BigData Lab 2016. Сарапин Виктор: Размер имеет значение: анализ по требова...GeeksLab Odessa
 
Proactive ops for container orchestration environments
Proactive ops for container orchestration environmentsProactive ops for container orchestration environments
Proactive ops for container orchestration environmentsDocker, Inc.
 
Reactive robotics io_t_2017
Reactive robotics io_t_2017Reactive robotics io_t_2017
Reactive robotics io_t_2017Trayan Iliev
 

Similaire à Stream Processing with CompletableFuture and Flow in Java 9 (20)

optimizing_ceph_flash
optimizing_ceph_flashoptimizing_ceph_flash
optimizing_ceph_flash
 
Apache Kafka - Scalable Message-Processing and more !
Apache Kafka - Scalable Message-Processing and more !Apache Kafka - Scalable Message-Processing and more !
Apache Kafka - Scalable Message-Processing and more !
 
Reactive Java Robotics & IoT with Spring Reactor
Reactive Java Robotics & IoT with Spring ReactorReactive Java Robotics & IoT with Spring Reactor
Reactive Java Robotics & IoT with Spring Reactor
 
Anomaly Detection at Scale
Anomaly Detection at ScaleAnomaly Detection at Scale
Anomaly Detection at Scale
 
Apache Kafka® and the Data Mesh
Apache Kafka® and the Data MeshApache Kafka® and the Data Mesh
Apache Kafka® and the Data Mesh
 
OS for AI: Elastic Microservices & the Next Gen of ML
OS for AI: Elastic Microservices & the Next Gen of MLOS for AI: Elastic Microservices & the Next Gen of ML
OS for AI: Elastic Microservices & the Next Gen of ML
 
Scaling Security on 100s of Millions of Mobile Devices Using Apache Kafka® an...
Scaling Security on 100s of Millions of Mobile Devices Using Apache Kafka® an...Scaling Security on 100s of Millions of Mobile Devices Using Apache Kafka® an...
Scaling Security on 100s of Millions of Mobile Devices Using Apache Kafka® an...
 
Big Data Streams Architectures. Why? What? How?
Big Data Streams Architectures. Why? What? How?Big Data Streams Architectures. Why? What? How?
Big Data Streams Architectures. Why? What? How?
 
Building and deploying LLM applications with Apache Airflow
Building and deploying LLM applications with Apache AirflowBuilding and deploying LLM applications with Apache Airflow
Building and deploying LLM applications with Apache Airflow
 
Slim Baltagi – Flink vs. Spark
Slim Baltagi – Flink vs. SparkSlim Baltagi – Flink vs. Spark
Slim Baltagi – Flink vs. Spark
 
Flink vs. Spark
Flink vs. SparkFlink vs. Spark
Flink vs. Spark
 
Real time analytics
Real time analyticsReal time analytics
Real time analytics
 
kumarResume
kumarResumekumarResume
kumarResume
 
Data Applications and Infrastructure at LinkedIn__HadoopSummit2010
Data Applications and Infrastructure at LinkedIn__HadoopSummit2010Data Applications and Infrastructure at LinkedIn__HadoopSummit2010
Data Applications and Infrastructure at LinkedIn__HadoopSummit2010
 
Distributed Systems in Data Engineering
Distributed Systems in Data EngineeringDistributed Systems in Data Engineering
Distributed Systems in Data Engineering
 
UnConference for Georgia Southern Computer Science March 31, 2015
UnConference for Georgia Southern Computer Science March 31, 2015UnConference for Georgia Southern Computer Science March 31, 2015
UnConference for Georgia Southern Computer Science March 31, 2015
 
AI&BigData Lab 2016. Сарапин Виктор: Размер имеет значение: анализ по требова...
AI&BigData Lab 2016. Сарапин Виктор: Размер имеет значение: анализ по требова...AI&BigData Lab 2016. Сарапин Виктор: Размер имеет значение: анализ по требова...
AI&BigData Lab 2016. Сарапин Виктор: Размер имеет значение: анализ по требова...
 
As34269277
As34269277As34269277
As34269277
 
Proactive ops for container orchestration environments
Proactive ops for container orchestration environmentsProactive ops for container orchestration environments
Proactive ops for container orchestration environments
 
Reactive robotics io_t_2017
Reactive robotics io_t_2017Reactive robotics io_t_2017
Reactive robotics io_t_2017
 

Plus de Trayan Iliev

Learning Programming Using Robots - Sofia University Conference 2018
Learning Programming Using Robots - Sofia University Conference 2018 Learning Programming Using Robots - Sofia University Conference 2018
Learning Programming Using Robots - Sofia University Conference 2018 Trayan Iliev
 
Active Learning Using Connected Things - 2018 (in Bulgarian)
Active Learning Using Connected Things - 2018 (in Bulgarian)Active Learning Using Connected Things - 2018 (in Bulgarian)
Active Learning Using Connected Things - 2018 (in Bulgarian)Trayan Iliev
 
Fog Computing - DEV.BG 2018
Fog Computing - DEV.BG 2018Fog Computing - DEV.BG 2018
Fog Computing - DEV.BG 2018Trayan Iliev
 
React HOCs, Context and Observables
React HOCs, Context and ObservablesReact HOCs, Context and Observables
React HOCs, Context and ObservablesTrayan Iliev
 
Hackathon: “IPTPI and LeJaRo Meet The Real World”
Hackathon: “IPTPI and LeJaRo Meet The Real World”Hackathon: “IPTPI and LeJaRo Meet The Real World”
Hackathon: “IPTPI and LeJaRo Meet The Real World”Trayan Iliev
 
Java & JavaScipt Reactive Robotics and IoT 2016 @ jProfessionals
Java & JavaScipt Reactive Robotics and IoT 2016 @ jProfessionalsJava & JavaScipt Reactive Robotics and IoT 2016 @ jProfessionals
Java & JavaScipt Reactive Robotics and IoT 2016 @ jProfessionalsTrayan Iliev
 
IPT angular2 typescript SPA 2016
IPT angular2 typescript SPA 2016IPT angular2 typescript SPA 2016
IPT angular2 typescript SPA 2016Trayan Iliev
 
New MVC 1.0 JavaEE 8 API
New MVC 1.0 JavaEE 8 APINew MVC 1.0 JavaEE 8 API
New MVC 1.0 JavaEE 8 APITrayan Iliev
 
IPT High Performance Reactive Programming with JAVA 8 and JavaScript
IPT High Performance Reactive Programming with JAVA 8 and JavaScriptIPT High Performance Reactive Programming with JAVA 8 and JavaScript
IPT High Performance Reactive Programming with JAVA 8 and JavaScriptTrayan Iliev
 
IPT Workshops on Java Robotics and IoT
IPT Workshops on Java Robotics and IoTIPT Workshops on Java Robotics and IoT
IPT Workshops on Java Robotics and IoTTrayan Iliev
 
IPT – Java Robotics and IoT
IPT – Java Robotics and IoTIPT – Java Robotics and IoT
IPT – Java Robotics and IoTTrayan Iliev
 
Novelties in Java EE 7: JAX-RS 2.0 + IPT REST HATEOAS Polling Demo @ BGOUG Co...
Novelties in Java EE 7: JAX-RS 2.0 + IPT REST HATEOAS Polling Demo @ BGOUG Co...Novelties in Java EE 7: JAX-RS 2.0 + IPT REST HATEOAS Polling Demo @ BGOUG Co...
Novelties in Java EE 7: JAX-RS 2.0 + IPT REST HATEOAS Polling Demo @ BGOUG Co...Trayan Iliev
 

Plus de Trayan Iliev (12)

Learning Programming Using Robots - Sofia University Conference 2018
Learning Programming Using Robots - Sofia University Conference 2018 Learning Programming Using Robots - Sofia University Conference 2018
Learning Programming Using Robots - Sofia University Conference 2018
 
Active Learning Using Connected Things - 2018 (in Bulgarian)
Active Learning Using Connected Things - 2018 (in Bulgarian)Active Learning Using Connected Things - 2018 (in Bulgarian)
Active Learning Using Connected Things - 2018 (in Bulgarian)
 
Fog Computing - DEV.BG 2018
Fog Computing - DEV.BG 2018Fog Computing - DEV.BG 2018
Fog Computing - DEV.BG 2018
 
React HOCs, Context and Observables
React HOCs, Context and ObservablesReact HOCs, Context and Observables
React HOCs, Context and Observables
 
Hackathon: “IPTPI and LeJaRo Meet The Real World”
Hackathon: “IPTPI and LeJaRo Meet The Real World”Hackathon: “IPTPI and LeJaRo Meet The Real World”
Hackathon: “IPTPI and LeJaRo Meet The Real World”
 
Java & JavaScipt Reactive Robotics and IoT 2016 @ jProfessionals
Java & JavaScipt Reactive Robotics and IoT 2016 @ jProfessionalsJava & JavaScipt Reactive Robotics and IoT 2016 @ jProfessionals
Java & JavaScipt Reactive Robotics and IoT 2016 @ jProfessionals
 
IPT angular2 typescript SPA 2016
IPT angular2 typescript SPA 2016IPT angular2 typescript SPA 2016
IPT angular2 typescript SPA 2016
 
New MVC 1.0 JavaEE 8 API
New MVC 1.0 JavaEE 8 APINew MVC 1.0 JavaEE 8 API
New MVC 1.0 JavaEE 8 API
 
IPT High Performance Reactive Programming with JAVA 8 and JavaScript
IPT High Performance Reactive Programming with JAVA 8 and JavaScriptIPT High Performance Reactive Programming with JAVA 8 and JavaScript
IPT High Performance Reactive Programming with JAVA 8 and JavaScript
 
IPT Workshops on Java Robotics and IoT
IPT Workshops on Java Robotics and IoTIPT Workshops on Java Robotics and IoT
IPT Workshops on Java Robotics and IoT
 
IPT – Java Robotics and IoT
IPT – Java Robotics and IoTIPT – Java Robotics and IoT
IPT – Java Robotics and IoT
 
Novelties in Java EE 7: JAX-RS 2.0 + IPT REST HATEOAS Polling Demo @ BGOUG Co...
Novelties in Java EE 7: JAX-RS 2.0 + IPT REST HATEOAS Polling Demo @ BGOUG Co...Novelties in Java EE 7: JAX-RS 2.0 + IPT REST HATEOAS Polling Demo @ BGOUG Co...
Novelties in Java EE 7: JAX-RS 2.0 + IPT REST HATEOAS Polling Demo @ BGOUG Co...
 

Dernier

%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 

Dernier (20)

%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 

Stream Processing with CompletableFuture and Flow in Java 9

  • 1. June 2, 2017 IPT – Intellectual Products & Technologies Asynchronous Data Stream Processing Using CompletableFuture and Flow in Java 9 Trayan Iliev tiliev@iproduct.org http://iproduct.org Copyright © 2003-2017 IPT - Intellectual Products & Technologies
  • 2. 2 Trademarks Oracle®, Java™ and JavaScript™ are trademarks or registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
  • 3. 3 Disclaimer All information presented in this document and all supplementary materials and programming code represent only my personal opinion and current understanding and has not received any endorsement or approval by IPT - Intellectual Products and Technologies or any third party. It should not be taken as any kind of advice, and should not be used for making any kind of decisions with potential commercial impact. The information and code presented may be incorrect or incomplete. It is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and non-infringement. In no event shall the author or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the information, materials or code presented or the use or other dealings with this information or programming code.
  • 4. IPT - Intellectual Products & Technologies 4 Since 2003 we provide trainings and share skills in JS/ TypeScript/ Node/ Express/ Socket.IO/ NoSQL/ Angular/ React / Java SE/ EE/ Web/ REST SOA:  Node.js + Express/ hapi + React.js + Redux + GraphQL  Angular + TypeScript + Redux (ngrx)  Java EE6/7, Spring, JSF, Portals: Liferay, GateIn  Reactive IoT with Reactor / RxJava / RxJS  SOA & Distributed Hypermedia APIs (REST)  Domain Driven Design & Reactive Microservices
  • 5. 5 Stream Processing with JAVA 9  Stream based data / event / message processing for real-time distributed SOA / microservice / database architectures.  PUSH (hot) and PULL (cold) event streams in Java  CompletableFuture & CompletionStage non-blocking, asynchronous hot event stream composition  Reactive programming. Design patterns. Reactive Streams (java.util.concurrent.Flow)  Novelties in Java 9 CompletableFuture  Examples for (reactive) hot event streams processing
  • 6. Where to Find the Demo Code? 6 CompletableFuture and Flow demos are available @ GitHub: https://github.com/iproduct/reactive-demos-java-9
  • 7. Data / Event / Message Streams 7 “Conceptually, a stream is a (potentially never-ending) flow of data records, and a transformation is an operation that takes one or more streams as input, and produces one or more output streams as a result.” Apache Flink: Dataflow Programming Model
  • 8. Data Stream Programming 8 The idea of abstracting logic from execution is hardly new -- it was the dream of SOA. And the recent emergence of microservices and containers shows that the dream still lives on. For developers, the question is whether they want to learn yet one more layer of abstraction to their coding. On one hand, there's the elusive promise of a common API to streaming engines that in theory should let you mix and match, or swap in and swap out. Tony Baer (Ovum) @ ZDNet - Apache Beam and Spark: New coopetition for squashing the Lambda Architecture?
  • 9. Lambda Architecture - I 9 https://commons.wikimedia.org/w/index.php?curid=34963986, By Textractor - Own work, CC BY-SA 4
  • 10. Lambda Architecture - II 10 https://commons.wikimedia.org/w/index.php?curid=34963987, By Textractor - Own work, CC BY-SA 4
  • 11. Lambda Architecture - III 11  Data-processing architecture designed to handle massive quantities of data by using both batch- and stream-processing methods  Balances latency, throughput, fault-tolerance, big data, real-time analytics, mitigates the latencies of map- reduce  Data model with an append-only, immutable data source that serves as a system of record  Ingesting and processing timestamped events that are appended to existing events. State is determined from the natural time-based ordering of the data.
  • 12. Druid Distributed Data Store (Java) 12 https://commons.wikimedia.org/w/index.php?curid=33899448 By Fangjin Yang - sent to me personally, GFDL Apache ZooKeeper MySQL / PostgreSQL HDFS / Amazon S3
  • 13. Lambda Architecture: Projects - I 13  Apache Spark is an open-source cluster-computing framework. Spark Streaming leverages Spark Core's fast scheduling capability to perform streaming analytics. Spark MLlib - a distributed machine learning lib.  Apache Storm is a distributed stream processing computation framework – uses streams as DAG  Apache Apex™ unified stream and batch processing engine.
  • 14. Lambda Architecture: Projects - II 14  Apache Flink - open source stream processing framework – Java, Scala  Apache Beam – unified batch and streaming, portable, extensible  Apache Kafka - open-source stream processing, real-time, low-latency, unified, high-throughput, massively scalable pub/sub message queue architecture as distributed transaction log - Kafka Streams, a Java library
  • 16. Synchronous vs. Asynchronous IO 16 DB Synchronous A A B B DB Asynchronous A B C D A B C D
  • 17. Example: Internet of Things (IoT) 17 CC BY 2.0, Source: https://www.flickr.com/photos/wilgengebroed/8249565455/ Radar, GPS, lidar for navigation and obstacle avoidance ( 2007 DARPA Urban Challenge )
  • 18. IoT Services Architecture 18 Devices: Hardware + Embedded Software + Firmware UART/ I2C/ 2G/ 3G/ LTE/ ZigBee/ 6LowPan/ BLE Aggregation/ Bus: ESB, Message Broker Device Gateway: Local Coordination and Event Aggregation M2M: HTTP(/2) / WS / MQTT / CoAP Management: TR-069 / OMA-DM / OMA LWM2M HTTP, AMQP Cloud (Micro)Service Mng. Docker, Kubernetes/ Apache Brooklyn Web/ Mobile Portal PaaSDashboard PaaS API: Event Processing Services, Analytics
  • 19. All Sensors Provide Hot Streams 19
  • 20. 20  Performance is about 2 things (Martin Thompson – http://www.infoq.com/articles/low-latency-vp ): – Throughput – units per second, and – Latency – response time  Real-time – time constraint from input to response regardless of system load.  Hard real-time system if this constraint is not honored then a total system failure can occur.  Soft real-time system – low latency response with little deviation in response time  100 nano-seconds to 100 milli-seconds. [Peter Lawrey] What's High Performance?
  • 21. 21  Low garbage by reusing existing objects + infrequent GC when application not busy – can improve app 2 - 5x  JVM generational GC startegy – ideal for objects living very shortly (garbage collected next minor sweep) or be immortal  Non-blocking, lockless coding or CAS  Critical data structures – direct memory access using DirectByteBuffers or Unsafe => predictable memory layout and cache misses avoidance  Busy waiting – giving the CPU to OS kernel slows program 2-5x => avoid context switches  Amortize the effect of expensive IO - blocking Low Latency: Things to Remember
  • 22. 22  Non-blocking (synchronous) implementation is 2 orders of magnitude better then synchronized  We should try to avoid blocking and especially contended blocking if want to achieve low latency  If blocking is a must we have to prefer CAS and optimistic concurrency over blocking (but have in mind it always depends on concurrent problem at hand and how much contention do we experience – test early, test often, microbenchmarks are unreliable and highly platform dependent – test real application with typical load patterns)  The real question is: HOW is is possible to build concurrency without blocking? Mutex Comparison => Conclusions
  • 23. 23  Queues typically use either linked-lists or arrays for the underlying storage of elements. Linked lists are not „mechanically sympathetic” – there is no predictable caching “stride” (should be less than 2048 bytes in each direction).  Bounded queues often experience write contention on head, tail, and size variables. Even if head and tail separated using CAS, they usually are in the same cache- line.  Queues produce much garbage.  Typical queues conflate a number of different concerns – producer and consumer synchronization and data storage Blocking Queues Disadvantages [http://lmax-exchange.github.com/disruptor/files/Disruptor-1.0.pdf]
  • 24. 24 CPU Cache – False Sharing Core 2 Core NCore 1 ... Registers Execution Units L1 Cache A | | B | L2 Cache A | | B | L3 Cache A | | B | DRAM Memory A | | B | Registers Execution Units L1 Cache A | | B | L2 Cache A | | B |
  • 25. Tracking Complexity 25 We need tools to cope with all that complexity inherent in robotics and IoT domains. Simple solutions are needed – cope with problems through divide and concur on different levels of abstraction: Domain Driven Design (DDD) – back to basics: domain objects, data and logic. Described by Eric Evans in his book: Domain Driven Design: Tackling Complexity in the Heart of Software, 2004
  • 26. Domain Driven Design 26 Main concepts:  Entities, value objects and modules  Aggregates and Aggregate Roots [Haywood]: value < entity < aggregate < module < BC  Aggregate Roots are exposed as Open Host Services  Repositories, Factories and Services: application services <-> domain services  Separating interface from implementation
  • 27. Microservices and DDD 27 Actually DDD require additional efforts (as most other divide and concur modeling approaches :)  Ubiquitous language and Bounded Contexts  DDD Application Layers: Infrastructure, Domain, Application, Presentation  Hexagonal architecture : OUTSIDE <-> transformer <-> ( application <-> domain ) [A. Cockburn]
  • 28. Imperative and Reactive 28 We live in a Connected Universe ... there is hypothesis that all the things in the Universe are intimately connected, and you can not change a bit without changing all. Action – Reaction principle is the essence of how Universe behaves.
  • 29. Imperative and Reactive  Reactive Programming: using static or dynamic data flows and propagation of change Example: a := b + c  Functional Programming: evaluation of mathematical functions, ➢ Avoids changing-state and mutable data, declarative programming ➢ Side effects free => much easier to understand and predict the program behavior. Example: books.stream().filter(book -> book.getYear() > 2010) .forEach( System.out::println )
  • 30. Functional Reactive (FRP) 30 According to Connal Elliot's (ground-breaking paper @ Conference on Functional Programming, 1997), FRP is: (a) Denotative (b) Temporally continuous
  • 32. 32  Message Driven – asynchronous message-passing allows to establish a boundary between components that ensures loose coupling, isolation, location transparency, and provides the means to delegate errors as messages [Reactive Manifesto].  The main idea is to separate concurrent producer and consumer workers by using message queues.  Message queues can be unbounded or bounded (limited max number of messages)  Unbounded message queues can present memory allocation problem in case the producers outrun the consumers for a long period → OutOfMemoryError Scalable, Massively Concurrent
  • 33. Reactive Programming 33  Microsoft® opens source polyglot project ReactiveX (Reactive Extensions) [http://reactivex.io]: Rx = Observables + LINQ + Schedulers :) Java: RxJava, JavaScript: RxJS, C#: Rx.NET, Scala: RxScala, Clojure: RxClojure, C++: RxCpp, Ruby: Rx.rb, Python: RxPY, Groovy: RxGroovy, JRuby: RxJRuby, Kotlin: RxKotlin ...  Reactive Streams Specification [http://www.reactive-streams.org/] used by:  (Spring) Project Reactor [http://projectreactor.io/]  Actor Model – Akka (Java, Scala) [http://akka.io/]
  • 34. Trayan Iliev IPT – Intellectual Products & Technologies Ltd. Multi-Agent Systems & Social Robotics 15/01/2015 Slide 34Copyright © 2003-2015 IPT – Intellectual Products & Technologies Ltd. All rights reserved. Подход на интелигентните агенти при моделиране на знания и системи
  • 35. Reactive Streams Spec. 35  Reactive Streams – provides standard for asynchronous stream processing with non-blocking back pressure.  Minimal set of interfaces, methods and protocols for asynchronous data streams  April 30, 2015: has been released version 1.0.0 of Reactive Streams for the JVM (Java API, Specification, TCK and implementation examples)  Java 9: java.util.concurrent.Flow
  • 36. Reactive Streams Spec. 36  Publisher – provider of potentially unbounded number of sequenced elements, according to Subscriber(s) demand. Publisher.subscribe(Subscriber) => onSubscribe onNext* (onError | onComplete)?  Subscriber – calls Subscription.request(long) to receive notifications  Subscription – one-to-one Subscriber ↔ Publisher, request data and cancel demand (allow cleanup).  Processor = Subscriber + Publisher
  • 37. FRP = Async Data Streams 37  FRP is asynchronous data-flow programming using the building blocks of functional programming (e.g. map, reduce, filter) and explicitly modeling time  Used for GUIs, robotics, and music. Example (RxJava): Observable.from( new String[]{"Reactive", "Extensions", "Java"}) .take(2).map(s -> s + " : on " + new Date()) .subscribe(s -> System.out.println(s)); Result: Reactive : on Wed Jun 17 21:54:02 GMT+02:00 2015 Extensions : on Wed Jun 17 21:54:02 GMT+02:00 2015
  • 38. Project Reactor 38  Reactor project allows building high-performance (low latency high throughput) non-blocking asynchronous applications on JVM.  Reactor is designed to be extraordinarily fast and can sustain throughput rates on order of 10's of millions of operations per second.  Reactor has powerful API for declaring data transformations and functional composition.  Makes use of the concept of Mechanical Sympathy built on top of Disruptor / RingBuffer.
  • 39. Reactor Projects 39 https://github.com/reactor/reactor, Apache Software License 2.0 IPC – Netty, Kafka, Aeron
  • 42. Flux Design Pattern Source: Flux in GitHub, https://github.com/facebook/flux, License: BSD 3-clause "New" License
  • 43. Linear flow: Source: @ngrx/store in GitHub, https://gist.github.com/btroncone/a6e4347326749f938510 Redux Design Pattern
  • 44. Source: RxJava 2 API documentation, http://reactivex.io/RxJava/2.x/javadoc/ Redux == Rx Scan Opearator
  • 45. Hot and Cold Event Streams 45  PULL-based (Cold Event Streams) – Cold streams (e.g. RxJava Observable / Flowable or Reactor Flow / Mono) are streams that run their sequence when and if they are subscribed to. They present the sequence from the start to each subscriber.  PUSH-based (Hot Event Streams) – Hot streams emit values independent of individual subscriptions. They have their own timeline and events occur whether someone is listening or not. An example of this is mouse events. A mouse is generating events regardless of whether there is a subscription. When subscription is made observer receives current events as they happen.
  • 46. Cold RxJava 2 Flowable Example 46 Flowable<String> cold = Flowable.just("Hello", "Reactive", "World", "from", "RxJava", "!"); cold.subscribe(i -> System.out.println("First: " + i)); Thread.sleep(500); cold.subscribe(i -> System.out.println("Second: " + i)); Results: First: Hello First: Reactive First: World First: from First: RxJava First: ! Second: Hello Second: Reactive Second: World Second: from Second: RxJava Second: !
  • 47. Cold RxJava Example 2 47 Flowable<Long> cold = Flowable.intervalRange(1,10,0,200, TimeUnit.MILLISECONDS); cold.subscribe(i -> System.out.println("First: " + i)); Thread.sleep(500); cold.subscribe(i -> System.out.println("Second: " + i)); Thread.sleep(3000); Results: First: 1 First: 2 First: 3 Second: 1 First: 4 Second: 2 First: 5 Second: 3 First: 6 Second: 4 First: 7 Second: 5 First: 8 Second: 6 First: 9 Second: 7 First: 10 Second: 8 Second: 9 Second: 10
  • 48. Hot Stream RxJava 2 Example 48 ConnectableFlowable<Long> hot = Flowable.intervalRange(1,10,0,200,TimeUnit.MILLISECONDS) .publish();; hot.connect(); // start emmiting Flowable -> Subscribers hot.subscribe(i -> System.out.println("First: " + i)); Thread.sleep(500); hot.subscribe(i -> System.out.println("Second: " + i)); Thread.sleep(3000); Results: First: 2 First: 3 First: 4 Second: 4 First: 5 Second: 5 First: 6 Second: 6 First: 7 Second: 7 First: 8 Second: 8 First: 9 Second: 9 First: 10 Second: 10
  • 49. Converting Cold to Hot Stream 49
  • 50. Cold Stream Example – Reactor 50 Flux.fromIterable(getSomeLongList()) .mergeWith(Flux.interval(100)) .doOnNext(serviceA::someObserver) .map(d -> d * 2) .take(3) .onErrorResumeWith(errorHandler::fallback) .doAfterTerminate(serviceM::incrementTerminate) .subscribe(System.out::println); https://github.com/reactor/reactor-core, Apache Software License 2.0
  • 51. Hot Stream Example - Reactor 51 public static void main(String... args) throws InterruptedException { EmitterProcessor<String> emitter = EmitterProcessor.create(); BlockingSink<String> sink = emitter.connectSink(); emitter.publishOn(Schedulers.single()) .map(String::toUpperCase) .filter(s → s.startsWith("HELLO")) .delayMillis(1000).subscribe(System.out::println); sink.submit("Hello World!"); // emit - non blocking sink.submit("Goodbye World!"); sink.submit("Hello Trayan!"); Thread.sleep(3000); }
  • 52. Example: IPTPI - RPi + Ardunio Robot 52  Raspberry Pi 2 (quad-core ARMv7 @ 900MHz) + Arduino Leonardo cloneA-Star 32U4 Micro  Optical encoders (custom), IR optical array, 3D accelerometers, gyros, and compass MinIMU-9 v2  IPTPI is programmed in Java using Pi4J, Reactor, RxJava, Akka  More information about IPTPI: http://robolearn.org/iptpi-robot/
  • 53. IPTPI Hot Event Streams Example 53 Encoder Readings ArduinoData Flux Arduino SerialData Position Flux Robot Positions Command Movement Subscriber RobotWSService (using Reactor) Angular 2 / TypeScript MovementCommands
  • 54. Futures in Java 8 - I 54  Future (implemented by FutureTask) – represents the result of an cancelable asynchronous computation. Methods are provided to check if the computation is complete, to wait for its completion, and to retrieve the result of the computation (blocking till its ready).  RunnableFuture – a Future that is Runnable. Successful execution of the run method causes Future completion, and allows access to its results.  ScheduledFuture – delayed cancelable action that returns result. Usually a scheduled future is the result of scheduling a task with a ScheduledExecutorService
  • 55. Future Use Example 55 Future<String> future = executor.submit( new Callable<String>() { public String call() { return searchService.findByTags(tags); } } ); DoSomethingOther(); try { showResult(future.get()); // use future result } catch (ExecutionException ex) { cleanup(); }
  • 56. Futures in Java 8 - II 56  CompletableFuture – a Future that may be explicitly completed (by setting its value and status), and may be used as a CompletionStage, supporting dependent functions and actions that trigger upon its completion.  CompletionStage – a stage of possibly asynchronous computation, that is triggered by completion of previous stage or stages (CompletionStages form Direct Acyclic Graph – DAG). A stage performs an action or computes value and completes upon termination of its computation, which in turn triggers next dependent stages. Computation may be Function (apply), Consumer (accept), or Runnable (run).
  • 57. CompletableFuture Example - I 57 private CompletableFuture<String> longCompletableFutureTask(int i, Executor executor) { return CompletableFuture.supplyAsync(() -> { try { Thread.sleep(1000); // long computation :) } catch (InterruptedException e) { e.printStackTrace(); } return i + "-" + "test"; }, executor); }
  • 58. CompletableFuture Example - II 58 ExecutorService executor = ForkJoinPool.commonPool(); //ExecutorService executor = Executors.newCachedThreadPool(); public void testlCompletableFutureSequence() { List<CompletableFuture<String>> futuresList = IntStream.range(0, 20).boxed() .map(i -> longCompletableFutureTask(i, executor) .exceptionally(t -> t.getMessage())) .collect(Collectors.toList()); CompletableFuture<List<String>> results = CompletableFuture.allOf( futuresList.toArray(new CompletableFuture[0])) .thenApply(v -> futuresList.stream() .map(CompletableFuture::join) .collect(Collectors.toList()) );
  • 59. CompletableFuture Example - III 59 try { System.out.println(results.get(10, TimeUnit.SECONDS)); } catch (ExecutionException | TimeoutException | InterruptedException e) { e.printStackTrace(); } executor.shutdown(); } // OR just: System.out.println(results.join()); executor.shutdown(); Which is better?
  • 60. CompletionStage 60  Computation may be Function (apply), Consumer (accept), or Runnable (run) – e.g.: completionStage.thenApply( x -> x * x ) .thenAccept(System.out::print ) .thenRun( System.out::println )  Stage computation can be triggered by completion of 1 (then), 2 (combine), or either 1 of 2 (either)  Functional composition can be applied to stages themselves instead to their results using compose  handle & whenComplete – support unconditional computation – both normal or exceptional triggering
  • 61. CompletionStages Composition 61 public void testlCompletableFutureComposition() throws InterruptedException, ExecutionException { Double priceInEuro = CompletableFuture.supplyAsync(() -> getStockPrice("GOOGL")) .thenCombine(CompletableFuture.supplyAsync(() -> getExchangeRate(USD, EUR)), this::convertPrice) .exceptionally(throwable -> { System.out.println("Error: " + throwable.getMessage()); return -1d; }).get(); System.out.println("GOOGL stock price in Euro: " + priceInEuro ); }
  • 62. New in Java 9: CompletableFuture 62  Executor defaultExecutor()  CompletableFuture<U> newIncompleteFuture()  CompletableFuture<T> copy()  CompletionStage<T> minimalCompletionStage()  CompletableFuture<T> completeAsync( Supplier<? extends T> supplier[, Executor executor])  CompletableFuture<T> orTimeout( long timeout, TimeUnit unit)  CompletableFuture<T> completeOnTimeout( T value, long timeout, TimeUnit unit)
  • 63. More Demos ... 63 CompletableFuture, Flow & RxJava2 @ GitHub: https://github.com/iproduct/reactive-demos-java-9  completable-future-demo – composition, delayed, ...  flow-demo – custom Flow implementations using CFs  rxjava2-demo – RxJava2 intro to reactive composition  completable-future-jaxrs-cdi-cxf – async observers, ...  completable-future-jaxrs-cdi-jersey  completable-future-jaxrs-cdi-jersey-client
  • 64. Ex.1: Async CDI Events with CF 64 @Inject @CpuProfiling private Event<CpuLoad> event; ... IntervalPublisher.getDefaultIntervalPublisher( 500, TimeUnit.MILLISECONDS) // Custom CF Flow Publisher .subscribe(new Subscriber<Integer>() { @Override public void onComplete() {} @Override public void onError(Throwable t) {} @Override public void onNext(Integer i) { event.fireAsync(new CpuLoad( System.currentTimeMillis(), getJavaCPULoad(), areProcessesChanged())) .thenAccept(event -> { logger.info("CPU load event fired: " + event); }); } //firing CDI async event returns CF @Override public void onSubscribe(Subscription subscription) {subscription.request(Long.MAX_VALUE);} });
  • 65. Ex.2: Reactive JAX-RS Client - CF 65 CompletionStage<List<ProcessInfo>> processesStage = processes.request().rx() .get(new GenericType<List<ProcessInfo>>() {}) .exceptionally(throwable -> { logger.error("Error: " + throwable.getMessage()); return Collections.emptyList(); }); CompletionStage<Void> printProcessesStage = processesStage.thenApply(proc -> { System.out.println("Active JAVA Processes: " + proc); return null; });
  • 66. Ex.2: Reactive JAX-RS Client - CF 66 (- continues -) printProcessesStage.thenRun( () -> { try (SseEventSource source = SseEventSource.target(stats).build()) { source.register(System.out::println); source.open(); Thread.sleep(20000); // Consume events for 20 sec } catch (InterruptedException e) { logger.info("SSE consumer interrupted: " + e); } }) .thenRun(() -> {System.exit(0);});
  • 67. Thank’s for Your Attention! 67 Trayan Iliev CEO of IPT – Intellectual Products & Technologies http://iproduct.org/ http://robolearn.org/ https://github.com/iproduct https://twitter.com/trayaniliev https://www.facebook.com/IPT.EACAD https://plus.google.com/+IproductOrg