SlideShare a Scribd company logo
1 of 32
Download to read offline
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Tim Ward

tim.ward@paremus.com
Reactive OSGi meets Reactive Java
Don’t cross the streams?
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Who is Tim Ward?
Chief Technology Officer at Paremus
9 years developing OSGi specifications
Co-chair of the OSGi IoT Expert Group
Interested in Asynchronous Distributed Systems
Author of Manning’s Enterprise OSGi in Action
http://www.manning.com/cummins
@TimothyWard
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
A quick introduction
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
What is Reactive Programming?
A set of principles for handling high volumes of “live” data
Live data may be historic, but not stored for batch processing
Changes should be “reactive” and reflected immediately
Operations are stream-centric
Resource utilisation must be controlled
Asynchronous exchange of data to decouple processing
Non-blocking back-pressure to limit the rate of event production
Concepts described at https://www.reactivemanifesto.org
Standardisation at http://www.reactive-streams.org
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Reactive Java specifications
The Reactive Streams initiative
Defines the org.reactivestreams API, a specification and a TCK
Does not define an implementation
OSGi PushStreams
Defines the org.osgi.util.pushstream API
The API is self-implementing
The Java 9 Flow API
A simple re-namespacing of the Reactive Streams API
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
The reactive primitives
Reactive
Streams / Java 9 PushStreams
Event / Data
Source
Publisher<T> PushEventSource<T>
Event / Data
Sink
Subscriber<T> PushEventConsumer<T>
“Connection” Subscription AutoCloseable
“Pipeline” Processor<T,R> PushStream<T>
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Being Reactive
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Reactive examples
In the following examples:
The data stream is a monotonic infinite sequence from 0
Data events occur every 50 ms
The consumer wants to print out the first N events
The consumer wants to print out when they are finished
This is a fairly simple, but practical example case
Short circuiting is necessary for infinite streams!
Let’s compare OSGi Push Streams and Reactive Streams
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Push Streams
Demo code…
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Push Streams (2)
Highlights:
The SimplePushEventSource is powerful
It can multiplex multiple consumers from a single event stream
It is internally buffered to protect against slow consumers
It uses callbacks to allow lazy event generation
The PushStream offers a familiar processing pipeline model
There is no dependency on the rest of the OSGi API
Easy to deploy in “standard Java”
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Reactive Streams
Demo code…
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Reactive Streams (2)
The code looks pretty horrible, right?
This wasn’t really a fair fight…
Reactive Streams is a pure API
Any non-trivial application must use an implementation
The same is true of Java 9’s Flow API!
A fairer comparison would be to use a library
RxJava was originally from Netflix, and is widely used
Note that the example also ran faster…
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Rx Java
Demo code…
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Rx Java (2)
This example is super-concise
It isn’t really a fair comparison either!
The other examples use async “push” publication
Most RxJava methods make data “on demand”
This is one reason why the raw API version ran faster too!
We need to move publication onto a different thread…
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Rx Java (3)
Demo code…
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Rx Java (4)
The code is now very similar to the Push Stream example
This is unsurprising, as the primitives are pretty similar
So what actually is the difference?
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
The differences
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Creating the connection
Connecting a source and consumer is subtly different:
AutoCloseable open(PushEventConsumer<T> pec)
void subscribe(Subscriber<T> s)
A Reactive Stream cannot be closed by the creator!
The subscription can do this but it is hidden
RxJava’s Disposable isn’t the same
Reactive Streams are not (in general) Lambda friendly
The Subscriber has four methods, and must be stateful
Specific libraries try to work around this
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
The way events are propagated
A Subscriber must request data before it can be sent
The data cannot be delivered concurrently
This is Thread Safe, and reduces CPU exhaustion
Push Streams can push data whenever they like
In general event delivery is concurrent (see sequential())
Pipeline functions should be stateless and/or Thread Safe
Back pressure need not be honoured by the source
In many cases these differences have no effect
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Publishers - Hot, Cold, Push and Pull
Sources of events can have different characteristics
Cold sources can be restarted from the beginning (e.g. a List)
Hot sources provide live data and cannot restart (e.g. a sensor)
Pull sources provide data “on request”
Push sources provide data as a result of something
Cold sources are almost always Pull
Reactive Streams work well for Pull sources
Data can only be sent after it is requested
Push Streams API work well for Push sources
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Coping with slow consumers
Event processing is easy when the consumer is fast
If a Push source is faster than the consumer we have a problem!
Reactive Streams must always use buffers for Push sources
This is because Subscribers must be called on request
Pushstreams use the incoming thread to receive data
Pushed data on multiple threads is processed in parallel
Long running/blocking operations should use their own thread(s)
Buffering is still valuable as it releases the publisher thread
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Coping with slow consumers (2)
Buffering is only part of the solution!
Buffers cannot be infinite (OutOfMemoryError)
Buffers solve “bursts” not a long term mismatch in speed
Reactive Streams require you to “fan out”
Spread the processing over multiple streams
Often this uses a new process (see Akka)
Pushstreams can simply use more threads!
Buffers allow the number of workers to scale up or down
Use the buffer to solve both bursts and speed up
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Coping with slow consumers (3)
We can only get so far by speeding up the consumer
We need to use back pressure to slow down the data source
Reactive Streams back pressure is controlled by request
This helps with Pull sources, but how does it help with Push?
How long should we hold/drop data for?
Pushstreams return a “delay” that should be observed
Dropping messages for the period may make sense
A periodic producer may be able to slow down
A Push source with important messages is always a challenge
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Slow consumer examples
In the following examples:
The data stream is a monotonic infinite sequence from 0
The data stream produces events every 50 ms
The consumer wants to print out the first 500 events
The consumer takes 80 ms per event
The examples may process the stream on N threads
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Slow consumer examples (2)
Demo code…
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Library comparisons
Both libraries are easy to deploy (small dependency graph)
The default PushStream implementation is small (110kb)
Rx Java 2.1.4 is 2100kb (> 10% the size of a custom Java 9 JVM!)
The API decisions match the original use cases
Handling Hot, Push data events from IoT sensors/message queues
Rescaling video streams based on user backpressure
This is why Push Streams work naturally with multiple threads
The Reactive Streams API is useless, except as an SPI
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Making use of Reactive Streams
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Library interoperability
The Reactive Streams API is good for library interoperation
A standard PushStream can be treated as a Publisher
A standard Publisher can be treated as a PushEventSource
This means that any Stream can be linked to any other!
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Interoperation examples
Demo code…
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
Questions?
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017
For more about OSGi...
Specifications at http://www.osgi.org
Enterprise OSGi in Action
For more about the Push Streams
https://www.osgi.org/developer/specifications/
http://oss.sonatype.org/content/groups/osgi/
For more about Reactive Streams/Rx Java
https://github.com/ReactiveX/RxJava
http://www.reactive-streams.org
Thanks!
http://www.paremus.com
info@paremus.com
http://www.manning.com/
cummins
We look forward to seeing you tomorrow morning
Copyright © 2017 Paremus Ltd.

May not be reproduced by any means without express permission. All rights reserved.
Reactive OSGi meets Reactive Java October 2017

More Related Content

What's hot

Asynchronous OSGi – Promises for the Masses - T Ward
Asynchronous OSGi – Promises for the Masses - T WardAsynchronous OSGi – Promises for the Masses - T Ward
Asynchronous OSGi – Promises for the Masses - T Ward
mfrancis
 

What's hot (18)

Asynchronous OSGi – Promises for the Masses - T Ward
Asynchronous OSGi – Promises for the Masses - T WardAsynchronous OSGi – Promises for the Masses - T Ward
Asynchronous OSGi – Promises for the Masses - T Ward
 
London Oracle Developer Meetup April 18
London Oracle Developer Meetup April 18London Oracle Developer Meetup April 18
London Oracle Developer Meetup April 18
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
 
Scaling micro services at gilt
Scaling micro services at giltScaling micro services at gilt
Scaling micro services at gilt
 
Introduction to React Native - Nader Dabit
Introduction to React Native - Nader DabitIntroduction to React Native - Nader Dabit
Introduction to React Native - Nader Dabit
 
AWS Cloud9 – Cloud IDE for Writing, Running and Debugging Code
AWS Cloud9 – Cloud IDE for Writing, Running and Debugging CodeAWS Cloud9 – Cloud IDE for Writing, Running and Debugging Code
AWS Cloud9 – Cloud IDE for Writing, Running and Debugging Code
 
Dsug 05 02-15 - ScalDI - lightweight DI in Scala
Dsug 05 02-15 - ScalDI - lightweight DI in ScalaDsug 05 02-15 - ScalDI - lightweight DI in Scala
Dsug 05 02-15 - ScalDI - lightweight DI in Scala
 
Community day _aws_ci_cd_v0.2
Community day _aws_ci_cd_v0.2Community day _aws_ci_cd_v0.2
Community day _aws_ci_cd_v0.2
 
Building Microservices with the Twelve Factor App Pattern on AWS
Building Microservices with the Twelve Factor App Pattern on AWSBuilding Microservices with the Twelve Factor App Pattern on AWS
Building Microservices with the Twelve Factor App Pattern on AWS
 
Building Mobile Apps with AWS Amplify
Building Mobile Apps with AWS AmplifyBuilding Mobile Apps with AWS Amplify
Building Mobile Apps with AWS Amplify
 
Security & Compliance in the Cloud
Security & Compliance in the CloudSecurity & Compliance in the Cloud
Security & Compliance in the Cloud
 
Scaling up to and beyond 10M users
Scaling up to and beyond 10M usersScaling up to and beyond 10M users
Scaling up to and beyond 10M users
 
Introduction to Kitura - Swift Hong Kong Meetup 2016 July
Introduction to Kitura - Swift Hong Kong Meetup 2016 JulyIntroduction to Kitura - Swift Hong Kong Meetup 2016 July
Introduction to Kitura - Swift Hong Kong Meetup 2016 July
 
Polyglot on the JVM with Graal (Japanese)
Polyglot on the JVM with Graal (Japanese)Polyglot on the JVM with Graal (Japanese)
Polyglot on the JVM with Graal (Japanese)
 
Just-in-time Java EE - provisioning runtimes for enterprise applications - Ja...
Just-in-time Java EE - provisioning runtimes for enterprise applications - Ja...Just-in-time Java EE - provisioning runtimes for enterprise applications - Ja...
Just-in-time Java EE - provisioning runtimes for enterprise applications - Ja...
 
OSGi DevCon 2009 Review
OSGi DevCon 2009 ReviewOSGi DevCon 2009 Review
OSGi DevCon 2009 Review
 
Building Mobile Apps with AWS Amplify - Nader Dabit
Building Mobile Apps with AWS Amplify - Nader DabitBuilding Mobile Apps with AWS Amplify - Nader Dabit
Building Mobile Apps with AWS Amplify - Nader Dabit
 
Run Kubernetes with Amazon EKS
Run Kubernetes with Amazon EKSRun Kubernetes with Amazon EKS
Run Kubernetes with Amazon EKS
 

Similar to Reactive OSGi meets Reactive Java - Don’t cross the streams - T Ward

How to Build Scalable Serverless Applications
How to Build Scalable Serverless ApplicationsHow to Build Scalable Serverless Applications
How to Build Scalable Serverless Applications
Amazon Web Services
 
Transaction Control – a Functional Approach to Modular Transaction Management...
Transaction Control – a Functional Approach to Modular Transaction Management...Transaction Control – a Functional Approach to Modular Transaction Management...
Transaction Control – a Functional Approach to Modular Transaction Management...
mfrancis
 

Similar to Reactive OSGi meets Reactive Java - Don’t cross the streams - T Ward (20)

Under the Hood of Reactive Data Access (1/2)
Under the Hood of Reactive Data Access (1/2)Under the Hood of Reactive Data Access (1/2)
Under the Hood of Reactive Data Access (1/2)
 
Oracle SOA Tips & Tricks
Oracle SOA Tips & TricksOracle SOA Tips & Tricks
Oracle SOA Tips & Tricks
 
SRV314_Building a Serverless Pipeline to Transcode a Two-Hour Video in Minutes
SRV314_Building a Serverless Pipeline to Transcode a Two-Hour Video in MinutesSRV314_Building a Serverless Pipeline to Transcode a Two-Hour Video in Minutes
SRV314_Building a Serverless Pipeline to Transcode a Two-Hour Video in Minutes
 
What's New in Serverless - SRV305 - re:Invent 2017
What's New in Serverless - SRV305 - re:Invent 2017What's New in Serverless - SRV305 - re:Invent 2017
What's New in Serverless - SRV305 - re:Invent 2017
 
Dean4j@Njug5
Dean4j@Njug5Dean4j@Njug5
Dean4j@Njug5
 
Spring Framework 5.0による Reactive Web Application #JavaDayTokyo
Spring Framework 5.0による Reactive Web Application #JavaDayTokyoSpring Framework 5.0による Reactive Web Application #JavaDayTokyo
Spring Framework 5.0による Reactive Web Application #JavaDayTokyo
 
10 Lessons from 10 Years of AWS
10 Lessons from 10 Years of AWS10 Lessons from 10 Years of AWS
10 Lessons from 10 Years of AWS
 
Technological Accelerants for Organizational Transformation - DVC303 - re:Inv...
Technological Accelerants for Organizational Transformation - DVC303 - re:Inv...Technological Accelerants for Organizational Transformation - DVC303 - re:Inv...
Technological Accelerants for Organizational Transformation - DVC303 - re:Inv...
 
DVC303-Technological Accelerants for Organizational Transformation
DVC303-Technological Accelerants for Organizational TransformationDVC303-Technological Accelerants for Organizational Transformation
DVC303-Technological Accelerants for Organizational Transformation
 
What's New in Serverless
What's New in ServerlessWhat's New in Serverless
What's New in Serverless
 
Hands-On Lab: Building a Serverless Real-Time Chat Application with AWS AppSync
Hands-On Lab: Building a Serverless Real-Time Chat Application with AWS AppSyncHands-On Lab: Building a Serverless Real-Time Chat Application with AWS AppSync
Hands-On Lab: Building a Serverless Real-Time Chat Application with AWS AppSync
 
Application Performance Management on AWS
Application Performance Management on AWSApplication Performance Management on AWS
Application Performance Management on AWS
 
Don't Wait! Develop responsive applications with Java EE7 instead
Don't Wait! Develop responsive applications with Java EE7 insteadDon't Wait! Develop responsive applications with Java EE7 instead
Don't Wait! Develop responsive applications with Java EE7 instead
 
FRP with Ractive and RxJS
FRP with Ractive and RxJSFRP with Ractive and RxJS
FRP with Ractive and RxJS
 
Application Performance Management on AWS - ARC317 - re:Invent 2017
Application Performance Management on AWS - ARC317 - re:Invent 2017Application Performance Management on AWS - ARC317 - re:Invent 2017
Application Performance Management on AWS - ARC317 - re:Invent 2017
 
How to Build Scalable Serverless Applications
How to Build Scalable Serverless ApplicationsHow to Build Scalable Serverless Applications
How to Build Scalable Serverless Applications
 
How serverless helps startups innovate and scale
How serverless helps startups innovate and scaleHow serverless helps startups innovate and scale
How serverless helps startups innovate and scale
 
How Nextdoor Built a Scalable, Serverless Data Pipeline for Billions of Event...
How Nextdoor Built a Scalable, Serverless Data Pipeline for Billions of Event...How Nextdoor Built a Scalable, Serverless Data Pipeline for Billions of Event...
How Nextdoor Built a Scalable, Serverless Data Pipeline for Billions of Event...
 
Transaction Control – a Functional Approach to Modular Transaction Management...
Transaction Control – a Functional Approach to Modular Transaction Management...Transaction Control – a Functional Approach to Modular Transaction Management...
Transaction Control – a Functional Approach to Modular Transaction Management...
 
Keys to Successfully Monitoring and Optimizing Innovative and Sophisticated C...
Keys to Successfully Monitoring and Optimizing Innovative and Sophisticated C...Keys to Successfully Monitoring and Optimizing Innovative and Sophisticated C...
Keys to Successfully Monitoring and Optimizing Innovative and Sophisticated C...
 

More from mfrancis

Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
mfrancis
 
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
mfrancis
 
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
mfrancis
 
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
mfrancis
 

More from mfrancis (20)

Eclipse Modeling Framework and plain OSGi the easy way - Mark Hoffman (Data I...
Eclipse Modeling Framework and plain OSGi the easy way - Mark Hoffman (Data I...Eclipse Modeling Framework and plain OSGi the easy way - Mark Hoffman (Data I...
Eclipse Modeling Framework and plain OSGi the easy way - Mark Hoffman (Data I...
 
OSGi and Java 9+ - BJ Hargrave (IBM)
OSGi and Java 9+ - BJ Hargrave (IBM)OSGi and Java 9+ - BJ Hargrave (IBM)
OSGi and Java 9+ - BJ Hargrave (IBM)
 
Simplify Web UX Coding using OSGi Modularity Magic - Paul Fraser (A2Z Living)
Simplify Web UX Coding using OSGi Modularity Magic - Paul Fraser (A2Z Living)Simplify Web UX Coding using OSGi Modularity Magic - Paul Fraser (A2Z Living)
Simplify Web UX Coding using OSGi Modularity Magic - Paul Fraser (A2Z Living)
 
OSGi for the data centre - Connecting OSGi to Kubernetes - Frank Lyaruu
OSGi for the data centre - Connecting OSGi to Kubernetes - Frank LyaruuOSGi for the data centre - Connecting OSGi to Kubernetes - Frank Lyaruu
OSGi for the data centre - Connecting OSGi to Kubernetes - Frank Lyaruu
 
Remote Management and Monitoring of Distributed OSGi Applications - Tim Verbe...
Remote Management and Monitoring of Distributed OSGi Applications - Tim Verbe...Remote Management and Monitoring of Distributed OSGi Applications - Tim Verbe...
Remote Management and Monitoring of Distributed OSGi Applications - Tim Verbe...
 
OSGi with Docker - a powerful way to develop Java systems - Udo Hafermann (So...
OSGi with Docker - a powerful way to develop Java systems - Udo Hafermann (So...OSGi with Docker - a powerful way to develop Java systems - Udo Hafermann (So...
OSGi with Docker - a powerful way to develop Java systems - Udo Hafermann (So...
 
A real world use case with OSGi R7 - Jurgen Albert (Data In Motion Consulting...
A real world use case with OSGi R7 - Jurgen Albert (Data In Motion Consulting...A real world use case with OSGi R7 - Jurgen Albert (Data In Motion Consulting...
A real world use case with OSGi R7 - Jurgen Albert (Data In Motion Consulting...
 
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
 
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
 
OSGi CDI Integration Specification - Ray Augé (Liferay)
OSGi CDI Integration Specification - Ray Augé (Liferay)OSGi CDI Integration Specification - Ray Augé (Liferay)
OSGi CDI Integration Specification - Ray Augé (Liferay)
 
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
 
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
 
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...
 
Popular patterns revisited on OSGi - Christian Schneider (Adobe)
Popular patterns revisited on OSGi - Christian Schneider (Adobe)Popular patterns revisited on OSGi - Christian Schneider (Adobe)
Popular patterns revisited on OSGi - Christian Schneider (Adobe)
 
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
 
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)
 
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...
 
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
 
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
 
How to connect your OSGi application - Dirk Fauth (Bosch)
How to connect your OSGi application - Dirk Fauth (Bosch)How to connect your OSGi application - Dirk Fauth (Bosch)
How to connect your OSGi application - Dirk Fauth (Bosch)
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

Reactive OSGi meets Reactive Java - Don’t cross the streams - T Ward

  • 1. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Tim Ward
 tim.ward@paremus.com Reactive OSGi meets Reactive Java Don’t cross the streams?
  • 2. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Who is Tim Ward? Chief Technology Officer at Paremus 9 years developing OSGi specifications Co-chair of the OSGi IoT Expert Group Interested in Asynchronous Distributed Systems Author of Manning’s Enterprise OSGi in Action http://www.manning.com/cummins @TimothyWard
  • 3. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 A quick introduction
  • 4. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 What is Reactive Programming? A set of principles for handling high volumes of “live” data Live data may be historic, but not stored for batch processing Changes should be “reactive” and reflected immediately Operations are stream-centric Resource utilisation must be controlled Asynchronous exchange of data to decouple processing Non-blocking back-pressure to limit the rate of event production Concepts described at https://www.reactivemanifesto.org Standardisation at http://www.reactive-streams.org
  • 5. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Reactive Java specifications The Reactive Streams initiative Defines the org.reactivestreams API, a specification and a TCK Does not define an implementation OSGi PushStreams Defines the org.osgi.util.pushstream API The API is self-implementing The Java 9 Flow API A simple re-namespacing of the Reactive Streams API
  • 6. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 The reactive primitives Reactive Streams / Java 9 PushStreams Event / Data Source Publisher<T> PushEventSource<T> Event / Data Sink Subscriber<T> PushEventConsumer<T> “Connection” Subscription AutoCloseable “Pipeline” Processor<T,R> PushStream<T>
  • 7. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Being Reactive
  • 8. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Reactive examples In the following examples: The data stream is a monotonic infinite sequence from 0 Data events occur every 50 ms The consumer wants to print out the first N events The consumer wants to print out when they are finished This is a fairly simple, but practical example case Short circuiting is necessary for infinite streams! Let’s compare OSGi Push Streams and Reactive Streams
  • 9. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Push Streams Demo code…
  • 10. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Push Streams (2) Highlights: The SimplePushEventSource is powerful It can multiplex multiple consumers from a single event stream It is internally buffered to protect against slow consumers It uses callbacks to allow lazy event generation The PushStream offers a familiar processing pipeline model There is no dependency on the rest of the OSGi API Easy to deploy in “standard Java”
  • 11. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Reactive Streams Demo code…
  • 12. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Reactive Streams (2) The code looks pretty horrible, right? This wasn’t really a fair fight… Reactive Streams is a pure API Any non-trivial application must use an implementation The same is true of Java 9’s Flow API! A fairer comparison would be to use a library RxJava was originally from Netflix, and is widely used Note that the example also ran faster…
  • 13. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Rx Java Demo code…
  • 14. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Rx Java (2) This example is super-concise It isn’t really a fair comparison either! The other examples use async “push” publication Most RxJava methods make data “on demand” This is one reason why the raw API version ran faster too! We need to move publication onto a different thread…
  • 15. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Rx Java (3) Demo code…
  • 16. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Rx Java (4) The code is now very similar to the Push Stream example This is unsurprising, as the primitives are pretty similar So what actually is the difference?
  • 17. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 The differences
  • 18. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Creating the connection Connecting a source and consumer is subtly different: AutoCloseable open(PushEventConsumer<T> pec) void subscribe(Subscriber<T> s) A Reactive Stream cannot be closed by the creator! The subscription can do this but it is hidden RxJava’s Disposable isn’t the same Reactive Streams are not (in general) Lambda friendly The Subscriber has four methods, and must be stateful Specific libraries try to work around this
  • 19. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 The way events are propagated A Subscriber must request data before it can be sent The data cannot be delivered concurrently This is Thread Safe, and reduces CPU exhaustion Push Streams can push data whenever they like In general event delivery is concurrent (see sequential()) Pipeline functions should be stateless and/or Thread Safe Back pressure need not be honoured by the source In many cases these differences have no effect
  • 20. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Publishers - Hot, Cold, Push and Pull Sources of events can have different characteristics Cold sources can be restarted from the beginning (e.g. a List) Hot sources provide live data and cannot restart (e.g. a sensor) Pull sources provide data “on request” Push sources provide data as a result of something Cold sources are almost always Pull Reactive Streams work well for Pull sources Data can only be sent after it is requested Push Streams API work well for Push sources
  • 21. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Coping with slow consumers Event processing is easy when the consumer is fast If a Push source is faster than the consumer we have a problem! Reactive Streams must always use buffers for Push sources This is because Subscribers must be called on request Pushstreams use the incoming thread to receive data Pushed data on multiple threads is processed in parallel Long running/blocking operations should use their own thread(s) Buffering is still valuable as it releases the publisher thread
  • 22. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Coping with slow consumers (2) Buffering is only part of the solution! Buffers cannot be infinite (OutOfMemoryError) Buffers solve “bursts” not a long term mismatch in speed Reactive Streams require you to “fan out” Spread the processing over multiple streams Often this uses a new process (see Akka) Pushstreams can simply use more threads! Buffers allow the number of workers to scale up or down Use the buffer to solve both bursts and speed up
  • 23. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Coping with slow consumers (3) We can only get so far by speeding up the consumer We need to use back pressure to slow down the data source Reactive Streams back pressure is controlled by request This helps with Pull sources, but how does it help with Push? How long should we hold/drop data for? Pushstreams return a “delay” that should be observed Dropping messages for the period may make sense A periodic producer may be able to slow down A Push source with important messages is always a challenge
  • 24. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Slow consumer examples In the following examples: The data stream is a monotonic infinite sequence from 0 The data stream produces events every 50 ms The consumer wants to print out the first 500 events The consumer takes 80 ms per event The examples may process the stream on N threads
  • 25. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Slow consumer examples (2) Demo code…
  • 26. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Library comparisons Both libraries are easy to deploy (small dependency graph) The default PushStream implementation is small (110kb) Rx Java 2.1.4 is 2100kb (> 10% the size of a custom Java 9 JVM!) The API decisions match the original use cases Handling Hot, Push data events from IoT sensors/message queues Rescaling video streams based on user backpressure This is why Push Streams work naturally with multiple threads The Reactive Streams API is useless, except as an SPI
  • 27. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Making use of Reactive Streams
  • 28. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Library interoperability The Reactive Streams API is good for library interoperation A standard PushStream can be treated as a Publisher A standard Publisher can be treated as a PushEventSource This means that any Stream can be linked to any other!
  • 29. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Interoperation examples Demo code…
  • 30. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 Questions?
  • 31. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017 For more about OSGi... Specifications at http://www.osgi.org Enterprise OSGi in Action For more about the Push Streams https://www.osgi.org/developer/specifications/ http://oss.sonatype.org/content/groups/osgi/ For more about Reactive Streams/Rx Java https://github.com/ReactiveX/RxJava http://www.reactive-streams.org Thanks! http://www.paremus.com info@paremus.com http://www.manning.com/ cummins We look forward to seeing you tomorrow morning
  • 32. Copyright © 2017 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Reactive OSGi meets Reactive Java October 2017