Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Rx Java introduction
Search
SingaSUG
July 29, 2015
Technology
0
120
Rx Java introduction
Talk from Xavier Lepretre
SingaSUG
July 29, 2015
Tweet
Share
More Decks by SingaSUG
See All by SingaSUG
Java/Spring and Node.JS side by side
singasug
0
200
Migrating to microservices (Carlos Queiroz)
singasug
0
230
Docker 101 - Mario Loriedo
singasug
0
270
Docker for Java/Spring developers
singasug
0
88
Cloud Foundry and Docker
singasug
0
210
Multi dimensional scaling with CouchBase
singasug
1
130
NoSql presentation from Clarence Tauro
singasug
2
190
Spring Websockets
singasug
0
210
migrating from JSP to AngularJS
singasug
0
2.6k
Other Decks in Technology
See All in Technology
BiDiってなんだ?
tomorrowkey
1
300
ReproでのicebergのStreaming Writeの検証と実運用にむけた取り組み
joker1007
0
350
AI Agent Agentic Workflow の可観測性 / Observability of AI Agent Agentic Workflow
yuzujoe
5
2.3k
「全社導入」は結果。1人の熱狂が組織に伝播したmikanのn8n活用
sota_mikami
0
300
Agentic Coding 実践ワークショップ
watany
25
20k
Exadata Database Service ソフトウェアのアップデートとアップグレードの概要
oracle4engineer
PRO
1
1.2k
純粋なイミュータブルモデルを設計してからイベントソーシングと組み合わせるDeciderの実践方法の紹介 /Introducing Decider Pattern with Event Sourcing
tomohisa
1
1.3k
All About Sansan – for New Global Engineers
sansan33
PRO
1
1.3k
さくらのクラウドでのシークレット管理を考える/tamachi.sre#2
fujiwara3
1
210
クラウドセキュリティの進化 — AWSの20年を振り返る
kei4eva4
0
150
20260120 Amazon VPC のパブリックサブネットを無くしたい!
masaruogura
2
140
これまでのネットワーク運用を変えるかもしれないアプデをおさらい
hatahata021
4
250
Featured
See All Featured
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
250
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
890
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
150
How Software Deployment tools have changed in the past 20 years
geshan
0
31k
For a Future-Friendly Web
brad_frost
181
10k
The Limits of Empathy - UXLibs8
cassininazir
1
200
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
54
49k
How to Ace a Technical Interview
jacobian
281
24k
Balancing Empowerment & Direction
lara
5
850
Raft: Consensus for Rubyists
vanstee
141
7.3k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.3k
Transcript
RxJava Intro Functional reactive programming By Xavier Lepretre
What we want What we know
Imperative and synchronous var a = fetch(key); var b =
transform(a); var c = transformAgain(b); return process(c);
Asynchronous with callbacks fetch(key, new Callback() { void onReceived(a) {
transform(a, new Callback() { void onFinished(b) ... }); } });
Futures future = executor.submit(new Callback() { Object call() { return
doLongExecution(); } }); a = future.get();
Nice to have, workflow description When done, do that fetch(key).then(a
-> transform(a)) .then(b -> transformAgain(b)) .then(c -> process(c)) .then(d -> use(d));
Important classes
Observable<MyType> - like an object(s) pipe - no limit on
number of objects piped - also pipes Throwable - signals when no more object, completed - can have many observers, like a multicast
Observer<MyType> - will receive: - the objects - the errors
- the completed signal - can subscribe to many observables
Subscription - a handle to an observer subscribed to an
observable - call .unsubscribe() when you no longer need to receive
Action1<MyType> { void call(MyType obj); } - 1 because it
takes 1 parameter - There are Action2 … Action9
Func1<MyType, NextType> { public NextType call(MyType obj); } - 1
because it takes 1 parameter - There are Func2 … Func9
Important operations
.map(new Func1<A,B>(){}) - works on an object traveling along the
pipe - transforms from one type to another - to be used when the transformation is synchronous - example: convert
None
.doOnNext(new Action1<A>(){}) - Works on a object from the pipe
- Leaves the object unchanged - Example: save in cache, log
None
.flatMap(Func1<A, Observable<B>>) - Works on an object traveling along the
pipe - Transforms from one type to another - To be used when the transformation is asynchronous - Example: network fetch, open dialog
None
Advantages - Unsubscription handles removing callback - Method can describe
a subset of workflow
Create your own: OnSubscribe<> - Change callbacks into objects in
pipeline - Know when to call onCompleted() - subscribeOn() - Subscriptions.create() - AndroidSubscriptions. unsubscribeInUiThread
Pitfalls - Forgot to .subscribe() - subscriptionList.unsubscribe(). Do not reuse
- forgot observeOn(AndroidSchedulers. mainThread()) - callbacks may not show as used if you use retrolambda
Code Example https://github.com/xavierlepretre/rx-example
- All code shown is on client - Retrofit creates
Observables -
- workflow pieces in methods: for dialog, no need to
know next step - .onErrorResumeNext() to avoid break on less important elements - .flatMap() to show and wait for dialog - .publish() and .connect() to share Observable - SimpleAlertDialogOperator to convert a dialog into Observable