Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

RxJava, Getting Started - David Wursteisen - 16 Octobre 2014

2,328 views

Published on

Les applications sont de plus en plus interconnectées. Une architecture type WOA (Web Oriented Archiecture) et l’utilisation des micros-services nécessitent de faire de plus en plus appel à différents services web.
Comment composer un résultat à partir de ces différents services, sans avoir à ce soucier de l’ordre dans lequel les serveurs vont répondre ?
RxJava offre une manière élégante de faire de l’asynchrone et de la composition au sein de son application. David vous exposera les concepts de Rx (Reactive eXtension) avant de vous montrer une mise en application avec des exemples de code venant d’une application Android.

Published in: Technology
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

RxJava, Getting Started - David Wursteisen - 16 Octobre 2014

  1. 1. RxJava Getting Started David Wursteisen 16 Octobre 2014
  2. 2. David Wursteisen Direction Expertise Innovation @dwursteisen
  3. 3. David Wursteisen
  4. 4. Architecture distribuée Sync/Async/Concurrence
  5. 5. Architecture distribuée
  6. 6. Architecture distribuée
  7. 7. Architecture distribuée The Internet
  8. 8. Architecture distribuée The Internet
  9. 9. Synchrone
  10. 10. Synchrone Appel bloquant
  11. 11. Asynchrone
  12. 12. Asynchrone Appel non bloquant
  13. 13. Complexité
  14. 14. Complexité future.get();
  15. 15. Complexité future1.get(); future2.get(); future3.get(); future4.get(); future5.get(); future6.get(); future7.get();
  16. 16. Complexité future1.get(); future2.get(); future3.get(); future4.get(); future5.get(); future6.get(); future7.get(); Ordonnancement optimal ?
  17. 17. Complexité client.execute(new Callback() { @Override public void completed(HttpResponse response) { } });
  18. 18. Complexité client.execute(new Callback() { @Override public void completed(HttpResponse response) { client.execute(new Callback() { @Override public void completed(HttpResponse response) { } }); } });
  19. 19. Complexité client.execute(new Callback() { @Override public void completed(HttpResponse response) { client.execute(new Callback() { @Override public void completed(HttpResponse response) { client.execute(new Callback() { @Override public void completed(HttpResponse response) { } }); } });
  20. 20. Complexité client.execute(new Callback() { @Override public void completed(HttpResponse response) { client.execute(new Callback() { @Override public void completed(HttpResponse response) { client.execute(new Callback() { @Override public void completed(HttpResponse response) { } }); } }); Callback hell
  21. 21. Concurrence
  22. 22. Concurrence
  23. 23. Concurrence Concurrence
  24. 24. Concurrence
  25. 25. Concurrence RxJava permet de manipuler des évènements d’une manière synchrone et/ou asynchrone.
  26. 26. Historique Il était une fois...
  27. 27. Historique
  28. 28. Historique
  29. 29. Historique
  30. 30. Historique
  31. 31. Historique ReactiveX.io
  32. 32. Observables Travailler avec des flux
  33. 33. Flux d’évènements fini Évènements Fin du flux
  34. 34. Flux d’évènements en erreur Évènements Erreur
  35. 35. Flux d’évènements infini Évènements
  36. 36. Flux d’évènements Observable.never() Observable.empty() Observable.just(1) Observable.from(1, 2, 3) Observable.range(1, 4400) Observable.timer(5, TimeUnit.SECONDS) Observable.create(...)
  37. 37. Flux d’évènements Observable.never() Observable.empty() Observable.just(1) Observable.from(1, 2, 3) Observable.range(1, 4400) Observable.timer(5, TimeUnit.SECONDS) Observable.create(...)
  38. 38. Flux d’évènements Observable.never() Observable.empty() Observable.just(1) Observable.from(1, 2, 3) Observable.range(1, 4400) Observable.timer(5, TimeUnit.SECONDS) Observable.create(...) 1
  39. 39. Flux d’évènements Observable.never() Observable.empty() Observable.just(1) Observable.from(1, 2, 3) Observable.range(1, 4400) Observable.timer(5, TimeUnit.SECONDS) Observable.create(...) 1 2 3
  40. 40. Flux d’évènements Observable.never() Observable.empty() Observable.just(1) Observable.from(1, 2, 3) Observable.range(1, 4400) Observable.timer(5, TimeUnit.SECONDS) Observable.create(...) 1 4400
  41. 41. Flux d’évènements Observable.never() Observable.empty() Observable.just(1) Observable.from(1, 2, 3) Observable.range(1, 4400) Observable.timer(5, TimeUnit.SECONDS) Observable.create(...) 0 t t + 5 secondes
  42. 42. Flux d’évènements Observable.never() Observable.empty() Observable.just(1) Observable.from(1, 2, 3) Observable.range(1, 4400) Observable.timer(5, TimeUnit.SECONDS) Observable.create(...) A C
  43. 43. Flux d’évènements Observable<json> json json json λ ϕ φ Observable<Integer> Observable<Click>
  44. 44. Observer Push des données
  45. 45. Observer OnNext* (OnCompleted|OnError)?
  46. 46. Observer OnNext* (OnCompleted|OnError)?
  47. 47. Observer OnNext* (OnCompleted|OnError)?
  48. 48. Observer OnNext* (OnCompleted|OnError)?
  49. 49. Observer Observable.range(1, 4400)
  50. 50. Observer Observable.range(1, 4400).subscribe()
  51. 51. Observer Observable.range(1, 4400).subscribe(onNext)
  52. 52. Observer Observable.range(1, 4400).subscribe(System.out::println)
  53. 53. Observer Observable.range(1, 4400).subscribe(System.out::println, onError)
  54. 54. Observer Observable.range(1, 4400).subscribe(System.out::println, System.err::println)
  55. 55. Observer Observable.range(1, 4400).subscribe(System.out::println, System.err::println, onCompleted)
  56. 56. Observer Observable.range(1, 4400).subscribe(System.out::println, System.err::println, () -> System.out.println(“finished”))
  57. 57. Manipulation d’évènements Quand l’écoute ne suffit plus
  58. 58. Manipulation d’évènements 0 1
  59. 59. Manipulation d’évènements 0 1 map
  60. 60. Manipulation d’évènements 0 1 map A B
  61. 61. Manipulation d’évènements 1 4
  62. 62. Manipulation d’évènements 1 4 filter ( x <= 2 )
  63. 63. Manipulation d’évènements 1 4 1 filter ( x <= 2 )
  64. 64. Manipulation d’évènements 1 2
  65. 65. Manipulation d’évènements 1 2 delay ( 5, SECONDS )
  66. 66. Manipulation d’évènements 1 2 delay ( 5, SECONDS ) 1 2
  67. 67. Manipulation d’évènements Observable.from(0, 1, 2, 3, 4) Observable<Integer>
  68. 68. Manipulation d’évènements Observable.from(0, 1, 2, 3, 4) .filter((i) -> i < 3) Observable<Integer> Observable<Integer>
  69. 69. Manipulation d’évènements Observable.from(0, 1, 2, 3, 4) .filter((i) -> i < 3) .delay(5, TimeUnit.SECONDS) Observable<Integer> Observable<Integer> Observable<Integer>
  70. 70. Manipulation d’évènements Observable.from(0, 1, 2, 3, 4) .filter((i) -> i < 3) .delay(5, TimeUnit.SECONDS) .map((i) -> Character.toString((char)(i + 'A'))) Observable<Integer> Observable<Integer> Observable<Integer> Observable<String>
  71. 71. Manipulation d’évènements Observable.from(0, 1, 2, 3, 4) .filter((i) -> i < 3) .delay(5, TimeUnit.SECONDS) .map((i) -> Character.toString((char)(i + 'A'))) .subscribe(System.out::println); Observable<Integer> Observable<Integer> Observable<Integer> Observable<String>
  72. 72. Manipulation d’évènements Observable.from(0, 1, 2, 3, 4) .filter((i) -> i < 3) .delay(5, TimeUnit.SECONDS) .map((i) -> Character.toString((char)(i + 'A'))) .subscribe(System.out::println); 0, 1, 2, 3, 4 => A, B, C Observable<Integer> Observable<Integer> Observable<Integer> Observable<String>
  73. 73. Manipulation d’évènements
  74. 74. Manipulation d’évènements
  75. 75. Manipulation d’évènements
  76. 76. Composition Création d’un flux à partir d’un ensemble de flux
  77. 77. Composition
  78. 78. Composition
  79. 79. Composition
  80. 80. Mise en pratique de composition Learn from the trenches
  81. 81. Composition
  82. 82. Composition
  83. 83. Composition
  84. 84. Composition
  85. 85. Composition
  86. 86. Composition merge
  87. 87. Composition merge
  88. 88. Composition
  89. 89. Composition
  90. 90. Composition zip
  91. 91. Composition zip
  92. 92. Subscription Et gestion de l’unsubscribe
  93. 93. Subscription Observable.create(new OnSubscribe<T>() { … });
  94. 94. Subscription Observable.create(new OnSubscribe<T>() { @Override public void call(Subscriber<? super T> s) { s.onNext(123); s.onCompleted(); } });
  95. 95. Subscription Observable.create(new OnSubscribe<T>() { @Override public void call(Subscriber<? super T> s) { s.onNext(123); s.onCompleted(); } }); Émission synchronne
  96. 96. Subscription Observable.create(new OnSubscribe<T>() { @Override public void call(Subscriber<? super T> subscriber) { // ... httpClient.execute(httpRequest, new FutureCallback<HttpResponse>() { @Override public void completed(String content) { subscriber.onNext(content); subscriber.onCompleted(); } @Override public void failed(Exception e) { subscriber.onError(e); } }); } });
  97. 97. Subscription Observable.create(new OnSubscribe<T>() { @Override public void call(Subscriber<? super T> subscriber) { // ... httpClient.execute(httpRequest, new FutureCallback<HttpResponse>() { @Override public void completed(String content) { subscriber.onNext(content); subscriber.onCompleted(); } @Override public void failed(Exception e) { subscriber.onError(e); } }); } });
  98. 98. Subscription Observable.create(new OnSubscribe<T>() { @Override public void call(Subscriber<? super T> subscriber) { // ... httpClient.execute(httpRequest, new FutureCallback<HttpResponse>() { @Override public void completed(String content) { subscriber.onNext(content); subscriber.onCompleted(); } @Override public void failed(Exception e) { subscriber.onError(e); } }); } });
  99. 99. Subscription Observable.create(new OnSubscribe<T>() { @Override public void call(Subscriber<? super T> subscriber) { // ... httpClient.execute(httpRequest, new FutureCallback<HttpResponse>() { @Override public void completed(String content) { subscriber.onNext(content); subscriber.onCompleted(); } @Override public void failed(Exception e) { subscriber.onError(e); } }); } }); Émission asynchronne
  100. 100. Subscription Observable.create(new OnSubscribe<T>() { @Override public void call(Subscriber<? super T> subscriber) { // ... httpClient.execute(httpRequest, new FutureCallback<HttpResponse>() { @Override public void completed(String content) { subscriber.onNext(content); subscriber.onCompleted(); } @Override public void failed(Exception e) { subscriber.onError(e); } }); } }); Propagation des erreurs
  101. 101. Subscription La souscription permet d’uniformiser des API différentes par leurs natures (Callback, etc...)
  102. 102. Unsubscribe Subscription subscription = Observable.interval(1, TimeUnit.SECONDS).subscribe();
  103. 103. Unsubscribe Souscription Subscription subscription = Observable.interval(1, TimeUnit.SECONDS).subscribe();
  104. 104. Unsubscribe Handler sur la souscription Subscription subscription = Observable.interval(1, TimeUnit.SECONDS).subscribe();
  105. 105. Unsubscribe Subscription subscription = Observable.interval(1, TimeUnit.SECONDS).subscribe(); /* ... */ subscription.unsubscribe();
  106. 106. Unsubscribe Subscription subscription = Observable.interval(1, TimeUnit.SECONDS).subscribe(); /* ... */ subscription.unsubscribe(); Arrêt de la souscription
  107. 107. Schedulers
  108. 108. Schedulers observableReadingSynchronously(“strings.txt”) .take(10) .delay(1, SECONDS) .map(parse()) .map(n -> “=> ” + n)) .subscribe(to_the_view())
  109. 109. Schedulers main
  110. 110. Schedulers observableReadingSynchronously(“strings.txt”) .take(10) .delay(1, SECONDS) .map(parse()) .map(n -> “=> ” + n)) .subscribe(to_the_view())
  111. 111. Schedulers main IO Computation UI
  112. 112. Schedulers main IO Computation UI
  113. 113. Schedulers main IO Computation UI
  114. 114. Schedulers main IO Computation UI
  115. 115. Schedulers main IO Computation UI
  116. 116. Schedulers main IO Computation UI
  117. 117. Schedulers observableReadingSynchronously(“strings.txt”) .subscribeOn(scheduler) .take(10) .delay(1, SECONDS, scheduler) .map(parse()) .observeOn(scheduler) .map(n -> “=> ” + n)) .subscribe(to_the_view())
  118. 118. Schedulers observableReadingSynchronously(“strings.txt”) .subscribeOn(Schedulers.io()) .take(10) .delay(1, SECONDS, Schedulers.computation()) .map(parse()) .observeOn(Schedulers.from(uiExecutor())) .map(n -> “=> ” + n)) .subscribe(to_the_view())
  119. 119. Schedulers Computation UI
  120. 120. Schedulers Computation UI
  121. 121. Schedulers Computation UI
  122. 122. Schedulers Computation UI
  123. 123. Schedulers Computation UI
  124. 124. Hot & Cold Observable
  125. 125. Cold Observable Observable<Integer> obs = Observable.from(1, 2, 3, 4); obs.subscribe(System.out::println); obs.subscribe(System.out::println);
  126. 126. Cold Observable Observable<Integer> obs = Observable.from(1, 2, 3, 4); obs.subscribe(System.out::println); obs.subscribe(System.out::println);
  127. 127. Cold Observable Observable<Integer> obs = Observable.from(1, 2, 3, 4); obs.subscribe(System.out::println); Subscribe obs.subscribe(System.out::println);
  128. 128. Cold Observable Observable<Integer> obs = Observable.from(1, 2, 3, 4); obs.subscribe(System.out::println); obs.subscribe(System.out::println); Subscribe
  129. 129. Cold Observable Observable<Integer> obs = Observable.from(1, 2, 3, 4); obs.subscribe(System.out::println); obs.subscribe(System.out::println); Souscription différente
  130. 130. Hot Observable ConnectableObservable<Integer> obs = Observable.from(1, 2, 3, 4).publish(); obs.subscribe(System.out::println); obs.subscribe(System.out::println); obs.connect();
  131. 131. Hot Observable ConnectableObservable<Integer> obs = Observable.from(1, 2, 3, 4).publish(); obs.subscribe(System.out::println); obs.subscribe(System.out::println); obs.connect();
  132. 132. Hot Observable ConnectableObservable<Integer> obs = Observable.from(1, 2, 3, 4).publish(); obs.subscribe(System.out::println); obs.subscribe(System.out::println); obs.connect();
  133. 133. Hot Observable ConnectableObservable<Integer> obs = Observable.from(1, 2, 3, 4).publish(); obs.subscribe(System.out::println); obs.subscribe(System.out::println); obs.connect();
  134. 134. Hot Observable ConnectableObservable<Integer> obs = Observable.from(1, 2, 3, 4).publish(); obs.subscribe(System.out::println); obs.subscribe(System.out::println); obs.connect();
  135. 135. Hot Observable ConnectableObservable<Integer> obs = Observable.from(1, 2, 3, 4).publish(); obs.subscribe(System.out::println); obs.subscribe(System.out::println); Subscribe obs.connect();
  136. 136. Hot Observable ConnectableObservable<Integer> obs = Observable.from(1, 2, 3, 4).publish(); obs.subscribe(System.out::println); obs.subscribe(System.out::println); obs.connect(); Partage la même souscription
  137. 137. Hot Observable ConnectableObservable<Integer> obs = Observable.from(1, 2, 3, 4).publish(); obs.subscribe(System.out::println); obs.subscribe(System.out::println); obs.connect();
  138. 138. Hot Observable ConnectableObservable<Integer> obs = Observable.from(1, 2, 3, 4).publish(); obs.connect(); Souscription obs.subscribe(System.out::println); obs.subscribe(System.out::println);
  139. 139. Cold & Hot Observable Cold Observable = flux passif Hot Observable = flux actif
  140. 140. Back Pressure Contrôler la production
  141. 141. Back Pressure Production
  142. 142. Back Pressure Production buffer
  143. 143. Back Pressure Production Pression arrière
  144. 144. Back Pressure Demande de production de n élements Production Pression arrière
  145. 145. Retour d’expérience
  146. 146. Opérateurs Observable.from(1, 2, 3, 4) .reduce(new LinkedList<Integer>(), (seed, value) -> { seed.add(value); return seed; }) .first() .subscribe(System.out::println);
  147. 147. Opérateurs Observable.from(1, 2, 3, 4) .reduce(new LinkedList<Integer>(), (seed, value) -> { seed.add(value); return seed; }) .first() .subscribe(System.out::println);
  148. 148. Opérateurs Observable.from(1, 2, 3, 4) .toList() .first() .subscribe(System.out::println);
  149. 149. Opérateurs Observable.from(1, 2, 3, 4) .toList() .first() .subscribe(System.out::println);
  150. 150. Opérateurs Observable.from(1, 2, 3, 4) .toList() .first() .subscribe(System.out::println); Différence entre first() / single() / take(1) ?
  151. 151. Gestion des erreurs Observable.from(1, 2, 3, 4) .toList() .single() .subscribe(System.out::println);
  152. 152. Gestion des erreurs Observable.from(1, 2, 3, 4) .toList() .single() .subscribe(System.out::println); Notification des erreurs absentes
  153. 153. Gestion des erreurs static { RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() { @Override public void handleError(Throwable e) { e.printStackTrace(); } }); }
  154. 154. Lambda & Java 8 Observable.from(1, 2, 3, 4) .filter(new Func1<Integer, Boolean>() { @Override public Boolean call(Integer i) { return i > 3; } }) .subscribe(new Action1<Integer>() { @Override public void call(Integer x) { System.out.println(x); } });
  155. 155. Lambda & Java 8 Observable.from(1, 2, 3, 4) .filter(new Func1<Integer, Boolean>() { @Override public Boolean call(Integer i) { return i > 3; } }) .subscribe(new Action1<Integer>() { @Override public void call(Integer x) { System.out.println(x); } }); Bruit
  156. 156. Lambda & Java 8 Observable.from(1, 2, 3, 4) .filter(i -> i > 3) .subscribe(System.out::println);
  157. 157. Lambda & Java 8 Observable.from(1, 2, 3, 4) .filter(new Func1<Integer, Boolean>() { @Override public Boolean call(Integer i) { return i > 3; } }) .subscribe(new Action1<Integer>() { @Override public void call(Integer x) { System.out.println(x); } }); Observable.from(1, 2, 3, 4) .filter(i -> i > 3) .subscribe(System.out::println); Retrolambda
  158. 158. Concurrence obs1.mergeWith(obs2) .take(5) .subscribe(System.out::println);
  159. 159. Concurrence obs1.mergeWith(obs2) .take(5) .subscribe(System.out::println);
  160. 160. Concurrence obs1.mergeWith(obs2) Doit gérer la concurrence .take(5) .subscribe(System.out::println);
  161. 161. Concurrence obs1.mergeWith(obs2) .take(5) .subscribe(System.out::println);
  162. 162. Concurrence obs1.mergeWith(obs2) .take(5) .subscribe(System.out::println); non concurrence
  163. 163. Sync & Async Observable<Integer> generator();
  164. 164. Sync & Async Observable<Integer> generator(); Sync ?
  165. 165. Sync & Async Sync ? Async ? Observable<Integer> generator();
  166. 166. Sync & Async Sync ? Async ? Observable<Integer> generator(); Computation ?
  167. 167. Sync & Async Sync ? Async ? Observable<Integer> generator(); Computation ? Acteur ?
  168. 168. “Leak” des Observables everything is an event
  169. 169. “Leak” des Observables ViewPager
  170. 170. “Leak” des Observables ViewPager Observable Preferences
  171. 171. “Leak” des Observables ViewPager Observable Preferences Observable UserService
  172. 172. Future<RxJava>
  173. 173. Future<RxJava> Support RxJava
  174. 174. Reactive Streams
  175. 175. Reactive Streams Reactive Streams is an initiative to provide a standard for asynchronous stream processing with non-blocking back pressure on the JVM. http://www.reactive-streams.org/
  176. 176. Reactive Streams RxJava | Akka Streams | Reactor Composable | Ratpack
  177. 177. Reactive Streams RxJava | Akka Streams | Reactor Composable | Ratpack > 700 Ko | Java | Android
  178. 178. Reactive Streams RxJava | Akka Streams | Reactor Composable | Ratpack > 2.5 Mo | Scala | Akka
  179. 179. Reactive Streams RxJava | Akka Streams | Reactor Composable | Ratpack ~1Mo | Java | RingBufferDispatcher
  180. 180. Reactive Streams RxJava | Akka Streams | Reactor Composable | Ratpack Java 8 | Http
  181. 181. Si il ne fallait retenir qu’une chose
  182. 182. Si il ne fallait retenir qu’une chose RxJava est un modèle de programmation pour écrire des applications asynchrones Frontend | Backend | Crossplatform
  183. 183. Questions ? david.wursteisen@soat.fr @dwursteisen

×