SlideShare a Scribd company logo
RxJava2
Should I use it?
RxJava2
1. What’s new?
2. Performance
3. Libraries compatibility
4. RxJava1 compatibility
5. Summary
What’s new?
● Reactive Streams compatibility
● Observable types
● Null handling
● Backpressure handling
● Testing
Reactive Streams
“Reactive Streams is an initiative to provide a standard for asynchronous
stream processing with non-blocking back pressure. This encompasses efforts
aimed at runtime environments (JVM and JavaScript) as well as network
protocols.”
Reactive Streams
public interface Publisher<T> {
public void subscribe(Subscriber<? super T> s);
}
public interface Subscriber< T> {
public void onSubscribe (Subscription s) ;
public void onNext(T t);
public void onError(Throwable t) ;
public void onComplete();
}
Reactive Streams
public interface Subscription {
public void request(long n);
public void cancel();
}
public interface Processor<T, R> extends Subscriber<T>, Publisher<R> {
}
Observable types
Type Description
Flowable<T> Emits 0 or n items and terminates with complete or an
error. Supports backpressure, which allows to control
how fast a source emits items.
Observable<T> Emits 0 or n items and terminates with complete or an
error.
Single<T> Emits either a single item or an error. The reactive
version of a method call. You subscribe to a Single and
you get either a return value or an error.
Maybe<T> Succeeds with an item, or no item, or errors. The
reactive version of an Optional.
Completable Either completes or returns an error. It never return
items. The reactive version of a Runnable.
Null handling
Observable.just(null);
Single.just(null);
Observable.fromCallable(() -> null)
.subscribe(System. out::println, Throwable::printStackTrace) ;
Observable.just(1).map(v -> null)
.subscribe(System. out::println, Throwable::printStackTrace) ;
Null handling
Solution:
enum Irrelevant { INSTANCE }
Single.just(1).map(v -> Irrelevant. INSTANCE);
Backpressure handling
private Flowable<Integer> createFlowable (int items,
BackpressureStrategy backpressureStrategy) {
return Flowable.create(subscriber -> {
for (int i = 0; i < items; i++) {
if (subscriber.isCancelled()) {
return;
}
subscriber.onNext(i) ;
}
subscriber.onComplete() ;
}, backpressureStrategy) ;
}
Backpressure handling
● BackpressureStrategy.BUFFER
● BackpressureStrategy.DROP
● BackpressureStrategy.LATEST
● BackpressureStrategy.ERROR
● BackpressureStrategy.MISSING
Testing
@Test
public void testUsingTestObserver () {
//given
TestObserver<String> observer = new TestObserver<>() ;
Observable<String> observable = Observable. fromIterable(WORDS)
.zipWith(Observable. range(1, Integer.MAX_VALUE),
(string, index) -> String. format("%2d. %s", index, string));
//when
observable.subscribe(observer) ;
//then
observer.assertComplete() ;
observer.assertNoErrors() ;
observer.assertValueCount( 9);
assertThat(observer.values() , hasItem(" 4. fox"));
}
Testing
//given
TestObserver<String> observer = new TestObserver<>() ;
Observable<String> observable = Observable. fromIterable(WORDS)
.zipWith(Observable. range(1, Integer.MAX_VALUE),
(string, index) -> String. format("%2d. %s", index, string))
.subscribeOn(Schedulers. computation());
//when
observable.subscribe(observer) ;
//then
observer.assertComplete() ;
observer.assertNoErrors() ;
observer.assertValueCount( 4);
assertThat(observer.values() , hasItem(" 4. fox"));
Testing
public class ImmediateSchedulerRule implements TestRule {
@Override
public Statement apply(final Statement base , Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
RxJavaPlugins. setIoSchedulerHandler(build(Schedulers. trampoline()));
RxJavaPlugins. setComputationSchedulerHandler(build(Schedulers. trampoline()));
RxJavaPlugins. setNewThreadSchedulerHandler(build(Schedulers. trampoline()));
try {
base.evaluate() ;
} finally {
RxJavaPlugins. reset();
}
}
};
Testing
@Rule
public final ImmediateSchedulerRule testSchedulerRule
= new ImmediateSchedulerRule() ;
Testing
@Test
public void testUsingTestObserver () {
//given
TestObserver<String> observer ;
Observable<String> observable = Observable. fromIterable(WORDS)
.zipWith(Observable. range(1, Integer.MAX_VALUE),
(string, index) -> String. format("%2d. %s", index, string))
.subscribeOn(Schedulers. computation());
//when
observer = observable.test() ;
//then
observer.assertComplete() ;
observer.assertNoErrors() ;
observer.assertValueCount( 4);
assertThat(observer.values() , hasItem(" 4. fox"));
}
Performance
Libraries compatibility
● Retrofit READY
● Realm NOT
● Requery READY
● SugarOrm NOT
● Ormlite NOT
● GreenDao NOT
● Firebase NOT (wrapper libraries)
● SqlBrite NOT
RxJava 1 compatibility
github.com/akarnokd/RxJava2Interop
RxJava 1 compatibility
github.com/akarnokd/RxJava2Interop
Should I switch to RxJava2?

More Related Content

What's hot

Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronization
vinay arora
 
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
NAVER / MusicPlatform
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency Gotchas
Alex Miller
 
6 Synchronisation
6 Synchronisation6 Synchronisation
6 Synchronisation
Dr. Loganathan R
 
Qt Framework Events Signals Threads
Qt Framework Events Signals ThreadsQt Framework Events Signals Threads
Qt Framework Events Signals Threads
Neera Mital
 
Java Concurrency Idioms
Java Concurrency IdiomsJava Concurrency Idioms
Java Concurrency Idioms
Alex Miller
 
2009 03-26 grails-testing
2009 03-26 grails-testing2009 03-26 grails-testing
2009 03-26 grails-testing
geoffnettaglich
 
TDC 2015 SP - O ciclo de vida de aplicações UWP
TDC 2015 SP - O ciclo de vida de aplicações UWP TDC 2015 SP - O ciclo de vida de aplicações UWP
TDC 2015 SP - O ciclo de vida de aplicações UWP
Vitor Meriat
 
Angular2 rxjs
Angular2 rxjsAngular2 rxjs
Angular2 rxjs
Christoffer Noring
 
Transactions
TransactionsTransactions
Transactions
ashish61_scs
 
Compose Async with RxJS
Compose Async with RxJSCompose Async with RxJS
Compose Async with RxJS
Kyung Yeol Kim
 
J2ee Transaction Overview
J2ee Transaction OverviewJ2ee Transaction Overview
J2ee Transaction Overview
Terry Cho
 
React tips
React tipsReact tips
React tips
Vedran Maršić
 
Modeling the Behavior of Threads in the PREEMPT_RT Linux Kernel Using Automata
Modeling the Behavior of Threads in the PREEMPT_RT Linux Kernel Using AutomataModeling the Behavior of Threads in the PREEMPT_RT Linux Kernel Using Automata
Modeling the Behavior of Threads in the PREEMPT_RT Linux Kernel Using Automata
Daniel Bristot de Oliveira
 
Tdd guide
Tdd guideTdd guide
Tdd guide
Hanokh Aloni
 
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho PolutaInfinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum
 
Sistemas de control a tiempo discreto por Guillermo Guzmán
Sistemas de control a tiempo discreto por Guillermo GuzmánSistemas de control a tiempo discreto por Guillermo Guzmán
Sistemas de control a tiempo discreto por Guillermo Guzmán
GuillermoGuzmn16
 
Os3
Os3Os3
Effective java - concurrency
Effective java - concurrencyEffective java - concurrency
Effective java - concurrency
feng lee
 
Clojure concurrency overview
Clojure concurrency overviewClojure concurrency overview
Clojure concurrency overview
Sergey Stupin
 

What's hot (20)

Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronization
 
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency Gotchas
 
6 Synchronisation
6 Synchronisation6 Synchronisation
6 Synchronisation
 
Qt Framework Events Signals Threads
Qt Framework Events Signals ThreadsQt Framework Events Signals Threads
Qt Framework Events Signals Threads
 
Java Concurrency Idioms
Java Concurrency IdiomsJava Concurrency Idioms
Java Concurrency Idioms
 
2009 03-26 grails-testing
2009 03-26 grails-testing2009 03-26 grails-testing
2009 03-26 grails-testing
 
TDC 2015 SP - O ciclo de vida de aplicações UWP
TDC 2015 SP - O ciclo de vida de aplicações UWP TDC 2015 SP - O ciclo de vida de aplicações UWP
TDC 2015 SP - O ciclo de vida de aplicações UWP
 
Angular2 rxjs
Angular2 rxjsAngular2 rxjs
Angular2 rxjs
 
Transactions
TransactionsTransactions
Transactions
 
Compose Async with RxJS
Compose Async with RxJSCompose Async with RxJS
Compose Async with RxJS
 
J2ee Transaction Overview
J2ee Transaction OverviewJ2ee Transaction Overview
J2ee Transaction Overview
 
React tips
React tipsReact tips
React tips
 
Modeling the Behavior of Threads in the PREEMPT_RT Linux Kernel Using Automata
Modeling the Behavior of Threads in the PREEMPT_RT Linux Kernel Using AutomataModeling the Behavior of Threads in the PREEMPT_RT Linux Kernel Using Automata
Modeling the Behavior of Threads in the PREEMPT_RT Linux Kernel Using Automata
 
Tdd guide
Tdd guideTdd guide
Tdd guide
 
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho PolutaInfinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
 
Sistemas de control a tiempo discreto por Guillermo Guzmán
Sistemas de control a tiempo discreto por Guillermo GuzmánSistemas de control a tiempo discreto por Guillermo Guzmán
Sistemas de control a tiempo discreto por Guillermo Guzmán
 
Os3
Os3Os3
Os3
 
Effective java - concurrency
Effective java - concurrencyEffective java - concurrency
Effective java - concurrency
 
Clojure concurrency overview
Clojure concurrency overviewClojure concurrency overview
Clojure concurrency overview
 

Similar to Rx java2 - Should I use it?

Iniciación rx java
Iniciación rx javaIniciación rx java
Iniciación rx java
Elisa De Gregorio Medrano
 
Rx workshop
Rx workshopRx workshop
Rx workshop
Ryan Riley
 
How to Think in RxJava Before Reacting
How to Think in RxJava Before ReactingHow to Think in RxJava Before Reacting
How to Think in RxJava Before Reacting
IndicThreads
 
rxJava 2 tips and tricks
rxJava 2 tips and tricks rxJava 2 tips and tricks
rxJava 2 tips and tricks
Stepan Goncharov
 
Reactive mesh
Reactive meshReactive mesh
Reactive mesh
Kalin Maldzhanski
 
Saving lives with rx java
Saving lives with rx javaSaving lives with rx java
Saving lives with rx java
Shahar Barsheshet
 
RxJava applied [JavaDay Kyiv 2016]
RxJava applied [JavaDay Kyiv 2016]RxJava applied [JavaDay Kyiv 2016]
RxJava applied [JavaDay Kyiv 2016]
Igor Lozynskyi
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process Synchronization
Wayne Jones Jnr
 
RxJava 2 Reactive extensions for the JVM
RxJava 2  Reactive extensions for the JVMRxJava 2  Reactive extensions for the JVM
RxJava 2 Reactive extensions for the JVM
Netesh Kumar
 
RxJava и Android. Плюсы, минусы, подводные камни
RxJava и Android. Плюсы, минусы, подводные камниRxJava и Android. Плюсы, минусы, подводные камни
RxJava и Android. Плюсы, минусы, подводные камни
Stfalcon Meetups
 
Finagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestFinagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at Pinterest
Pavan Chitumalla
 
Reactive Streams and RxJava2
Reactive Streams and RxJava2Reactive Streams and RxJava2
Reactive Streams and RxJava2
Yakov Fain
 
Functional Programming in Java - Code for Maintainability
Functional Programming in Java - Code for MaintainabilityFunctional Programming in Java - Code for Maintainability
Functional Programming in Java - Code for Maintainability
Marcin Stepien
 
RxJava2 Slides
RxJava2 SlidesRxJava2 Slides
RxJava2 Slides
YarikS
 
RxJava on Android
RxJava on AndroidRxJava on Android
RxJava on Android
Dustin Graham
 
Reactive Java (33rd Degree)
Reactive Java (33rd Degree)Reactive Java (33rd Degree)
Reactive Java (33rd Degree)
Tomasz Kowalczewski
 
An Introduction to RxJava
An Introduction to RxJavaAn Introduction to RxJava
An Introduction to RxJava
Sanjay Acharya
 
Akka.NET streams and reactive streams
Akka.NET streams and reactive streamsAkka.NET streams and reactive streams
Akka.NET streams and reactive streams
Bartosz Sypytkowski
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
Rick Warren
 
Get Reactive: Microservices, Programming, and Systems
Get Reactive: Microservices, Programming, and SystemsGet Reactive: Microservices, Programming, and Systems
Get Reactive: Microservices, Programming, and Systems
Jeremy Davis
 

Similar to Rx java2 - Should I use it? (20)

Iniciación rx java
Iniciación rx javaIniciación rx java
Iniciación rx java
 
Rx workshop
Rx workshopRx workshop
Rx workshop
 
How to Think in RxJava Before Reacting
How to Think in RxJava Before ReactingHow to Think in RxJava Before Reacting
How to Think in RxJava Before Reacting
 
rxJava 2 tips and tricks
rxJava 2 tips and tricks rxJava 2 tips and tricks
rxJava 2 tips and tricks
 
Reactive mesh
Reactive meshReactive mesh
Reactive mesh
 
Saving lives with rx java
Saving lives with rx javaSaving lives with rx java
Saving lives with rx java
 
RxJava applied [JavaDay Kyiv 2016]
RxJava applied [JavaDay Kyiv 2016]RxJava applied [JavaDay Kyiv 2016]
RxJava applied [JavaDay Kyiv 2016]
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process Synchronization
 
RxJava 2 Reactive extensions for the JVM
RxJava 2  Reactive extensions for the JVMRxJava 2  Reactive extensions for the JVM
RxJava 2 Reactive extensions for the JVM
 
RxJava и Android. Плюсы, минусы, подводные камни
RxJava и Android. Плюсы, минусы, подводные камниRxJava и Android. Плюсы, минусы, подводные камни
RxJava и Android. Плюсы, минусы, подводные камни
 
Finagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestFinagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at Pinterest
 
Reactive Streams and RxJava2
Reactive Streams and RxJava2Reactive Streams and RxJava2
Reactive Streams and RxJava2
 
Functional Programming in Java - Code for Maintainability
Functional Programming in Java - Code for MaintainabilityFunctional Programming in Java - Code for Maintainability
Functional Programming in Java - Code for Maintainability
 
RxJava2 Slides
RxJava2 SlidesRxJava2 Slides
RxJava2 Slides
 
RxJava on Android
RxJava on AndroidRxJava on Android
RxJava on Android
 
Reactive Java (33rd Degree)
Reactive Java (33rd Degree)Reactive Java (33rd Degree)
Reactive Java (33rd Degree)
 
An Introduction to RxJava
An Introduction to RxJavaAn Introduction to RxJava
An Introduction to RxJava
 
Akka.NET streams and reactive streams
Akka.NET streams and reactive streamsAkka.NET streams and reactive streams
Akka.NET streams and reactive streams
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
 
Get Reactive: Microservices, Programming, and Systems
Get Reactive: Microservices, Programming, and SystemsGet Reactive: Microservices, Programming, and Systems
Get Reactive: Microservices, Programming, and Systems
 

Recently uploaded

SAP implementation steps PDF - Zyple Software
SAP implementation steps PDF - Zyple SoftwareSAP implementation steps PDF - Zyple Software
SAP implementation steps PDF - Zyple Software
Zyple Software
 
Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...
Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...
Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...
confluent
 
Il Data Streaming per un’AI real-time di nuova generazione
Il Data Streaming per un’AI real-time di nuova generazioneIl Data Streaming per un’AI real-time di nuova generazione
Il Data Streaming per un’AI real-time di nuova generazione
confluent
 
Applitools Autonomous 2.0 Sneak Peek.pdf
Applitools Autonomous 2.0 Sneak Peek.pdfApplitools Autonomous 2.0 Sneak Peek.pdf
Applitools Autonomous 2.0 Sneak Peek.pdf
Applitools
 
A Step-by-Step Guide to Selecting the Right Automated Software Testing Tools.pdf
A Step-by-Step Guide to Selecting the Right Automated Software Testing Tools.pdfA Step-by-Step Guide to Selecting the Right Automated Software Testing Tools.pdf
A Step-by-Step Guide to Selecting the Right Automated Software Testing Tools.pdf
kalichargn70th171
 
Authentication Review-June -2024 AP & TS.pptx
Authentication Review-June -2024 AP & TS.pptxAuthentication Review-June -2024 AP & TS.pptx
Authentication Review-June -2024 AP & TS.pptx
DEMONDUOS
 
Girls Call Jogeshwari 9967584737 Provide Best And Top Girl Service And No1 in...
Girls Call Jogeshwari 9967584737 Provide Best And Top Girl Service And No1 in...Girls Call Jogeshwari 9967584737 Provide Best And Top Girl Service And No1 in...
Girls Call Jogeshwari 9967584737 Provide Best And Top Girl Service And No1 in...
simran hot girls
 
How To Fill Timesheet in TaskSprint: Quick Guide 2024
How To Fill Timesheet in TaskSprint: Quick Guide 2024How To Fill Timesheet in TaskSprint: Quick Guide 2024
How To Fill Timesheet in TaskSprint: Quick Guide 2024
TaskSprint | Employee Efficiency Software
 
Amazon Music Spelling Correction - SIGIR 2024
Amazon Music Spelling Correction - SIGIR 2024Amazon Music Spelling Correction - SIGIR 2024
Amazon Music Spelling Correction - SIGIR 2024
siddharth1729
 
當測試開始左移
當測試開始左移當測試開始左移
當測試開始左移
Jersey (CHE-PING) Su
 
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in CityGirls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
neshakor5152
 
Independent Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class H...
Independent Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class H...Independent Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class H...
Independent Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class H...
aslasdfmkhan4750
 
Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...
Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...
Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...
bhumivarma35300
 
GT degree offer diploma Transcript
GT degree offer diploma TranscriptGT degree offer diploma Transcript
GT degree offer diploma Transcript
attueb
 
AWS DevOps-Tutorial CHANAKYA SRIYAN DUKKA.
AWS DevOps-Tutorial CHANAKYA SRIYAN DUKKA.AWS DevOps-Tutorial CHANAKYA SRIYAN DUKKA.
AWS DevOps-Tutorial CHANAKYA SRIYAN DUKKA.
Srinivas Dukka
 
Celebrity Girls Call Mumbai 9930687706 Unlimited Short Providing Girls Servic...
Celebrity Girls Call Mumbai 9930687706 Unlimited Short Providing Girls Servic...Celebrity Girls Call Mumbai 9930687706 Unlimited Short Providing Girls Servic...
Celebrity Girls Call Mumbai 9930687706 Unlimited Short Providing Girls Servic...
kiara pandey
 
Private Girls Call Navi Mumbai 🛵🚡9820252231 💃 Choose Best And Top Girl Servic...
Private Girls Call Navi Mumbai 🛵🚡9820252231 💃 Choose Best And Top Girl Servic...Private Girls Call Navi Mumbai 🛵🚡9820252231 💃 Choose Best And Top Girl Servic...
Private Girls Call Navi Mumbai 🛵🚡9820252231 💃 Choose Best And Top Girl Servic...
902basic
 
AI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdf
AI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdfAI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdf
AI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdf
Daniel Zivkovic
 
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
OnePlan Solutions
 
Crafting highly scalable and performant Modern Data Platforms
Crafting highly scalable and performant Modern Data PlatformsCrafting highly scalable and performant Modern Data Platforms
Crafting highly scalable and performant Modern Data Platforms
Sameer Paradkar
 

Recently uploaded (20)

SAP implementation steps PDF - Zyple Software
SAP implementation steps PDF - Zyple SoftwareSAP implementation steps PDF - Zyple Software
SAP implementation steps PDF - Zyple Software
 
Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...
Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...
Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...
 
Il Data Streaming per un’AI real-time di nuova generazione
Il Data Streaming per un’AI real-time di nuova generazioneIl Data Streaming per un’AI real-time di nuova generazione
Il Data Streaming per un’AI real-time di nuova generazione
 
Applitools Autonomous 2.0 Sneak Peek.pdf
Applitools Autonomous 2.0 Sneak Peek.pdfApplitools Autonomous 2.0 Sneak Peek.pdf
Applitools Autonomous 2.0 Sneak Peek.pdf
 
A Step-by-Step Guide to Selecting the Right Automated Software Testing Tools.pdf
A Step-by-Step Guide to Selecting the Right Automated Software Testing Tools.pdfA Step-by-Step Guide to Selecting the Right Automated Software Testing Tools.pdf
A Step-by-Step Guide to Selecting the Right Automated Software Testing Tools.pdf
 
Authentication Review-June -2024 AP & TS.pptx
Authentication Review-June -2024 AP & TS.pptxAuthentication Review-June -2024 AP & TS.pptx
Authentication Review-June -2024 AP & TS.pptx
 
Girls Call Jogeshwari 9967584737 Provide Best And Top Girl Service And No1 in...
Girls Call Jogeshwari 9967584737 Provide Best And Top Girl Service And No1 in...Girls Call Jogeshwari 9967584737 Provide Best And Top Girl Service And No1 in...
Girls Call Jogeshwari 9967584737 Provide Best And Top Girl Service And No1 in...
 
How To Fill Timesheet in TaskSprint: Quick Guide 2024
How To Fill Timesheet in TaskSprint: Quick Guide 2024How To Fill Timesheet in TaskSprint: Quick Guide 2024
How To Fill Timesheet in TaskSprint: Quick Guide 2024
 
Amazon Music Spelling Correction - SIGIR 2024
Amazon Music Spelling Correction - SIGIR 2024Amazon Music Spelling Correction - SIGIR 2024
Amazon Music Spelling Correction - SIGIR 2024
 
當測試開始左移
當測試開始左移當測試開始左移
當測試開始左移
 
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in CityGirls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
 
Independent Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class H...
Independent Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class H...Independent Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class H...
Independent Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class H...
 
Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...
Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...
Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...
 
GT degree offer diploma Transcript
GT degree offer diploma TranscriptGT degree offer diploma Transcript
GT degree offer diploma Transcript
 
AWS DevOps-Tutorial CHANAKYA SRIYAN DUKKA.
AWS DevOps-Tutorial CHANAKYA SRIYAN DUKKA.AWS DevOps-Tutorial CHANAKYA SRIYAN DUKKA.
AWS DevOps-Tutorial CHANAKYA SRIYAN DUKKA.
 
Celebrity Girls Call Mumbai 9930687706 Unlimited Short Providing Girls Servic...
Celebrity Girls Call Mumbai 9930687706 Unlimited Short Providing Girls Servic...Celebrity Girls Call Mumbai 9930687706 Unlimited Short Providing Girls Servic...
Celebrity Girls Call Mumbai 9930687706 Unlimited Short Providing Girls Servic...
 
Private Girls Call Navi Mumbai 🛵🚡9820252231 💃 Choose Best And Top Girl Servic...
Private Girls Call Navi Mumbai 🛵🚡9820252231 💃 Choose Best And Top Girl Servic...Private Girls Call Navi Mumbai 🛵🚡9820252231 💃 Choose Best And Top Girl Servic...
Private Girls Call Navi Mumbai 🛵🚡9820252231 💃 Choose Best And Top Girl Servic...
 
AI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdf
AI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdfAI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdf
AI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdf
 
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
 
Crafting highly scalable and performant Modern Data Platforms
Crafting highly scalable and performant Modern Data PlatformsCrafting highly scalable and performant Modern Data Platforms
Crafting highly scalable and performant Modern Data Platforms
 

Rx java2 - Should I use it?

  • 2. RxJava2 1. What’s new? 2. Performance 3. Libraries compatibility 4. RxJava1 compatibility 5. Summary
  • 3. What’s new? ● Reactive Streams compatibility ● Observable types ● Null handling ● Backpressure handling ● Testing
  • 4. Reactive Streams “Reactive Streams is an initiative to provide a standard for asynchronous stream processing with non-blocking back pressure. This encompasses efforts aimed at runtime environments (JVM and JavaScript) as well as network protocols.”
  • 5. Reactive Streams public interface Publisher<T> { public void subscribe(Subscriber<? super T> s); } public interface Subscriber< T> { public void onSubscribe (Subscription s) ; public void onNext(T t); public void onError(Throwable t) ; public void onComplete(); }
  • 6. Reactive Streams public interface Subscription { public void request(long n); public void cancel(); } public interface Processor<T, R> extends Subscriber<T>, Publisher<R> { }
  • 7. Observable types Type Description Flowable<T> Emits 0 or n items and terminates with complete or an error. Supports backpressure, which allows to control how fast a source emits items. Observable<T> Emits 0 or n items and terminates with complete or an error. Single<T> Emits either a single item or an error. The reactive version of a method call. You subscribe to a Single and you get either a return value or an error. Maybe<T> Succeeds with an item, or no item, or errors. The reactive version of an Optional. Completable Either completes or returns an error. It never return items. The reactive version of a Runnable.
  • 8. Null handling Observable.just(null); Single.just(null); Observable.fromCallable(() -> null) .subscribe(System. out::println, Throwable::printStackTrace) ; Observable.just(1).map(v -> null) .subscribe(System. out::println, Throwable::printStackTrace) ;
  • 9. Null handling Solution: enum Irrelevant { INSTANCE } Single.just(1).map(v -> Irrelevant. INSTANCE);
  • 10. Backpressure handling private Flowable<Integer> createFlowable (int items, BackpressureStrategy backpressureStrategy) { return Flowable.create(subscriber -> { for (int i = 0; i < items; i++) { if (subscriber.isCancelled()) { return; } subscriber.onNext(i) ; } subscriber.onComplete() ; }, backpressureStrategy) ; }
  • 11. Backpressure handling ● BackpressureStrategy.BUFFER ● BackpressureStrategy.DROP ● BackpressureStrategy.LATEST ● BackpressureStrategy.ERROR ● BackpressureStrategy.MISSING
  • 12. Testing @Test public void testUsingTestObserver () { //given TestObserver<String> observer = new TestObserver<>() ; Observable<String> observable = Observable. fromIterable(WORDS) .zipWith(Observable. range(1, Integer.MAX_VALUE), (string, index) -> String. format("%2d. %s", index, string)); //when observable.subscribe(observer) ; //then observer.assertComplete() ; observer.assertNoErrors() ; observer.assertValueCount( 9); assertThat(observer.values() , hasItem(" 4. fox")); }
  • 13. Testing //given TestObserver<String> observer = new TestObserver<>() ; Observable<String> observable = Observable. fromIterable(WORDS) .zipWith(Observable. range(1, Integer.MAX_VALUE), (string, index) -> String. format("%2d. %s", index, string)) .subscribeOn(Schedulers. computation()); //when observable.subscribe(observer) ; //then observer.assertComplete() ; observer.assertNoErrors() ; observer.assertValueCount( 4); assertThat(observer.values() , hasItem(" 4. fox"));
  • 14. Testing public class ImmediateSchedulerRule implements TestRule { @Override public Statement apply(final Statement base , Description description) { return new Statement() { @Override public void evaluate() throws Throwable { RxJavaPlugins. setIoSchedulerHandler(build(Schedulers. trampoline())); RxJavaPlugins. setComputationSchedulerHandler(build(Schedulers. trampoline())); RxJavaPlugins. setNewThreadSchedulerHandler(build(Schedulers. trampoline())); try { base.evaluate() ; } finally { RxJavaPlugins. reset(); } } };
  • 15. Testing @Rule public final ImmediateSchedulerRule testSchedulerRule = new ImmediateSchedulerRule() ;
  • 16. Testing @Test public void testUsingTestObserver () { //given TestObserver<String> observer ; Observable<String> observable = Observable. fromIterable(WORDS) .zipWith(Observable. range(1, Integer.MAX_VALUE), (string, index) -> String. format("%2d. %s", index, string)) .subscribeOn(Schedulers. computation()); //when observer = observable.test() ; //then observer.assertComplete() ; observer.assertNoErrors() ; observer.assertValueCount( 4); assertThat(observer.values() , hasItem(" 4. fox")); }
  • 18. Libraries compatibility ● Retrofit READY ● Realm NOT ● Requery READY ● SugarOrm NOT ● Ormlite NOT ● GreenDao NOT ● Firebase NOT (wrapper libraries) ● SqlBrite NOT
  • 21. Should I switch to RxJava2?