SlideShare a Scribd company logo
1 of 40
APACHE SLING & FRIENDS TECH MEETUP 
BERLIN, 22-24 SEPTEMBER 2014 
OSGi Asynchronous Services: more than RPC 
Michael Dürig, Adobe Research
Some typical code 
socket.getInputStream().read(buffer);
Timings on typical hardware... 
Execute CPU instruction 1ns 
Fetch from L2 cache 7 ns 
Fetch from memory 100 ns 
Read from disk 8 ms 
Network round-trip Europe-US 150 ms 
source: http://norvig.com/21-days.html#answers
...in human terms 
Execute CPU instruction 1 s 
Fetch from L2 cache 7 s 
Fetch from memory 1.6 min 
Read from disk 13.2 weeks 
Network round-trip Europe-US 4.8 years 
source: http://norvig.com/21-days.html#answers
Outline 
 OSGi RFC 206: Asynchronous Services 
 Promise 
 Example
Goals 
 Improve resource utilisation 
 Parallelism 
 Non blocking IO 
 Automatic thread management 
 Runtime vs. hard coded
OSGi RFC 206: Asynchronous Services 
 Asynchronous method calls 
 Return Promise<T> instead of T 
 Direct implementations 
 Mediation through Async
Mediating a service 
Async async = ... 
ServiceReference<Weather> ref = ... 
Weather weather = async.mediate(ref, Weather.class); 
Promise<Boolean> sunnyPromise = async.call(weather.isSunny());
Promise<T>?
Promise 
 Encapsulation of a value that 
 maybe available at some later time 
 can be read multiple times 
 immutable once resolved
Promise callback 
sunnyPromise.then(...
Promise callback: success 
weather.isSunny().then( 
success -> { 
if (success.getValue()) { 
println("Sun fun and nothing to do"); 
} else { 
println("Singing in the rain"); 
}}, 
...
Promise callback: failure 
weather.isSunny().then( 
success -> { 
if (success.getValue()) { 
println("Sun fun and nothing to do"); 
} else { 
println("Singing in the rain"); 
}}, 
failure -> { 
failure.getFailure().printStackTrace();});
Effects 
 Promises capture the effects of 
 latency: when the call back happens 
 error: which call back happens
Promise<T>!
Vendor Service 
interface Vendor { 
Promise<Offer> getOffer(String item); 
} 
class Offer { 
public Offer(Vendor vendor, 
String item, 
double price, 
String currency) { 
...
Exchange Service 
Promise<Offer> convertToEuro1(Offer offer); 
Promise<Offer> convertToEuro2(Offer offer);
Goals 
 Get offer from vendor 
 Convert to € with recovery 
 Fail gracefully 
 Non blocking!
getOffer... 
Promise<Offer> getOffer(Vendor vendor, String item) { 
return vendor 
.getOffer(item); 
}
flatMap 
Promise<R> flatMap(T -> Promise<R>)
flatMap 
Promise<R> flatMap(Offer -> Promise<R>)
flatMap 
Promise<Offer> flatMap(Offer -> Promise<Offer>)
flatMap 
Promise<Offer> flatMap(Offer -> Promise<Offer>) 
Promise<Offer> convertToEuro1(Offer);
getOffer: convert to € 
Promise<Offer> getOffer(Vendor vendor, String item) { 
return vendor 
.getOffer(item) 
.flatMap(offer -> convertToEuro1(offer)); 
}
recoverWith 
Promise<R> recoverWith(Promise<?> -> Promise<R>)
recoverWith 
Promise<Offer> recoverWith(Promise<?> -> Promise<Offer>)
recoverWith 
Promise<Offer> recoverWith(Promise<?> -> Promise<Offer>) 
Promise<Offer> convertToEuro2(Offer);
getOffer: fallback 
Promise<Offer> getOffer(Vendor vendor, String item) { 
return vendor 
.getOffer(item) 
.flatMap(offer -> convertToEuro1(offer) 
.recoverWith(failed -> convertToEuro2(offer))); 
}
recover 
Promise<R> recover(Promise<?> -> R)
recover 
Promise<Offer> recover(Promise<?> -> Offer)
getOffer: fail gracefully 
Promise<Offer> getOffer(Vendor vendor, String item) { 
return vendor 
.getOffer(item) 
.flatMap(offer -> convertToEuro1(offer) 
.recoverWith(failed -> convertToEuro2(offer)) 
.recover(failed -> Offer.NONE)); 
}
Non blocking 
Act on Promise<T>instead of T
Demo
Summary 
 Promises capture latency and error 
 Non blocking 
 Focus on main path 
 Decouple parallelisation 
 Better resource utilisation 
 Application scalability
Resources 
http://goo.gl/pB9fza
Appendix
Deferred 
 Encapsulation of a value that 
 should be made available at some later time 
 can be written once 
 immutable once resolved
What about j.u.concurrent.Future? 
 Blocking semantics 
 No callbacks 
 Not composable 
 No map/flatMap/filter/...
Resources 
 Support material: https://github.com/mduerig/async-support/wiki 
 Session slides 
 Runnable demo 
 Links to further reading 
 RFC 206: https://github.com/osgi/design/tree/master/rfcs/rfc0206 
 Public draft of OSGi RFC 206: Asynchronous Services 
 OSGi Alliance: http://www.osgi.org/
Resources 
 RxJava: https://github.com/ReactiveX/RxJava 
 Observables: taking Promises one step further 
 Akka: http://akka.io/ 
 Toolkit for concurrent and distributed applications on the JVM

More Related Content

What's hot

The Ring programming language version 1.5.1 book - Part 71 of 180
The Ring programming language version 1.5.1 book - Part 71 of 180The Ring programming language version 1.5.1 book - Part 71 of 180
The Ring programming language version 1.5.1 book - Part 71 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 87 of 212
The Ring programming language version 1.10 book - Part 87 of 212The Ring programming language version 1.10 book - Part 87 of 212
The Ring programming language version 1.10 book - Part 87 of 212Mahmoud Samir Fayed
 
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"OdessaJS Conf
 
The Ring programming language version 1.2 book - Part 54 of 84
The Ring programming language version 1.2 book - Part 54 of 84The Ring programming language version 1.2 book - Part 54 of 84
The Ring programming language version 1.2 book - Part 54 of 84Mahmoud Samir Fayed
 
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"OdessaJS Conf
 
Zeromq - Pycon India 2013
Zeromq - Pycon India 2013Zeromq - Pycon India 2013
Zeromq - Pycon India 2013Srinivasan R
 
Concurrency in Golang
Concurrency in GolangConcurrency in Golang
Concurrency in GolangOliver N
 
Golang concurrency design
Golang concurrency designGolang concurrency design
Golang concurrency designHyejong
 
Introducere In Java Jx
Introducere In Java JxIntroducere In Java Jx
Introducere In Java Jxdanielnastase
 
Basic C concepts.
Basic C concepts.Basic C concepts.
Basic C concepts.Farooq Mian
 
Game Analytics Cluster Scheduler
Game Analytics Cluster SchedulerGame Analytics Cluster Scheduler
Game Analytics Cluster Schedulercmmdevries
 
Scheduling torque-maui-tutorial
Scheduling torque-maui-tutorialScheduling torque-maui-tutorial
Scheduling torque-maui-tutorialSantosh Kumar
 
Programa Sumar y Multiplicar
Programa Sumar y MultiplicarPrograma Sumar y Multiplicar
Programa Sumar y MultiplicarAnais Rodriguez
 
Benchmarking and PHPBench
Benchmarking and PHPBenchBenchmarking and PHPBench
Benchmarking and PHPBenchdantleech
 
NS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variablesNS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variablesTeerawat Issariyakul
 
function* - ES6, generators, and all that (JSRomandie meetup, February 2014)
function* - ES6, generators, and all that (JSRomandie meetup, February 2014)function* - ES6, generators, and all that (JSRomandie meetup, February 2014)
function* - ES6, generators, and all that (JSRomandie meetup, February 2014)Igalia
 
A gremlin in my graph confoo 2014
A gremlin in my graph confoo 2014A gremlin in my graph confoo 2014
A gremlin in my graph confoo 2014Damien Seguy
 

What's hot (20)

The Ring programming language version 1.5.1 book - Part 71 of 180
The Ring programming language version 1.5.1 book - Part 71 of 180The Ring programming language version 1.5.1 book - Part 71 of 180
The Ring programming language version 1.5.1 book - Part 71 of 180
 
The Ring programming language version 1.10 book - Part 87 of 212
The Ring programming language version 1.10 book - Part 87 of 212The Ring programming language version 1.10 book - Part 87 of 212
The Ring programming language version 1.10 book - Part 87 of 212
 
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
 
Oop1
Oop1Oop1
Oop1
 
The Ring programming language version 1.2 book - Part 54 of 84
The Ring programming language version 1.2 book - Part 54 of 84The Ring programming language version 1.2 book - Part 54 of 84
The Ring programming language version 1.2 book - Part 54 of 84
 
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
 
Zeromq - Pycon India 2013
Zeromq - Pycon India 2013Zeromq - Pycon India 2013
Zeromq - Pycon India 2013
 
Concurrency in Golang
Concurrency in GolangConcurrency in Golang
Concurrency in Golang
 
Golang concurrency design
Golang concurrency designGolang concurrency design
Golang concurrency design
 
Introducere In Java Jx
Introducere In Java JxIntroducere In Java Jx
Introducere In Java Jx
 
Basic C concepts.
Basic C concepts.Basic C concepts.
Basic C concepts.
 
Game Analytics Cluster Scheduler
Game Analytics Cluster SchedulerGame Analytics Cluster Scheduler
Game Analytics Cluster Scheduler
 
Scheduling torque-maui-tutorial
Scheduling torque-maui-tutorialScheduling torque-maui-tutorial
Scheduling torque-maui-tutorial
 
Textile
TextileTextile
Textile
 
Programa Sumar y Multiplicar
Programa Sumar y MultiplicarPrograma Sumar y Multiplicar
Programa Sumar y Multiplicar
 
Benchmarking and PHPBench
Benchmarking and PHPBenchBenchmarking and PHPBench
Benchmarking and PHPBench
 
NS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variablesNS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variables
 
Golang design4concurrency
Golang design4concurrencyGolang design4concurrency
Golang design4concurrency
 
function* - ES6, generators, and all that (JSRomandie meetup, February 2014)
function* - ES6, generators, and all that (JSRomandie meetup, February 2014)function* - ES6, generators, and all that (JSRomandie meetup, February 2014)
function* - ES6, generators, and all that (JSRomandie meetup, February 2014)
 
A gremlin in my graph confoo 2014
A gremlin in my graph confoo 2014A gremlin in my graph confoo 2014
A gremlin in my graph confoo 2014
 

Similar to OSGi Asynchronous Services: more than RPC

When symfony met promises
When symfony met promises When symfony met promises
When symfony met promises Marc Morera
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in GolangBo-Yi Wu
 
ngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency InjectionngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency InjectionDzmitry Ivashutsin
 
Fast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPCFast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPCTim Burks
 
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
 
Un dsl pour ma base de données
Un dsl pour ma base de donnéesUn dsl pour ma base de données
Un dsl pour ma base de donnéesRomain Lecomte
 
Currying and Partial Function Application (PFA)
Currying and Partial Function Application (PFA)Currying and Partial Function Application (PFA)
Currying and Partial Function Application (PFA)Dhaval Dalal
 
Introduction to nsubstitute
Introduction to nsubstituteIntroduction to nsubstitute
Introduction to nsubstituteSuresh Loganatha
 
TDC2016POA | Trilha JavaScript - JavaScript Promises na Prática
TDC2016POA | Trilha JavaScript - JavaScript Promises na PráticaTDC2016POA | Trilha JavaScript - JavaScript Promises na Prática
TDC2016POA | Trilha JavaScript - JavaScript Promises na Práticatdc-globalcode
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuningAOE
 
$q and Promises in AngularJS
$q and Promises in AngularJS $q and Promises in AngularJS
$q and Promises in AngularJS a_sharif
 
Better react/redux apps using redux-saga
Better react/redux apps using redux-sagaBetter react/redux apps using redux-saga
Better react/redux apps using redux-sagaYounes (omar) Meliani
 
AngularJS, More Than Directives !
AngularJS, More Than Directives !AngularJS, More Than Directives !
AngularJS, More Than Directives !Gaurav Behere
 
«Gevent — быть или не быть?» Александр Мокров, Positive Technologies
«Gevent — быть или не быть?» Александр Мокров, Positive Technologies«Gevent — быть или не быть?» Александр Мокров, Positive Technologies
«Gevent — быть или не быть?» Александр Мокров, Positive Technologiesit-people
 
Introduction to ParSeq: to make asynchronous java easier
Introduction to ParSeq: to make asynchronous java easierIntroduction to ParSeq: to make asynchronous java easier
Introduction to ParSeq: to make asynchronous java easierJunchuan Wang
 
How to perform debounce in react
How to perform debounce in reactHow to perform debounce in react
How to perform debounce in reactBOSC Tech Labs
 

Similar to OSGi Asynchronous Services: more than RPC (20)

When symfony met promises
When symfony met promises When symfony met promises
When symfony met promises
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in Golang
 
ngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency InjectionngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency Injection
 
Fast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPCFast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPC
 
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
 
Un dsl pour ma base de données
Un dsl pour ma base de donnéesUn dsl pour ma base de données
Un dsl pour ma base de données
 
Currying and Partial Function Application (PFA)
Currying and Partial Function Application (PFA)Currying and Partial Function Application (PFA)
Currying and Partial Function Application (PFA)
 
Introduction to nsubstitute
Introduction to nsubstituteIntroduction to nsubstitute
Introduction to nsubstitute
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
TDC2016POA | Trilha JavaScript - JavaScript Promises na Prática
TDC2016POA | Trilha JavaScript - JavaScript Promises na PráticaTDC2016POA | Trilha JavaScript - JavaScript Promises na Prática
TDC2016POA | Trilha JavaScript - JavaScript Promises na Prática
 
Promises & limbo
Promises & limboPromises & limbo
Promises & limbo
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuning
 
$q and Promises in AngularJS
$q and Promises in AngularJS $q and Promises in AngularJS
$q and Promises in AngularJS
 
Better react/redux apps using redux-saga
Better react/redux apps using redux-sagaBetter react/redux apps using redux-saga
Better react/redux apps using redux-saga
 
AngularJS, More Than Directives !
AngularJS, More Than Directives !AngularJS, More Than Directives !
AngularJS, More Than Directives !
 
Gevent be or not to be
Gevent be or not to beGevent be or not to be
Gevent be or not to be
 
«Gevent — быть или не быть?» Александр Мокров, Positive Technologies
«Gevent — быть или не быть?» Александр Мокров, Positive Technologies«Gevent — быть или не быть?» Александр Мокров, Positive Technologies
«Gevent — быть или не быть?» Александр Мокров, Positive Technologies
 
Refactoring Example
Refactoring ExampleRefactoring Example
Refactoring Example
 
Introduction to ParSeq: to make asynchronous java easier
Introduction to ParSeq: to make asynchronous java easierIntroduction to ParSeq: to make asynchronous java easier
Introduction to ParSeq: to make asynchronous java easier
 
How to perform debounce in react
How to perform debounce in reactHow to perform debounce in react
How to perform debounce in react
 

Recently uploaded

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 

Recently uploaded (20)

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 

OSGi Asynchronous Services: more than RPC

Editor's Notes

  1. RFC 206: https://github.com/osgi/design/tree/master/rfcs/rfc0206 Work in progress. Emphasis on general concepts and Promises (2nd part)
  2. Side effects: Might throw an exception Blocks waiting for more data Blocking is not evident from the API signature: easy to forget about it Handling side effects is awkward: Exception handling is difficult and blurs the main code path. Not blocking is next to impossible in with this style.
  3. Blocking is an issue!
  4. Scaling up to human terms results in almost 5 years spent waiting. Think of what could be done during that time!
  5. RFC 206 Asynchronous services provide ways to call methods asynchronously. By introducing the concept of a Promise they addresses the problems with exception handling and blocking.
  6. Maximise application throughput and resource utilisation by submitting tasks for execution and letting the environment decide on how, when and where to execute them. Optimise resource utilisation by letting the environment assign threads to the units of parallelisation instead of managing threads manually in the application. The environment is in much better control of the available resources. This is similar to the shift from manual memory management to automatic memory management that took place in the 90ies.
  7. Asynchronous calls are not handles “transparently” as common in RPC. The side effects concerning remote calls are reflected in the return type: Promise<T> instead of T While any OSGi service can be converted to an asynchronous service via a mediation service, direct implementations are encouraged. The only requirement for such a service is to return a Promise. The Promise API can be used independently of the rest of the OSGi framework.
  8. T Async#mediate(ServiceReference<T>, Class<T>) returns an asynchronous service for T. For any method on T returning some type R, the asynchronous variant will return Promise<R>. Promise<R> call(R r) calls an asynchronous service returning a Promise<R> as a handle for the result.
  9. Unfortunately there is some confusion regarding the naming. The term Promise was inherited from Javascript and refers to what in the Java is usually called a Future. See the slide about Deferred in the Appendix for more confusion.
  10. Promises let you register completion call backs, which is the low level mechanism behind a much richer combinator API (map, flatMap, filter). A Promise is similar to a Java Future but done right: promises are composable through their various combinator methods and don’t require blocking for the result. A Promise effectively establishes a happened before relation: the completion of a Promise happens before the invocation of any callbacks.
  11. A call back consists of a success and a failure part. Depending on whether the Promise resolves successfully or resolves with a failure either of both callbacks will be called.
  12. The success callback receives the successfully resolved promise. In this example it just retrieves the value and prints an according message. In general the success callback can return a chained promise, which will be used to resolve the promise returned by the then() call. That is, the promise returned by then() will resolve successfully if this promise resolve successfully and the promise returned by the success callback resolves successfully.
  13. The failure callback receives the failed promise. In this example it just prints the stack trace of the associated exception.
  14. Promises make the effects of e.g. remote calls explicit in the API signature. This is in contrast to classical RPC style, which tries to make such effects transparent and which usually does not work so well.
  15. A vendor can be asked for an offer for an item. An offer contains a reference to the vendor, the item, a price and the currency.
  16. Two (encapsulations of) currency conversions services for converting an offer in a given currency to an offer in €. The two services might be able to handle different sets of currency. So we can fall back to the other one in case the first one fails. Note that the service might also fail due to other reasons (e.g. network partition), which also is good reason for falling back to the other service.
  17. Get an offer from a vendor. The offer might be in any currency. Try to convert the offer to €. If this fails for any reason fall back to the other conversion service. Only if that one fails, fail the conversion for that item. All of this should happen entirely non blocking and decoupled from hard coded thread management: it should be possible to execute this on a single worker thread without ever blocking that thread (i.e. that thread stays available for handing other work while e.g. waiting for the vendor service to come back with an offer).
  18. Retrieve an offer for an item from the vendor. The offer might not be in the correct currency (€) though.
  19. The flatMap combinator can be used for chaining promises. Given a lambda that maps T to Promise<R> it will return Promise<R>. The return promise will fail if this promise fails or if the promise returned by the lambda fails. It will resolve successfully if both promises resolve successfully.
  20. To see how we can use flatMap in conjunction with convertToEuro1 an approach is “to work out the types”. As we call flatMap on an instance of Promise<Offer>, T must be of type Offer.
  21. As converToEuro1 returns a Promise<Offer>, we want flatMap to return that type. The lambda we pass to flatMap thus also needs to return a Promise<Offer>.
  22. This matches the convertToEuro1 signature: it maps Offer to a Promise<Offer>.
  23. Pass a lambda constructed from the convertToEuro1 function (via eta conversion) to flatMap. This version now does a first attempt at converting the offer to €. However it doesn’t fall back to a recovery service if conversion fails.
  24. The recoverWith method can be used to recover a failed Promise with another Promise. The method takes a lambda that maps the failed promise to a recovery Promise.
  25. As we want a Promise<Offer> as return type, the lambda must also map to that type.
  26. It seems that we can’t construct a lambda using convertToEuro2 as we need to pass it an Offer but we only have a Promise<?>.
  27. Turns out that we can close over the initial offer and pass this one to converToEuro2 effectively ignoring the failed argument. With this any failure encountered in convertToEuro1 will cause a fall back to convertToEuro2. Only when this also fails will the returned promise resolve with a failure. In order to make it fail gracefully we need to also recover from this.
  28. The recover method allows to recover a failed Promise with a value. The method takes a lambda that maps the failed promise to the value with which the return Promise will be resolved.
  29. As we want to return an Promise<Offer> our lambda needs to return an Offer.
  30. We simple return a constant sentinel, which signals that no offer is available. That sentinel will be returned either if getOffer fails or both conversions fail. The error is transparently chained through the calls keeping the code clean of error handling statements.
  31. Lifting all functions into the Promise allows us to make the entire calculation non blocking. At the same time errors will be chained through keeping the focus on the main code path.
  32. Making the effects of asynchronous calls explicit in the API signature (by returning a Promise<T> instead of T) allows us to cope with latency in an effective way regarding resource utilisation thereby maximising application throughput focusing on the error free path in the code while handling errors transparently. decouple parallelisation from threads leaving thread management to the environment / deployment Scale applications to run across a wide range of different hardware
  33. Promise and Deferred: like the two sides of the same door, entrance and exit. The janitor opens the door (once) for the crowd to come it (many). Unfortunately there is some confusion regarding the nomenclature. The term Deferred is inherited from the Javascript world and refers to the same that in the Java world is usually called a Promise. But a Promise in our case is already what otherwise is called a Future…