Nowadays users expect real time data - tweets, messages, order confirmations etc. - the user's attitude moved to the “push" model and it is high time for us devs to make that step as well.
Reactive Extensions (Rx) is the new hot stuff amongst developers these days. It is a library for composing asynchronous and event-based programs by using observable sequences. Sounds nice?
The only problem is that it can be a bit difficult to approach initially, especially when you come from an imperative world, but once mastered it helps dealing with some common problems in a nicer and cleaner way making your code more readable and easier to maintain.
Multiple implementations of Reactive Extensions helps reusing once learnt concepts between different programming languages. The aim of this talk is to provide a quick introduction to Rx theory and potential usecases. The examples are based on RxJava - the Java VM implementation of Reactive Extensions.
A presentation given to Overstock.com IT at annual conference. Twitter @TECHknO 2015. Goal of the presentation is to provide a good introduction to the reactive programming model with RxJava.
A practical guide to using RxJava on Android. Tips for improving your app architecture with reactive programming. What are the advantages and disadvantages of using RxJava over standard architecture? And how to connect with other popular Android libraries?
Presented at GDG DevFest The Netherlands 2016.
For most of us, Reactive Android means using RxJava. In this presentation, I try to borrow a few ideas from the backend world and enrich the concept of Reactive in Android.
Building Scalable Stateless Applications with RxJavaRick Warren
RxJava is a lightweight open-source library, originally from Netflix, that makes it easy to compose asynchronous data sources and operations. This presentation is a high-level intro to this library and how it can fit into your application.
A presentation given to Overstock.com IT at annual conference. Twitter @TECHknO 2015. Goal of the presentation is to provide a good introduction to the reactive programming model with RxJava.
A practical guide to using RxJava on Android. Tips for improving your app architecture with reactive programming. What are the advantages and disadvantages of using RxJava over standard architecture? And how to connect with other popular Android libraries?
Presented at GDG DevFest The Netherlands 2016.
For most of us, Reactive Android means using RxJava. In this presentation, I try to borrow a few ideas from the backend world and enrich the concept of Reactive in Android.
Building Scalable Stateless Applications with RxJavaRick Warren
RxJava is a lightweight open-source library, originally from Netflix, that makes it easy to compose asynchronous data sources and operations. This presentation is a high-level intro to this library and how it can fit into your application.
Reactive Programming on Android - RxAndroid - RxJavaAli Muzaffar
Introduction to RxJava for reactive programming and how to use RxAndroid to do reactive programming on Android.
There is a sample android app to go with the slides that has all the source shown in the project.
An exploration into RxJava on Android for the experienced, yet uninitiated software engineer. This presentation explores Declarative vs Imperative programming paradigms and expands the discussion into Functional Reactive Programming. It explains the benefits of the observer contract, high-order functions, and schedulers available in RxJava. It also explains the purpose of the Android integration libraries: RxAndroid, RxLifecycle, and RxBindings.
RxJava maakt het mogelijk om gemakkelijk schaalbare code op een reactive manier te schrijven. Het kan echter ook een uitdaging zijn om de code leesbaar te maken, en kunnen debuggen wat er gebeurt. Deze sessie beschrijft onze ervaringen met het inzetten van RxJava als basis-onderdeel in onze codebase: een suite educatieve applicaties voor basis-, voortgezet- en beroepsonderwijs, grootschalig ingezet in vijf landen. Ruim tien agile teams werken samen aan deze op micro-services gebaseerde suite. RxJava heeft ons belangrijke voordelen gebracht. De introductie van dit nieuwe framework gaf ons ook verschillende verwachte uitdagingen en een paar interessante verrassingen. Deze sessie gaat in op de lessons learned en valkuilen waar je rekening mee kunt houden als je start met RxJava. Onder andere de volgende onderwerpen worden besproken: introduceren RxJava in bestaande codebase, stappen om als team RxJava te leren, hoe je een aantal standaard workflows effectief in RxJava kunt programmeren, foutafhandeling en debugging. Daarnaast wordt besproken hoe je RxJava kunt combineren met Java EE en Spring, en wat de voordelen kunnen zijn van RxJava in een enterprise applicatie.
Intro to RxJava/RxAndroid - GDG Munich AndroidEgor Andreevich
The RX libraries have gained great popularity among developers lately. RX solves asynchronous programming elegantly based on the Observer pattern. This is especially helpful on Android where lots of interactions are asynchronous to the UI. Speaker: Egor Andreevici
Reactive Streams: Handling Data-Flow the Reactive WayRoland Kuhn
Building on the success of Reactive Extensions—first in Rx.NET and now in RxJava—we are taking Observers and Observables to the next level: by adding the capability of handling back-pressure between asynchronous execution stages we enable the distribution of stream processing across a cluster of potentially thousands of nodes. The project defines the common interfaces for interoperable stream implementations on the JVM and is the result of a collaboration between Twitter, Netflix, Pivotal, RedHat and Typesafe. In this presentation I introduce the guiding principles behind its design and show examples using the actor-based implementation in Akka.
Video and slides synchronized, mp3 and slide download available at URL http://bit.ly/1DXFg0h.
Ben Christensen summarizes why the Rx programming model was chosen and demonstrates how it is applied to a variety of use cases. Filmed at qconsf.com.
Ben Christensen is a software engineer on the Netflix Edge Services Platform team responsible for fault tolerance, performance, architecture and scale while enabling millions of customers to access the Netflix experience across more than 1,000 different device types.
Reactive Programming on Android - RxAndroid - RxJavaAli Muzaffar
Introduction to RxJava for reactive programming and how to use RxAndroid to do reactive programming on Android.
There is a sample android app to go with the slides that has all the source shown in the project.
An exploration into RxJava on Android for the experienced, yet uninitiated software engineer. This presentation explores Declarative vs Imperative programming paradigms and expands the discussion into Functional Reactive Programming. It explains the benefits of the observer contract, high-order functions, and schedulers available in RxJava. It also explains the purpose of the Android integration libraries: RxAndroid, RxLifecycle, and RxBindings.
RxJava maakt het mogelijk om gemakkelijk schaalbare code op een reactive manier te schrijven. Het kan echter ook een uitdaging zijn om de code leesbaar te maken, en kunnen debuggen wat er gebeurt. Deze sessie beschrijft onze ervaringen met het inzetten van RxJava als basis-onderdeel in onze codebase: een suite educatieve applicaties voor basis-, voortgezet- en beroepsonderwijs, grootschalig ingezet in vijf landen. Ruim tien agile teams werken samen aan deze op micro-services gebaseerde suite. RxJava heeft ons belangrijke voordelen gebracht. De introductie van dit nieuwe framework gaf ons ook verschillende verwachte uitdagingen en een paar interessante verrassingen. Deze sessie gaat in op de lessons learned en valkuilen waar je rekening mee kunt houden als je start met RxJava. Onder andere de volgende onderwerpen worden besproken: introduceren RxJava in bestaande codebase, stappen om als team RxJava te leren, hoe je een aantal standaard workflows effectief in RxJava kunt programmeren, foutafhandeling en debugging. Daarnaast wordt besproken hoe je RxJava kunt combineren met Java EE en Spring, en wat de voordelen kunnen zijn van RxJava in een enterprise applicatie.
Intro to RxJava/RxAndroid - GDG Munich AndroidEgor Andreevich
The RX libraries have gained great popularity among developers lately. RX solves asynchronous programming elegantly based on the Observer pattern. This is especially helpful on Android where lots of interactions are asynchronous to the UI. Speaker: Egor Andreevici
Reactive Streams: Handling Data-Flow the Reactive WayRoland Kuhn
Building on the success of Reactive Extensions—first in Rx.NET and now in RxJava—we are taking Observers and Observables to the next level: by adding the capability of handling back-pressure between asynchronous execution stages we enable the distribution of stream processing across a cluster of potentially thousands of nodes. The project defines the common interfaces for interoperable stream implementations on the JVM and is the result of a collaboration between Twitter, Netflix, Pivotal, RedHat and Typesafe. In this presentation I introduce the guiding principles behind its design and show examples using the actor-based implementation in Akka.
Video and slides synchronized, mp3 and slide download available at URL http://bit.ly/1DXFg0h.
Ben Christensen summarizes why the Rx programming model was chosen and demonstrates how it is applied to a variety of use cases. Filmed at qconsf.com.
Ben Christensen is a software engineer on the Netflix Edge Services Platform team responsible for fault tolerance, performance, architecture and scale while enabling millions of customers to access the Netflix experience across more than 1,000 different device types.
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!Masoud Kalali
This session focuses on how Java EE 7 provides extensive set of new and enhanced features to support standards like HTML5, WebSockets, and Server Sent Events among others.In this session we will show how these new features are designed and matched to work together for developing lightweight solutions matching end users high expectation from a web application’s responsiveness. The session will cover best practices and design patterns governing application development using JAX-RS 2.0, Async Servlet, and JSON-P (among others) as well as iterating over the pitfalls that should be avoided. During the session we will show code snippets and block diagrams that clarify use of APIs coming from the demo application we will show at the end.
This Presentation talks about various aspects of managing the Activity Backstack.
Please note this was prepared last year but most of the concepts are still relevant
Akka-demy (a.k.a. How to build stateful distributed systems) I/IIPeter Csala
This is the first part of a mini-series where we discuss how to build distributed stateful real-time applications using actor model and messaging.
The second part: https://www.slideshare.net/PeterCsala/akkademy-aka-how-to-build-stateful-distributed-systems-iiii
Mary Grygleski and myself, gave a very successful workshop to 51 attendees in NYC on April 15th - here is the updated presentation
https://www.linkedin.com/in/mary-grygleski/
https://www.linkedin.com/in/grant-steinfeld/
Everyone in the Scala world is using or looking into using Akka for low-latency, scalable, distributed or concurrent systems. I'd like to share my story of developing and productionizing multiple Akka apps, including low-latency ingestion and real-time processing systems, and Spark-based applications.
When does one use actors vs futures?
Can we use Akka with, or in place of, Storm?
How did we set up instrumentation and monitoring in production?
How does one use VisualVM to debug Akka apps in production?
What happens if the mailbox gets full?
What is our Akka stack like?
I will share best practices for building Akka and Scala apps, pitfalls and things we'd like to avoid, and a vision of where we would like to go for ideal Akka monitoring, instrumentation, and debugging facilities. Plus backpressure and at-least-once processing.
RxJS in Angular 2
1. Quick overview of progress on RxJS Next (now RxJS 5)
2. Comparing Promises with Observables, and talking about why Observables are a better choice for Single Page Applications, like those written with Angular
3. Show the anatomy of an Observable
4. Talk about what Operators are
5. Show an example of reconnecting a multiplexed Web Socket using Observables in Angular 2.
Докладчик расскажет о технических аспектах разработки с нуля прототипа межсетевого экрана уровня систем управления базами данных Database Firewall: о том, что нужно чтобы разработать DBFW, о возможности применения методов машинного обучения для эффективного обнаружения SQL-инъекций по SQL-запросам, обнаружении SQL-инъекций на основе методов синтаксического анализа, реализации ролевого и атрибутного управление доступом. Также речь пойдет о перспективных механизмах защиты приложений на основе технологий межсетевого экранирования и статического анализа кода.
Reactive Programming, Traits and Principles. What is Reactive, where does it come from, and what is it good for? How does it differ from event driven programming? It only functional?
Introduction to React-Native
- Difference between React & ReactNative
- Why one should use ReactNative?
- Basic Components
- Life Cycle of Component
- Environment Setup
Monitoring Big Data Systems Done "The Simple Way" - Demi Ben-Ari - Codemotion...Codemotion
Once you start working with Big Data systems, you discover a whole bunch of problems you won’t find in monolithic systems. Monitoring all of the components becomes a big data problem itself. In the talk, we’ll mention all of the aspects that you should take into consideration when monitoring a distributed system using tools like Web Services, Spark, Cassandra, MongoDB, AWS. Not only the tools, what should you monitor about the actual data that flows in the system? We’ll cover the simplest solution with your day to day open source tools, the surprising thing, that it comes not from an Ops Guy.
Monitoring Big Data Systems "Done the simple way" - Demi Ben-Ari - Codemotion...Demi Ben-Ari
Once you start working with distributed Big Data systems, you start discovering a whole bunch of problems you won’t find in monolithic systems.
All of a sudden to monitor all of the components becomes a big data problem itself.
In the talk we’ll mention all of the aspects that you should take in consideration when monitoring a distributed system once you’re using tools like:
Web Services, Apache Spark, Cassandra, MongoDB, Amazon Web Services.
Not only the tools, what should you monitor about the actual data that flows in the system?
And we’ll cover the simplest solution with your day to day open source tools, the surprising thing, that it comes not from an Ops Guy.
The Internet is asynchronous, people are asynchronous, the universe is asynchronous. They are now and they always will be. Writing applications which deal correctly with asynchronous data is difficult. Or at least it was. Microsoft open sourced ReactiveX in 2010 to make what used to be some of the hairiest kinds of coding almost easy.
The project was so well received that it has been ported to nearly every major programming language. Versions of ReactiveX exists for .NET, JavaScript, Java, Scala, Clojure, C++, Ruby, Python, Groovy, JRuby, Kotlin, and Swift. The project is open source and community maintain with corporate backing from the likes of Microsoft and Netflix.
Microsoft created the ReactiveX, then called reactive extensions, from the burnt out remains of Project Volta. Project Volta's goal was to extend .NET's to run both on the server and in the browser. A compiler would decide which parts were best to put where. It essentially was the Meteor framework in 2007.
In this talk we will take a deep look at ReactiveX. We will use code samples to show how things are done before and after ReactiveX. The code will be in C# and JavaScript. We will see how ReactiveX makes our lives as developers easier and our code more reactive.
Video and slides synchronized, mp3 and slide download available at URL http://bit.ly/1nyhaC6.
Nathan Marz discusses building NoSQL-based data systems that are scalable and easy to reason about. Filmed at qconlondon.com.
Nathan Marz is the creator of many open source projects which are relied upon by over 50 companies around the world, including Cascalog and Storm. Nathan is also working on a book for Manning publications entitled "Big Data: principles and best practices of scalable realtime data systems". Nathan was previously the lead engineer at BackType before being acquired by Twitter in 2011.
Similar to Streams, Streams Everywhere! An Introduction to Rx (20)
Cyaniclab : Software Development Agency Portfolio.pdfCyanic lab
CyanicLab, an offshore custom software development company based in Sweden,India, Finland, is your go-to partner for startup development and innovative web design solutions. Our expert team specializes in crafting cutting-edge software tailored to meet the unique needs of startups and established enterprises alike. From conceptualization to execution, we offer comprehensive services including web and mobile app development, UI/UX design, and ongoing software maintenance. Ready to elevate your business? Contact CyanicLab today and let us propel your vision to success with our top-notch IT solutions.
Unleash Unlimited Potential with One-Time Purchase
BoxLang is more than just a language; it's a community. By choosing a Visionary License, you're not just investing in your success, you're actively contributing to the ongoing development and support of BoxLang.
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamtakuyayamamoto1800
In this slide, we show the simulation example and the way to compile this solver.
In this solver, the Helmholtz equation can be solved by helmholtzFoam. Also, the Helmholtz equation with uniformly dispersed bubbles can be simulated by helmholtzBubbleFoam.
Utilocate offers a comprehensive solution for locate ticket management by automating and streamlining the entire process. By integrating with Geospatial Information Systems (GIS), it provides accurate mapping and visualization of utility locations, enhancing decision-making and reducing the risk of errors. The system's advanced data analytics tools help identify trends, predict potential issues, and optimize resource allocation, making the locate ticket management process smarter and more efficient. Additionally, automated ticket management ensures consistency and reduces human error, while real-time notifications keep all relevant personnel informed and ready to respond promptly.
The system's ability to streamline workflows and automate ticket routing significantly reduces the time taken to process each ticket, making the process faster and more efficient. Mobile access allows field technicians to update ticket information on the go, ensuring that the latest information is always available and accelerating the locate process. Overall, Utilocate not only enhances the efficiency and accuracy of locate ticket management but also improves safety by minimizing the risk of utility damage through precise and timely locates.
May Marketo Masterclass, London MUG May 22 2024.pdfAdele Miller
Can't make Adobe Summit in Vegas? No sweat because the EMEA Marketo Engage Champions are coming to London to share their Summit sessions, insights and more!
This is a MUG with a twist you don't want to miss.
Software Engineering, Software Consulting, Tech Lead.
Spring Boot, Spring Cloud, Spring Core, Spring JDBC, Spring Security,
Spring Transaction, Spring MVC,
Log4j, REST/SOAP WEB-SERVICES.
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Mind IT Systems
Healthcare providers often struggle with the complexities of chronic conditions and remote patient monitoring, as each patient requires personalized care and ongoing monitoring. Off-the-shelf solutions may not meet these diverse needs, leading to inefficiencies and gaps in care. It’s here, custom healthcare software offers a tailored solution, ensuring improved care and effectiveness.
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Globus
The U.S. Geological Survey (USGS) has made substantial investments in meeting evolving scientific, technical, and policy driven demands on storing, managing, and delivering data. As these demands continue to grow in complexity and scale, the USGS must continue to explore innovative solutions to improve its management, curation, sharing, delivering, and preservation approaches for large-scale research data. Supporting these needs, the USGS has partnered with the University of Chicago-Globus to research and develop advanced repository components and workflows leveraging its current investment in Globus. The primary outcome of this partnership includes the development of a prototype enterprise repository, driven by USGS Data Release requirements, through exploration and implementation of the entire suite of the Globus platform offerings, including Globus Flow, Globus Auth, Globus Transfer, and Globus Search. This presentation will provide insights into this research partnership, introduce the unique requirements and challenges being addressed and provide relevant project progress.
Software Engineering, Software Consulting, Tech Lead, Spring Boot, Spring Cloud, Spring Core, Spring JDBC, Spring Transaction, Spring MVC, OpenShift Cloud Platform, Kafka, REST, SOAP, LLD & HLD.
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus
As part of the DOE Integrated Research Infrastructure (IRI) program, NERSC at Lawrence Berkeley National Lab and ALCF at Argonne National Lab are working closely with General Atomics on accelerating the computing requirements of the DIII-D experiment. As part of the work the team is investigating ways to speedup the time to solution for many different parts of the DIII-D workflow including how they run jobs on HPC systems. One of these routes is looking at Globus Compute as a way to replace the current method for managing tasks and we describe a brief proof of concept showing how Globus Compute could help to schedule jobs and be a tool to connect compute at different facilities.
Listen to the keynote address and hear about the latest developments from Rachana Ananthakrishnan and Ian Foster who review the updates to the Globus Platform and Service, and the relevance of Globus to the scientific community as an automation platform to accelerate scientific discovery.
Enhancing Research Orchestration Capabilities at ORNL.pdfGlobus
Cross-facility research orchestration comes with ever-changing constraints regarding the availability and suitability of various compute and data resources. In short, a flexible data and processing fabric is needed to enable the dynamic redirection of data and compute tasks throughout the lifecycle of an experiment. In this talk, we illustrate how we easily leveraged Globus services to instrument the ACE research testbed at the Oak Ridge Leadership Computing Facility with flexible data and task orchestration capabilities.
Developing Distributed High-performance Computing Capabilities of an Open Sci...Globus
COVID-19 had an unprecedented impact on scientific collaboration. The pandemic and its broad response from the scientific community has forged new relationships among public health practitioners, mathematical modelers, and scientific computing specialists, while revealing critical gaps in exploiting advanced computing systems to support urgent decision making. Informed by our team’s work in applying high-performance computing in support of public health decision makers during the COVID-19 pandemic, we present how Globus technologies are enabling the development of an open science platform for robust epidemic analysis, with the goal of collaborative, secure, distributed, on-demand, and fast time-to-solution analyses to support public health.
Essentials of Automations: The Art of Triggers and Actions in FMESafe Software
In this second installment of our Essentials of Automations webinar series, we’ll explore the landscape of triggers and actions, guiding you through the nuances of authoring and adapting workspaces for seamless automations. Gain an understanding of the full spectrum of triggers and actions available in FME, empowering you to enhance your workspaces for efficient automation.
We’ll kick things off by showcasing the most commonly used event-based triggers, introducing you to various automation workflows like manual triggers, schedules, directory watchers, and more. Plus, see how these elements play out in real scenarios.
Whether you’re tweaking your current setup or building from the ground up, this session will arm you with the tools and insights needed to transform your FME usage into a powerhouse of productivity. Join us to discover effective strategies that simplify complex processes, enhancing your productivity and transforming your data management practices with FME. Let’s turn complexity into clarity and make your workspaces work wonders!
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Globus
The Earth System Grid Federation (ESGF) is a global network of data servers that archives and distributes the planet’s largest collection of Earth system model output for thousands of climate and environmental scientists worldwide. Many of these petabyte-scale data archives are located in proximity to large high-performance computing (HPC) or cloud computing resources, but the primary workflow for data users consists of transferring data, and applying computations on a different system. As a part of the ESGF 2.0 US project (funded by the United States Department of Energy Office of Science), we developed pre-defined data workflows, which can be run on-demand, capable of applying many data reduction and data analysis to the large ESGF data archives, transferring only the resultant analysis (ex. visualizations, smaller data files). In this talk, we will showcase a few of these workflows, highlighting how Globus Flows can be used for petabyte-scale climate analysis.
3. “Reactive” presentation plan *stream
5
4
1
2
3
Observable
Observer
Q&A
Tips and resources
Rx in example
Rx 101 with RxJava
Why going Reactive?
4. 1
Why going Reactive?
• Users expect real time data
• No-one wants to be blocked waiting for results
• When working with results sets it is better to start
processing individual results when they are ready
• The world has moved to push data model
• Async programming is very important but at the
same time it’s often difficult and error-prone
Some driving factors:
5. 1
Why going Reactive?
• A buzz word
• Pronunciation: /rɪˈaktɪv/
• “Showing a response to a stimulus.”
• “Acting in response to a situation rather than
creating or controlling it.”
Reactive:
6. 1
Why going Reactive?
• Responsive:
The system responds in a timely manner if at all possible
• Resilient:
The system stays responsive in the face of failure
• Elastic:
The system stays responsive under varying workload
• Message Driven:
Reactive Systems rely on asynchronous message-passing
www.reactivemanifesto.org
Reactive manifesto:
9. 1
Why going Reactive?
• RP: a paradigm oriented around asynchronous
data flows and the propagation of change
• Basically:
• Reactive model is Push rather than Pull
• Programming with async data sequences
• Discrete values emitted over time
• It’s not “Functional Reactive Programming”!
Reactive Programming:
10. 1
Why going Reactive?
• Rx stands for Reactive Extensions
• “A library for composing asynchronous and event-
based programs by using observable sequences.”
• Created by Erik Meijer (Microsoft) for the .NET
• Version 1.0 released 17/11/2009
• Version 2.0 released 15/08/2012
• Ported to different languages thereafter
ReactiveX:
11. 1
Why going Reactive?
• Provides a collection of operators
• Observer pattern “on steroids”:
• Support sequences of data and/or events
• Compose sequences using declarative way
• Abstract away concerns about low-level stuff
• Concurrent data structures and non-blocking I/O
• Threading and Thread Safety
ReactiveX:
12. 1
Why going Reactive?
Accessing sequences of data:
single items multiple items
sync T getData() Iterable<T> getData()
async Future<T> getData()
13. 1
Why going Reactive?
Accessing sequences of data:
single items multiple items
sync T getData() Iterable<T> getData()
async Future<T> getData() Observable<T> getData()
14. 1
Why going Reactive?
Accessing sequences of data:
single items multiple items
sync T getData() Iterable<T> getData()
async Future<T> getData() Observable<T> getData()
Reactive X is about
dealing with Observables!
15. 1
Why going Reactive?
• Composable:
They are intended for composing flows and sequences of
asynchronous data unlike i.e. Java Futures
• Flexible:
They support emission of single scalar value, but also of
sequences of values or even infinite streams. They have the
flexibility and elegance of their Iterable cousins
• Less Opinionated:
They just don’t care about the source of concurrency or
asynchronicity. The underlying nature of their implementation
might be changed without breaking the consumers
Observables are:
17. 1
Why going Reactive?
Observables vs Iterables:
Iterable (pull) Observable (push)
receive
data
T next() onNext(T)
discover
error
throws Exception onError(Exception)
complete !hasNext() onCompleted()
18. 1
Why going Reactive?
• Iterable is synchronous and pull
• Iterable: the consumer pulls the values from the producer
(blocking the thread until they arrives)
• Observable is asynchronous and push
• Observable: the producer pushes values to the consumer
whenever they are available
• Observable adds the ability for the producer to say:
• “There is no more data available!”
• “An error has occurred!”
Observables vs Iterables:
23. Section 1
Rx 101*
with RxJava
* The road is steep, the road is long, the talk is relatively short.
24. Rx 101 with RxJava
1
2
• JVM implementation of ReactiveX
• Ported by Netflix
• Reached stable (1.0.0) version in November 2014
• Polyglot implementation to Scala, Groovy, Clojure
and Kotlin
• Seems like just a library… but it’s also the concept
in the way you code
RxJava:
25. Rx 101 with RxJava
1
2
• Lightweight (Zero Dependencies and < 800KB Jar)
• Java 6+ & Android 2.3+
• Java 8 lambda support
• Non-opinionated about source of concurrency
• Async or synchronous execution
• Virtual time and schedulers for parameterised
concurrency
RxJava:
26. Rx 101 with RxJava
1
2
RxJava:
compile ‘io.reactivex:rxjava:x.y.z'
https://github.com/ReactiveX/RxJava/
Current version: 1.1.0 released on 02/12/2015
29. Rx 101 with RxJava
1
2
• Emits zero or more items (values)
• Notifies the Observer using onNext(T data)
method when the item is ready to be pushed
• Calls Observer’s onCompleted() method when the
sequence is finished
• Calls Observer’s onError(Throwable t) method
when a serious error happened
• It’s either onCompleted() or onError(Throwable t)
Observable:
30. Rx 101 with RxJava
1
2
Observable creation:
• Convert objects, lists, or arrays of objects into
Observables that emit those objects:
• Observable.just(…);
For converting a single object
• Observable.from(…);
For converting lists, or arrays of objects
• Design your own Observable implementing:
• Observable.create(…);
For async i/o, computational operations, streams of data…
31. Rx 101 with RxJava
1
2
Observable creation:
• There are many more practical ways of creating
Observables:
https://github.com/ReactiveX/RxJava/wiki/Creating-Observables
32. Rx 101 with RxJava
1
2
Observable.create():
Observable<Integer> observable = Observable.create(
new Observable.OnSubscribe<Integer>() {
@Override
public void call(Subscriber<? super Integer> subscriber) {
for (int i = 0; i < 10 && !subscriber.isUnsubscribed(); i++) {
subscriber.onNext(i);
}
if (!subscriber.isUnsubscribed()) {
subscriber.onCompleted();
}
}
});
34. Rx 101 with RxJava
1
2
Using lambda expressions:
Observable<Integer> observable = Observable.create(new Observable.OnSubscribe<Integer>() {
@Override
public void call(Subscriber<? super Integer> subscriber) {
for (int i = 0; i < 10 && !subscriber.isUnsubscribed(); i++) {
subscriber.onNext(i);
}
if (!subscriber.isUnsubscribed()) {
subscriber.onCompleted();
}
}
});
Observable<Integer> observable = Observable.create(subscriber -> {
for (int i = 0; i < 10 && !subscriber.isUnsubscribed(); i++) {
subscriber.onNext(i);
}
if (!subscriber.isUnsubscribed()) {
subscriber.onCompleted();
}
});
35. Rx 101 with RxJava
1
2
Using lambda expressions:
Observable<Integer> observable = Observable.create(new Observable.OnSubscribe<Integer>() {
@Override
public void call(Subscriber<? super Integer> subscriber) {
for (int i = 0; i < 10 && !subscriber.isUnsubscribed(); i++) {
subscriber.onNext(i);
}
if (!subscriber.isUnsubscribed()) {
subscriber.onCompleted();
}
}
});
Observable<Integer> observable = Observable.create(subscriber -> {
for (int i = 0; i < 10 && !subscriber.isUnsubscribed(); i++) {
subscriber.onNext(i);
}
if (!subscriber.isUnsubscribed()) {
subscriber.onCompleted();
}
});
Stuck with Java 5, 6 or 7?
Use Retrolambda to enjoy lambda
expressions from Java 8!
36. Rx 101 with RxJava
1
2
“Hot” vs “Cold” Observables:
37. Rx 101 with RxJava
1
2
• “Hot” Observables:
• May begin emitting items as soon as is is created
• Observer who later subscribes may start observing the
sequence somewhere in the middle
• “Cold” Observables:
• Waits until an observer subscribes to it before it emits items
• An observer is guaranteed to see the whole sequence from
the beginning
“Hot” vs “Cold” Observables:
40. Rx 101 with RxJava
1
2
• Interface methods:
• onNext(T data);
• onCompleted();
• onError(Throwable t);
• Receives zero or more items
• You can override all of the interface methods
(recommended for beginners) or just a single one
Observer<T> - the interface:
41. Rx 101 with RxJava
1
2
• “A Subscriber is an Observer that can also
unsubscribe from that data source.”
• Subscriber class is the implementation of two
interfaces: Observer and Subscriber
• It’s a common practice to pass the
implementation rather then the interface
• It reduces the learning curve for developers new
to Rx
Subscriber - the implementation:
42. Rx 101 with RxJava
1
2
Creating a Subscriber:
Subscriber<Integer> subscriber = new Subscriber<Integer>() {
@Override
public void onCompleted() {
Log.i(TAG, "Sequence is complete!");
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
@Override
public void onNext(Integer i) {
Log.i(TAG, "Item: " + i);
}
};
43. Rx 101 with RxJava
1
2
Subscription:
Observable Observer
44. Rx 101 with RxJava
1
2
Subscription:
321
Observable Observer
Subscription
onNext(..);
onNext(..);
onNext(..);
t
45. Rx 101 with RxJava
1
2
Subscription:
321
Observable Observer
Subscription
onNext(..);
onNext(..);
onNext(..);
// Unsubscribing the Observer/Subscriber
subscriber.unsubscribe();
// Subscribing to the Observable
observable.subscribe(subscriber);
46. Rx 101 with RxJava
1
2
Subscriptions in examples:
// subscribe() method can implement only onNext()
Observable.just("Hello world!")
.subscribe(new Action1<String>() {
@Override
public void call(String s) {
Log.i(TAG, "Greeting: " + s);
}
});
// Simplified using lambda expression
Observable.just("Hello world!")
.subscribe(s -> Log.i(TAG, "Greeting: " + s));
// subscribe() with onNext() and onError()
Observable.just("Hello world!")
.subscribe(
s -> Log.i(TAG, "Greeting: " + s),
t -> t.printStackTrace()
);
47. Rx 101 with RxJava
1
2
Subscriptions in examples:
// subscribe() method can implement only onNext()
Observable.just("Hello world!")
.subscribe(new Action1<String>() {
@Override
public void call(String s) {
Log.i(TAG, "Greeting: " + s);
}
});
// Simplified using lambda expression
Observable.just("Hello world!")
.subscribe(s -> Log.i(TAG, "Greeting: " + s));
// subscribe() with onNext() and onError()
Observable.just("Hello world!")
.subscribe(
s -> Log.i(TAG, "Greeting: " + s),
t -> t.printStackTrace()
);
48. Rx 101 with RxJava
1
2
Subscriptions in examples:
// subscribe() method can implement only onNext()
Observable.just("Hello world!")
.subscribe(new Action1<String>() {
@Override
public void call(String s) {
Log.i(TAG, "Greeting: " + s);
}
});
// Simplified using lambda expression
Observable.just("Hello world!")
.subscribe(s -> Log.i(TAG, "Greeting: " + s));
// subscribe() with onNext() and onError()
Observable.just("Hello world!")
.subscribe(
s -> Log.i(TAG, "Greeting: " + s),
t -> t.printStackTrace()
);
49. Rx 101 with RxJava
1
2
Subscriptions in examples:
// subscribe() method can implement only onNext()
Observable.just("Hello world!")
.subscribe(new Action1<String>() {
@Override
public void call(String s) {
Log.i(TAG, "Greeting: " + s);
}
});
// Simplified using lambda expression
Observable.just("Hello world!")
.subscribe(s -> Log.i(TAG, "Greeting: " + s));
// subscribe() with onNext() and onError()
Observable.just("Hello world!")
.subscribe(
s -> Log.i(TAG, "Greeting: " + s),
t -> t.printStackTrace()
);
56. Rx 101 with RxJava
1
2
Transforming - map:
Transform the items emitted by an Observable by
applying a function to each item
Source: http://rxmarbles.com
57. Rx 101 with RxJava
1
2
Transforming - flatMap:
Transform the items emitted by an Observable into
Observables, then flatten the emissions from those
into a single Observable
58. Rx 101 with RxJava
1
2
Filtering - filter:
Emit only those items from an Observable that pass
a predicate test
59. Rx 101 with RxJava
1
2
Filtering - take:
Emit only the first n items emitted by an Observable
60. Rx 101 with RxJava
1
2
Aggregating - concat:
Emit the emissions from two or more Observables
without interleaving them
61. Rx 101 with RxJava
1
2
Combining - merge:
Combine multiple Observables into one by merging
their emissions
62. Rx 101 with RxJava
1
2
Error handling - retry:
If a source Observable emits an error, resubscribe to
it in the hopes that it will complete without error
64. Rx 101 with RxJava
1
2
Operators - example:
String[] strings = {"Andrzej", "Sitek", "Rx", "101"};
Observable.from(strings)
.flatMap(new Func1<String, Observable<Integer>>() {
@Override
public Observable<Integer> call(String s) {
return Observable.just(s.length());
}
})
.take(3)
.filter(new Func1<Integer, Boolean>() {
@Override
public Boolean call(Integer i) {
return i > 5;
}
})
.map(new Func1<Integer, Integer>() {
@Override
public Integer call(Integer i) {
return i * 10;
}
})
.subscribe(new Action1<Integer>() {
@Override
public void call(Integer i) {
Log.i(TAG, "After few operations: " + i);
}
});
Lots of anonymous classes..
Use lambdas to reduce the
boilerplate!
65. Rx 101 with RxJava
1
2
Operators - example simplified:
String[] strings = {"Andrzej", "Sitek", "Rx", "101"};
Observable.from(strings)
.flatMap(s -> Observable.just(s.length()))
.take(3)
.filter(i -> i > 5)
.map(i -> i * 10)
.subscribe(i -> Log.i(TAG, "After few operations: " + i));
I/MainActivity: After few operations: 70
66. Rx 101 with RxJava
1
2
Schedulers:
• They provide concurrency for Observables
• Utility operators associated:
• Observable.observeOn(Scheduler s);
“perform work on that specific Scheduler”
• Observable.subscribeOn(Scheduler s);
“observe the results on that Scheduler”
• Provide different processing strategies such as
Thread Pools, Event Loops, Handlers, etc.
67. Rx 101 with RxJava
1
2
Schedulers in RxJava:
Scheduler Description
Schedulers.computation()
meant for computational work such as
event-loops and callback processing
Schedulers.from(executor) uses the specified Executor as a Scheduler
Schedulers.immediate()
schedules work to begin immediately in the
current thread
Schedulers.io()
meant for I/O-bound work such as
asynchronous performance of blocking I/O
Schedulers.newThread() creates a new thread for each unit of work
Schedulers.trampoline()
queues work to begin on the current thread
after any already-queued work
68. Rx 101 with RxJava
1
2
Schedulers - example:
Observable<String> observable = Observable.create(subscriber -> {
Log.d(TAG, "Executing on: " + Thread.currentThread());
subscriber.onNext("Schedulers Example");
subscriber.onCompleted();
});
observable.subscribeOn(Schedulers.newThread())
.observeOn(Schedulers.io())
.subscribe(s -> {
Log.i(TAG, "Observing on: " + Thread.currentThread());
Log.i(TAG, s);
});
D/MainActivity: Executing on: Thread[RxNewThreadScheduler-1,5,main]
I/MainActivity: Observing on: Thread[RxCachedThreadScheduler-1,5,main]
I/MainActivity: Schedulers Example
70. Rx in example
1
2
3
Throttled text search:
• Search Github repositories using a simple app
• Throttle the text input so it doesn’t send the
requests each time you type a character
• Don’t perform the search if the input is empty
• Perform network request for search query
• Filter the list of repositories to leave only those with
more than 10 watchers
• Show the results in the list
82. Rx in example
1
2
3
Simplified version - walkthrough:
mSubscription = RxTextView.textChanges(mSearchQuery)
.debounce(400, TimeUnit.MILLISECONDS)
.map(query -> query.toString().trim())
.filter(query -> query.length() > 0)
.doOnNext(query -> clearListAdapter())
.switchMap(query -> getRepositories(query))
.flatMap(list -> Observable.from(list.getItems()))
.filter(item -> item.getWatchersCount() > 10)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(item -> {
mAdapter.add(item);
mAdapter.notifyDataSetChanged();
});
Create the Subscription and add item by item to the list
83. Tips & resources
4
1
2
3
• First, master the rules and then go beyond them!
• Rx is single-threaded by default!
• Use it only when it makes sense - it’s very
tempting to use Rx everywhere..
• Side effect methods doOnNext, doOnError are
very useful for debugging.
• Lots of operators are too hard to learn by heart -
explore them with docs and marble diagrams.
Useful tips:
88. onComplete((s) -> Log.i(“Thank you!”));
Thanks for your attention!
I’d really appreciate your
feedback!
Stay in touch!
@andrzej_sitek
+AndrzejSitek