SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Downloaden Sie, um offline zu lesen
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?

Weitere ähnliche Inhalte

Was ist angesagt?

Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronizationvinay arora
 
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015NAVER / MusicPlatform
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency GotchasAlex Miller
 
Qt Framework Events Signals Threads
Qt Framework Events Signals ThreadsQt Framework Events Signals Threads
Qt Framework Events Signals ThreadsNeera Mital
 
Java Concurrency Idioms
Java Concurrency IdiomsJava Concurrency Idioms
Java Concurrency IdiomsAlex Miller
 
2009 03-26 grails-testing
2009 03-26 grails-testing2009 03-26 grails-testing
2009 03-26 grails-testinggeoffnettaglich
 
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
 
Compose Async with RxJS
Compose Async with RxJSCompose Async with RxJS
Compose Async with RxJSKyung Yeol Kim
 
J2ee Transaction Overview
J2ee Transaction OverviewJ2ee Transaction Overview
J2ee Transaction OverviewTerry Cho
 
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 AutomataDaniel Bristot de Oliveira
 
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 PolutaInfinum
 
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ánGuillermoGuzmn16
 
Effective java - concurrency
Effective java - concurrencyEffective java - concurrency
Effective java - concurrencyfeng lee
 
Clojure concurrency overview
Clojure concurrency overviewClojure concurrency overview
Clojure concurrency overviewSergey Stupin
 

Was ist angesagt? (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
 

Ähnlich wie Rx java2 - Should I use it?

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 ReactingIndicThreads
 
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 SynchronizationWayne 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 JVMNetesh 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 PinterestPavan Chitumalla
 
Reactive Streams and RxJava2
Reactive Streams and RxJava2Reactive Streams and RxJava2
Reactive Streams and RxJava2Yakov 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 MaintainabilityMarcin Stepien
 
RxJava2 Slides
RxJava2 SlidesRxJava2 Slides
RxJava2 SlidesYarikS
 
An Introduction to RxJava
An Introduction to RxJavaAn Introduction to RxJava
An Introduction to RxJavaSanjay Acharya
 
Akka.NET streams and reactive streams
Akka.NET streams and reactive streamsAkka.NET streams and reactive streams
Akka.NET streams and reactive streamsBartosz Sypytkowski
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaRick Warren
 
Get Reactive: Microservices, Programming, and Systems
Get Reactive: Microservices, Programming, and SystemsGet Reactive: Microservices, Programming, and Systems
Get Reactive: Microservices, Programming, and SystemsJeremy Davis
 

Ähnlich wie 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
 

Kürzlich hochgeladen

%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 

Kürzlich hochgeladen (20)

%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 

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?