SlideShare a Scribd company logo
ReactiveJava =
Reactive Programming
using RxJava
Hello!
I AM Hiten Pratap Singh
I am here because I love to dig in to experience new things.
You can find me at:
◦ hiten@nexthoughts.com
◦ http://github.com/hitenpratap/
◦ http://hprog99.wordpress.com/
I have divided this presentation into two parts
Reactive
Programming
RxJava
Reactive Programming
What’s Reactive Programming? What’s the big deal about it?
Reactive java - Reactive Programming + RxJava
“
In computing, reactive programming is a
programming paradigm oriented around data
flows and the propagation of change.
Reactive Programming
Reactive programming is programming
with asynchronous data streams.
◦ Event buses or your typical click events are really
an asynchronous event stream
◦ Streams are cheap and ubiquitous, anything can be
a stream: variables, user inputs, properties etc.
◦ For example, imagine your Twitter feed would be
a data stream in the same fashion that click events
are.
Reactive Programming
On top of that, you are given an amazing
toolbox of functions to combine, create and
filter any of those streams.
◦ A stream can be used as an input to another one.
◦ You can merge two streams.
◦ You can filter a stream to get another one that has
only those events you are interested in.
◦ You can map data values from one stream to
another new one.
A stream is a sequence of ongoing events ordered in time. It can emit three
different things: a value (of some type), an error, or a "completed" signal.
Consider that the "completed" takes place, for instance, when the current window
or view containing that button is closed.
We capture these emitted events only asynchronously, by defining a function that
will execute when a value is emitted, another function when an error is emitted,
and another function when 'completed' is emitted.
The "listening" to the stream is called subscribing. The functions we are defining
are observers. The stream is the subject (or "observable") being observed. This is
precisely the Observer Design Pattern.
Reactive Programming
Why should I consider adopting RP?
◦ RP raises the level of abstraction of your code.
◦ Code in RP will likely be more concise.
◦ Apps nowadays have an abundancy of real-time
events of every kind that enable a highly
interactive experience to the user.
◦ We need tools for properly dealing with that, and
Reactive Programming is an answer.
Reactive Programming
Key Takeaways
◦ RP is a specification for dealing with
asynchronous streams of data.
◦ Reactive provides tools for transforming and
combining streams and for managing flow-control
◦ Resembles Java Streams API but the resemblance
is purely superficial
Thinking in RP with
Example
What’s ReactiveX?
◦ A library for composing async and event based
program by using observable sequences.
◦ Created by Microsoft initially for .Net platform by
Erik Meijer
◦ Extends observer pattern-
* Supports sequence of data and/or events
* Add operators that allow you to compose sequences
together declaratively
▫ Abstracts away concerns around
* Threading and Thread Safety
* Concurrent data structures and non blocking I/O
▫ RxJava is a port of Reactive Extensions created by
Netflix.
What’s ReactiveX?
RxJava
A libraryto use mightypowers of Reactive Programmingin Java!
Maven
Getting Started
Gradle
You can also include its jar file without having to use
any of build system as well.
Reactive Components/Building Blocks
ObserverObservable Subject
Observable
Observable
In ReactiveX an observer subscribes to an Observable. Then that
observer reacts to whatever item or sequence of items the
Observable emits.This patternfacilitatesconcurrent operations
because it does not need to block while waiting for the
Observable to emit objects,but insteadit creates a sentryin the
form of an observer that stands ready to react appropriatelyat
whatever future time the Observable does so.
◦ Emits zero or more values
◦ Life Cycles
* Notifies Observer using onNext(T)
* Completes with either onError() or onCompleted()
Reactive java - Reactive Programming + RxJava
Operators
Operators By Categories
Creating
Observables
Transforming
Observables
Filtering
Observables
Combining
Observables
Error
handling
Operators
Observable
Utility
Operators
Operators By Categories(Contd.)
Conditional
and Boolean
Operators
Mathematical
and
Aggregate
Operators
Backpressure
Operators
ReactiveX provides great flexibility over operators by
letting us chaining them together or even creating new
ones.
Transforming Observable
Transforming Observable << Map
Transforming Observable << Flatmap
Filtering Observable
Filtering Observable << Take
Filtering Observable << Filter
Filtering Observable << Distinct
Filtering Observable << First
Combining Observable
Combining Observable << Merge
Combining Observable << Zip
Schedulers
If you want to introduce multithreadingintoyour cascade of
Observable operators, you can do so by instructingthose operators
(or particular Observables) to operate on particular Schedulers.
Observable Utility Operators
Observable Utility Operators << SubscribeOn
Observable Utility Operators << ObserveOn
Single
Single
◦ RxJava (and its derivatives like RxGroovy & RxScala) has developed
an Observable variant called “Single.”
◦ A Single is something like an Observable, but instead of emitting a
series of values — anywhere from none at all to an infinite number
— it always either emits one value or an error notification.
◦ For this reason, instead of subscribing to a Single with the three
methods you use to respond to notifications from an Observable
(onNext, onError, and onCompleted), you only use two methods to
subscribe:
Subjects
Subject
A Subject is a sort of bridge or proxy that is available in some
implementations of ReactiveX that acts both as an observer and as an
Observable. Because it is an observer, it can subscribe to one or more
Observables, and because it is an Observable, it can pass through the
items it observes by reemitting them, and it can also emit new items.
Because a Subject subscribes to an Observable, it will trigger that
Observable to begin emitting items (if that Observable is “cold” — that
is, if it waits for a subscription before it begins to emit items). This can
have the effect of making the resulting Subject a “hot” Observable
variant of the original “cold” Observable.
Varieties of Subject
◦ AsyncSubject
◦ BehaviorSubject
◦ PublishSubject
◦ ReplaySubject
Subject << AsyncSubject
Subject << BehaviorSubject
Subject << PublishSubject
Subject << ReplaySubject
Backpressure
Backpressure
In RxJava it is not difficult to get into a situation in which an Observable
is emitting items more rapidly than an operator or subscriber can
consume them. This presents the problem of what to do with such a
growing backlog of unconsumed items.
For example, imagine using the zip operator to zip together two infinite
Observables, one of which emits items twice as frequently as the other.
A naive implementation of the zip operator would have to maintain an
ever-expanding buffer of items emitted by the faster Observable to
eventually combine with items emitted by the slower one. This could
cause RxJava to seize an unwieldy amount of system resources.
Hot and Cold
Observable
Hot Observable
A hot Observable begins generating items to emit immediately when it
is created. Subscribers typically begin observing the sequence of items
emitted by a hot Observable from somewhere in the middle of the
sequence, beginning with the first item emitted by the Observable
subsequent to the establishment of the subscription.
Such an Observable emits items at its own pace, and it is up to its
observers to keep up.
Examples of items emitted by a hot Observable might include mouse &
keyboard events, system events, or stock prices.
Cold Observable
A cold Observable emits a particular sequence of items, but can begin
emitting this sequence when its Observer finds it to be convenient, and
at whatever rate the Observer desires, without disrupting the integrity of
the sequence.
For example if you convert a static Iterable into an Observable, that
Observable will emit the same sequence of items no matter when it is
later subscribed to or how frequently those items are observed.
Examples of items emitted by a cold Observable might include the
results of a database query, file retrieval, or web request.
Conclusion
Pros
◦ Makes Async code easy to develop
◦ Lots of resources to get started with
◦ Strong use of functional type programming
◦ Netflix used RxNetty and Reactive Programmingto
considerable performance advantage over Tomcat
◦ Web Service clients like Jerseyand Retrofit support RxJava.
Cons
◦ Learning curve and mind set change to use functional reactive
programming
◦ Appears like more code and more complex code initially–
Requires time for it to grow on you.
◦ If on Java 7 anonymous class would make this a non-starter.
Thanks!
ANY QUESTIONS?
You can find me at:
hiten@nexthoughts.com
http://github.com/hitenpratap/
http://hprog99.wordpress.com/

More Related Content

What's hot (20)

PDF
Spring Boot Microservices vs Akka Actor Cluster
OpenCredo
 
PDF
Demystifying Reactive Programming
Tom Bulatewicz, PhD
 
PPTX
Grails with swagger
NexThoughts Technologies
 
PDF
Reactive: Programming -> Systems -> Architecture
Aleksey Izmailov
 
PPTX
Reactive programming
SUDIP GHOSH
 
PDF
Understanding Reactive Programming
Andres Almiray
 
PPTX
Reactive Programming In Java Using: Project Reactor
Knoldus Inc.
 
PDF
Declarative Concurrency with Reactive Programming
Florian Stefan
 
PPTX
What’s expected in Spring 5
Gal Marder
 
PPTX
Functional reactive programming
Hung Hoang
 
PPTX
Reactive Micro Services with Java seminar
Gal Marder
 
PDF
Load test REST APIs using gatling
Jayaram Sankaranarayanan
 
PDF
Durable Functions vs Logic App : la guerra dei workflow!!
Massimo Bonanni
 
PPTX
Coordinating Micro-Services with Spring Cloud Contract
Omri Spector
 
PDF
Introduction to Akka
Knoldus Inc.
 
PDF
Introduction to akka actors with java 8
Johan Andrén
 
PPTX
Discovering the Service Fabric's actor model
Massimo Bonanni
 
PPTX
React gsg presentation with ryan jung &amp; elias malik
Lama K Banna
 
ODP
Gatling - Stress test tool
Knoldus Inc.
 
PDF
Introduction to Functional Reactive Programming
Đặng Thái Sơn
 
Spring Boot Microservices vs Akka Actor Cluster
OpenCredo
 
Demystifying Reactive Programming
Tom Bulatewicz, PhD
 
Grails with swagger
NexThoughts Technologies
 
Reactive: Programming -> Systems -> Architecture
Aleksey Izmailov
 
Reactive programming
SUDIP GHOSH
 
Understanding Reactive Programming
Andres Almiray
 
Reactive Programming In Java Using: Project Reactor
Knoldus Inc.
 
Declarative Concurrency with Reactive Programming
Florian Stefan
 
What’s expected in Spring 5
Gal Marder
 
Functional reactive programming
Hung Hoang
 
Reactive Micro Services with Java seminar
Gal Marder
 
Load test REST APIs using gatling
Jayaram Sankaranarayanan
 
Durable Functions vs Logic App : la guerra dei workflow!!
Massimo Bonanni
 
Coordinating Micro-Services with Spring Cloud Contract
Omri Spector
 
Introduction to Akka
Knoldus Inc.
 
Introduction to akka actors with java 8
Johan Andrén
 
Discovering the Service Fabric's actor model
Massimo Bonanni
 
React gsg presentation with ryan jung &amp; elias malik
Lama K Banna
 
Gatling - Stress test tool
Knoldus Inc.
 
Introduction to Functional Reactive Programming
Đặng Thái Sơn
 

Viewers also liked (16)

PDF
Introduction to gradle
NexThoughts Technologies
 
PPTX
Introduction to es6
NexThoughts Technologies
 
PPTX
Apache tika
NexThoughts Technologies
 
PDF
Introduction to thymeleaf
NexThoughts Technologies
 
PPTX
Progressive Web-App (PWA)
NexThoughts Technologies
 
PPTX
JFree chart
NexThoughts Technologies
 
PDF
Spring Web Flow
NexThoughts Technologies
 
PDF
Unit test-using-spock in Grails
NexThoughts Technologies
 
PDF
Cosmos DB Service
NexThoughts Technologies
 
PPTX
Actors model in gpars
NexThoughts Technologies
 
PDF
Java 8 features
NexThoughts Technologies
 
Introduction to gradle
NexThoughts Technologies
 
Introduction to es6
NexThoughts Technologies
 
Introduction to thymeleaf
NexThoughts Technologies
 
Progressive Web-App (PWA)
NexThoughts Technologies
 
Spring Web Flow
NexThoughts Technologies
 
Unit test-using-spock in Grails
NexThoughts Technologies
 
Cosmos DB Service
NexThoughts Technologies
 
Actors model in gpars
NexThoughts Technologies
 
Java 8 features
NexThoughts Technologies
 
Ad

Similar to Reactive java - Reactive Programming + RxJava (20)

PDF
RxJava - introduction & design
allegro.tech
 
PDF
Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015
Codemotion
 
PDF
Reactive Programming for a demanding world: building event-driven and respons...
Mario Fusco
 
PPTX
RxJava 2 Reactive extensions for the JVM
Netesh Kumar
 
PPTX
Reactive Programming in Java 8 with Rx-Java
Kasun Indrasiri
 
PDF
Streams, Streams Everywhere! An Introduction to Rx
Andrzej Sitek
 
PPTX
An Introduction to RxJava
Sanjay Acharya
 
PDF
Reactive x
Gabriel Araujo
 
PPTX
Introduction to RxJava on Android
Chris Arriola
 
PPTX
Intro to Functional Programming with RxJava
Mike Nakhimovich
 
PPTX
Strange Async Code - ReaxtiveX
Matthew Will
 
PDF
Intro to Rx Java
Syed Awais Mazhar Bukhari
 
PDF
Reactive Functional Programming with Java 8 on Android N
Shipeng Xu
 
PDF
RxJava@DAUG
Maxim Volgin
 
PPTX
Mario Fusco - Reactive programming in Java - Codemotion Milan 2017
Codemotion
 
PDF
RxJava@Android
Maxim Volgin
 
PPTX
Reactive Programming with RxJava
Grand Parade Poland
 
PPTX
Microservices Part 4: Functional Reactive Programming
Araf Karsh Hamid
 
PDF
Reactive Streams and the Wide World of Groovy
Steve Pember
 
PDF
The Mayans Lost Guide to RxJava on Android
Fernando Cejas
 
RxJava - introduction & design
allegro.tech
 
Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015
Codemotion
 
Reactive Programming for a demanding world: building event-driven and respons...
Mario Fusco
 
RxJava 2 Reactive extensions for the JVM
Netesh Kumar
 
Reactive Programming in Java 8 with Rx-Java
Kasun Indrasiri
 
Streams, Streams Everywhere! An Introduction to Rx
Andrzej Sitek
 
An Introduction to RxJava
Sanjay Acharya
 
Reactive x
Gabriel Araujo
 
Introduction to RxJava on Android
Chris Arriola
 
Intro to Functional Programming with RxJava
Mike Nakhimovich
 
Strange Async Code - ReaxtiveX
Matthew Will
 
Intro to Rx Java
Syed Awais Mazhar Bukhari
 
Reactive Functional Programming with Java 8 on Android N
Shipeng Xu
 
RxJava@DAUG
Maxim Volgin
 
Mario Fusco - Reactive programming in Java - Codemotion Milan 2017
Codemotion
 
RxJava@Android
Maxim Volgin
 
Reactive Programming with RxJava
Grand Parade Poland
 
Microservices Part 4: Functional Reactive Programming
Araf Karsh Hamid
 
Reactive Streams and the Wide World of Groovy
Steve Pember
 
The Mayans Lost Guide to RxJava on Android
Fernando Cejas
 
Ad

More from NexThoughts Technologies (20)

PDF
Alexa skill
NexThoughts Technologies
 
PDF
Docker & kubernetes
NexThoughts Technologies
 
PDF
Apache commons
NexThoughts Technologies
 
PDF
Microservice Architecture using Spring Boot with React & Redux
NexThoughts Technologies
 
PDF
Solid Principles
NexThoughts Technologies
 
PDF
Introduction to TypeScript
NexThoughts Technologies
 
PDF
Smart Contract samples
NexThoughts Technologies
 
PDF
My Doc of geth
NexThoughts Technologies
 
PDF
Geth important commands
NexThoughts Technologies
 
PDF
Ethereum genesis
NexThoughts Technologies
 
PPTX
Springboot Microservices
NexThoughts Technologies
 
PDF
An Introduction to Redux
NexThoughts Technologies
 
PPTX
Google authentication
NexThoughts Technologies
 
Docker & kubernetes
NexThoughts Technologies
 
Apache commons
NexThoughts Technologies
 
Microservice Architecture using Spring Boot with React & Redux
NexThoughts Technologies
 
Solid Principles
NexThoughts Technologies
 
Introduction to TypeScript
NexThoughts Technologies
 
Smart Contract samples
NexThoughts Technologies
 
My Doc of geth
NexThoughts Technologies
 
Geth important commands
NexThoughts Technologies
 
Ethereum genesis
NexThoughts Technologies
 
Springboot Microservices
NexThoughts Technologies
 
An Introduction to Redux
NexThoughts Technologies
 
Google authentication
NexThoughts Technologies
 

Recently uploaded (20)

PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Digital Circuits, important subject in CS
contactparinay1
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 

Reactive java - Reactive Programming + RxJava

  • 2. Hello! I AM Hiten Pratap Singh I am here because I love to dig in to experience new things. You can find me at: ◦ [email protected] ◦ http://github.com/hitenpratap/ ◦ http://hprog99.wordpress.com/
  • 3. I have divided this presentation into two parts Reactive Programming RxJava
  • 4. Reactive Programming What’s Reactive Programming? What’s the big deal about it?
  • 6. “ In computing, reactive programming is a programming paradigm oriented around data flows and the propagation of change.
  • 7. Reactive Programming Reactive programming is programming with asynchronous data streams. ◦ Event buses or your typical click events are really an asynchronous event stream ◦ Streams are cheap and ubiquitous, anything can be a stream: variables, user inputs, properties etc. ◦ For example, imagine your Twitter feed would be a data stream in the same fashion that click events are.
  • 8. Reactive Programming On top of that, you are given an amazing toolbox of functions to combine, create and filter any of those streams. ◦ A stream can be used as an input to another one. ◦ You can merge two streams. ◦ You can filter a stream to get another one that has only those events you are interested in. ◦ You can map data values from one stream to another new one.
  • 9. A stream is a sequence of ongoing events ordered in time. It can emit three different things: a value (of some type), an error, or a "completed" signal. Consider that the "completed" takes place, for instance, when the current window or view containing that button is closed. We capture these emitted events only asynchronously, by defining a function that will execute when a value is emitted, another function when an error is emitted, and another function when 'completed' is emitted. The "listening" to the stream is called subscribing. The functions we are defining are observers. The stream is the subject (or "observable") being observed. This is precisely the Observer Design Pattern.
  • 10. Reactive Programming Why should I consider adopting RP? ◦ RP raises the level of abstraction of your code. ◦ Code in RP will likely be more concise. ◦ Apps nowadays have an abundancy of real-time events of every kind that enable a highly interactive experience to the user. ◦ We need tools for properly dealing with that, and Reactive Programming is an answer.
  • 11. Reactive Programming Key Takeaways ◦ RP is a specification for dealing with asynchronous streams of data. ◦ Reactive provides tools for transforming and combining streams and for managing flow-control ◦ Resembles Java Streams API but the resemblance is purely superficial
  • 12. Thinking in RP with Example
  • 14. ◦ A library for composing async and event based program by using observable sequences. ◦ Created by Microsoft initially for .Net platform by Erik Meijer ◦ Extends observer pattern- * Supports sequence of data and/or events * Add operators that allow you to compose sequences together declaratively ▫ Abstracts away concerns around * Threading and Thread Safety * Concurrent data structures and non blocking I/O ▫ RxJava is a port of Reactive Extensions created by Netflix. What’s ReactiveX?
  • 15. RxJava A libraryto use mightypowers of Reactive Programmingin Java!
  • 16. Maven Getting Started Gradle You can also include its jar file without having to use any of build system as well.
  • 19. Observable In ReactiveX an observer subscribes to an Observable. Then that observer reacts to whatever item or sequence of items the Observable emits.This patternfacilitatesconcurrent operations because it does not need to block while waiting for the Observable to emit objects,but insteadit creates a sentryin the form of an observer that stands ready to react appropriatelyat whatever future time the Observable does so. ◦ Emits zero or more values ◦ Life Cycles * Notifies Observer using onNext(T) * Completes with either onError() or onCompleted()
  • 23. Operators By Categories(Contd.) Conditional and Boolean Operators Mathematical and Aggregate Operators Backpressure Operators ReactiveX provides great flexibility over operators by letting us chaining them together or even creating new ones.
  • 35. Schedulers If you want to introduce multithreadingintoyour cascade of Observable operators, you can do so by instructingthose operators (or particular Observables) to operate on particular Schedulers.
  • 40. Single ◦ RxJava (and its derivatives like RxGroovy & RxScala) has developed an Observable variant called “Single.” ◦ A Single is something like an Observable, but instead of emitting a series of values — anywhere from none at all to an infinite number — it always either emits one value or an error notification. ◦ For this reason, instead of subscribing to a Single with the three methods you use to respond to notifications from an Observable (onNext, onError, and onCompleted), you only use two methods to subscribe:
  • 42. Subject A Subject is a sort of bridge or proxy that is available in some implementations of ReactiveX that acts both as an observer and as an Observable. Because it is an observer, it can subscribe to one or more Observables, and because it is an Observable, it can pass through the items it observes by reemitting them, and it can also emit new items. Because a Subject subscribes to an Observable, it will trigger that Observable to begin emitting items (if that Observable is “cold” — that is, if it waits for a subscription before it begins to emit items). This can have the effect of making the resulting Subject a “hot” Observable variant of the original “cold” Observable.
  • 43. Varieties of Subject ◦ AsyncSubject ◦ BehaviorSubject ◦ PublishSubject ◦ ReplaySubject
  • 49. Backpressure In RxJava it is not difficult to get into a situation in which an Observable is emitting items more rapidly than an operator or subscriber can consume them. This presents the problem of what to do with such a growing backlog of unconsumed items. For example, imagine using the zip operator to zip together two infinite Observables, one of which emits items twice as frequently as the other. A naive implementation of the zip operator would have to maintain an ever-expanding buffer of items emitted by the faster Observable to eventually combine with items emitted by the slower one. This could cause RxJava to seize an unwieldy amount of system resources.
  • 51. Hot Observable A hot Observable begins generating items to emit immediately when it is created. Subscribers typically begin observing the sequence of items emitted by a hot Observable from somewhere in the middle of the sequence, beginning with the first item emitted by the Observable subsequent to the establishment of the subscription. Such an Observable emits items at its own pace, and it is up to its observers to keep up. Examples of items emitted by a hot Observable might include mouse & keyboard events, system events, or stock prices.
  • 52. Cold Observable A cold Observable emits a particular sequence of items, but can begin emitting this sequence when its Observer finds it to be convenient, and at whatever rate the Observer desires, without disrupting the integrity of the sequence. For example if you convert a static Iterable into an Observable, that Observable will emit the same sequence of items no matter when it is later subscribed to or how frequently those items are observed. Examples of items emitted by a cold Observable might include the results of a database query, file retrieval, or web request.
  • 54. Pros ◦ Makes Async code easy to develop ◦ Lots of resources to get started with ◦ Strong use of functional type programming ◦ Netflix used RxNetty and Reactive Programmingto considerable performance advantage over Tomcat ◦ Web Service clients like Jerseyand Retrofit support RxJava.
  • 55. Cons ◦ Learning curve and mind set change to use functional reactive programming ◦ Appears like more code and more complex code initially– Requires time for it to grow on you. ◦ If on Java 7 anonymous class would make this a non-starter.
  • 56. Thanks! ANY QUESTIONS? You can find me at: [email protected] http://github.com/hitenpratap/ http://hprog99.wordpress.com/