tags: Android advanced
First look at the entrance of RXJAVA. Since RXJAVA is actually an OBSERVABLE layer structure, a Scheduler is also set in the middle. Below this method is to set OBServer, the actual analysis of RXJAVA is nice to analyze the foot analysis. Everyone see how RXJAVA is highly abstract, using Scheduler, scheduling, and layer to OBServer. The schedule is actually mainly thread scheduling.
public final void subscribe(Observer<? super T> observer) {
ObjectHelper.requireNonNull(observer, "observer is null");
try {
// Calls The Associated Hook Function. It is actually called hook function.
observer = RxJavaPlugins.onSubscribe(this, observer);
ObjectHelper.requireNonNull(observer, "The RxJavaPlugins.onSubscribe hook returned a null Observer. Please change the handler provided to RxJavaPlugins.setOnObservableSubscribe for invalid null returns. Further reading: https://github.com/ReactiveX/RxJava/wiki/Plugins");
// This interface method actually calls the Observalbe included in the outer layer. Under normal circumstances. After the various OPERATORs of Observalbe generate shape colored OBserveRBE, how to associate Scheduler now. This is an abstract class. In fact, the last OBSERVABLE has only Observablesubscribeon formed in Subscribeon, which is the upstream schedule. The result of the formed layer is scheduled to
ObserVableObserve formed by Observeon. Finally passed to Observe. It is equal to that various operators are actually the corresponding RXJAVA call logic. Although Subscribeon is incorporated, it is, for example, iScheduler, but returned or OBSERVABLE.
The same is true of Observeon. Ioscheduler is the scheduling made by a thread pool. Observeon's Scheduler, such as new HandlerScheduler(new Handler(Looper.getMainLooper()), false) The Looper used by the main thread is naturally passed through Handler, passed Runable to the main thread, and finally passed to the apply method for Observe.
This paragraph is only part of the core, but it provides the learning idea of RXJAVA. Combined with the retrofit on the above, the final footpoint of Retrofit is to generate two synchronous or asynchronous Obserable. For example, CallexecuteObserveRvable and CallenqueueObserve. Original okhttp is a thread pool technology, Retrofit has been transformed with him, and the thread pool is provided by the outside SCHEDULER. And RXJAVA can also achieve similar EVENT BUS technology, it is really very boastry.
subscribeActual(observer);
} catch (NullPointerException e) { // NOPMD
throw e;
} catch (Throwable e) {
Exceptions.throwIfFatal(e);
// can't call onError because no way to know if a Disposable has been set or not
// can't call onSubscribe because the call might have set a Subscription already
RxJavaPlugins.onError(e);
NullPointerException npe = new NullPointerException("Actually not, but can't throw other exceptions due to RS");
npe.initCause(e);
throw npe;
}
}
while circulation of the three conditions 1. Initial value 2. Control Conditions 3. step Classic example: while recycling else statement When whi ... else condition is not satisfied in a conditional s...
Java is a strongly typed language: Each variable must declare its type, you can declare multiple variables in one line Local variables: The method of statement block internal variable Instance variabl...
The local wants to restore the file deleted a long time ago, and the committed commit has been pushed after the deletion, as follows: Switch to the branch that was pushed to before, such as each time ...
topic Ideas //First arrange the array in ascending order, and then group by two //The maximum value of the minimum sum is the sum of the even numbered elements at index Test Results...
Leetcode (js)-Daily practice of the product of arrays other than itself Advanced writing:...
Python applications (a) A, python definition 1, Python is a simple, interpreted, interactive, portable, ultra-high-level object-oriented language. 2. Select the main factors python: Software Quality: ...
In the annual school competition, all students finalists will receive a very nice t-shirt. But whenever our staff to hundreds of pieces of clothing shipped back to the stadium from the store when they...
This article describes about the use of Ansible to create a basic certificate related methods. Ansible basic knowledge used: csr file template module is used to set the certificate copy module for cop...
Article catalog 1. Return, SaltStack Components 1.1 Return process 1.2 use mysql as return storage method 2. job cache 2.1 Job Cache process 2.2 JOB Management 1. Return, SaltStack Components The RETU...