RxJava



rx.plugins
Class RxJavaObservableExecutionHook

java.lang.Object
  extended by rx.plugins.RxJavaObservableExecutionHook

public abstract class RxJavaObservableExecutionHook
extends java.lang.Object

Abstract ExecutionHook with invocations at different lifecycle points of Observable execution with a default no-op implementation.

See RxJavaPlugins or the RxJava GitHub Wiki for information on configuring plugins: https://github.com/Netflix/RxJava/wiki/Plugins.

Note on thread-safety and performance

A single implementation of this class will be used globally so methods on this class will be invoked concurrently from multiple threads so all functionality must be thread-safe.

Methods are also invoked synchronously and will add to execution time of the observable so all behavior should be fast. If anything time-consuming is to be done it should be spawned asynchronously onto separate worker threads.


Constructor Summary
RxJavaObservableExecutionHook()
           
 
Method Summary
<T> java.lang.Exception
onSubscribeError(Observable<T> observableInstance, java.lang.Exception e)
          Invoked after failed execution of Observable.subscribe(Observer) with thrown Exception.
<T> Subscription
onSubscribeReturn(Observable<T> observableInstance, Subscription subscription)
          Invoked after successful execution of Observable.subscribe(rx.Observer) with returned Subscription.
<T> Func1<Observer<T>,Subscription>
onSubscribeStart(Observable<T> observableInstance, Func1<Observer<T>,Subscription> onSubscribe)
          Invoked before Observable.subscribe(rx.Observer) is about to be executed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RxJavaObservableExecutionHook

public RxJavaObservableExecutionHook()
Method Detail

onSubscribeStart

public <T> Func1<Observer<T>,Subscription> onSubscribeStart(Observable<T> observableInstance,
                                                            Func1<Observer<T>,Subscription> onSubscribe)
Invoked before Observable.subscribe(rx.Observer) is about to be executed.

This can be used to decorate or replace the onSubscribe function or just perform extra logging, metrics and other such things and pass-thru the function.

Parameters:
observableInstance - The executing Observable instance.
onSubscribe - original Func1<Observer, Subscription> to be executed
Returns:
Func1<Observer, Subscription> function that can be modified, decorated, replaced or just returned as a pass-thru.

onSubscribeReturn

public <T> Subscription onSubscribeReturn(Observable<T> observableInstance,
                                          Subscription subscription)
Invoked after successful execution of Observable.subscribe(rx.Observer) with returned Subscription.

This can be used to decorate or replace the Subscription instance or just perform extra logging, metrics and other such things and pass-thru the subscription.

Parameters:
observableInstance - The executing Observable instance.
subscription - original Subscription
Returns:
Subscription subscription that can be modified, decorated, replaced or just returned as a pass-thru.

onSubscribeError

public <T> java.lang.Exception onSubscribeError(Observable<T> observableInstance,
                                                java.lang.Exception e)
Invoked after failed execution of Observable.subscribe(Observer) with thrown Exception.

This is NOT errors emitted via Observer.onError(Exception) but exceptions thrown when attempting to subscribe to a Func1<Observer, Subscription>.

Parameters:
observableInstance - The executing Observable instance.
e - Exception thrown by Observable.subscribe(Observer)
Returns:
Exception that can be decorated, replaced or just returned as a pass-thru.