-
public final class RxJavaHooksUtility class that holds hooks for various Observable, Single and Completable lifecycle-related points as well as Scheduler hooks.
The class features a lockdown state, see lockdown and isLockdown, to prevent further changes to the hooks.
-
-
Field Summary
Fields Modifier and Type Field Description static volatile Action1<Throwable>onErrorstatic volatile Func1<Observable.OnSubscribe, Observable.OnSubscribe>onObservableCreatestatic volatile Func2<Observable, Observable.OnSubscribe, Observable.OnSubscribe>onObservableStartstatic volatile Func1<Scheduler, Scheduler>onComputationSchedulerstatic volatile Func1<Scheduler, Scheduler>onIOSchedulerstatic volatile Func1<Scheduler, Scheduler>onNewThreadSchedulerstatic volatile Func1<Action0, Action0>onScheduleActionstatic volatile Func1<Subscription, Subscription>onObservableReturnstatic volatile Func1<Subscription, Subscription>onSingleReturnstatic volatile Func0<out ScheduledExecutorService>onGenericScheduledExecutorServicestatic volatile Func1<Throwable, Throwable>onObservableSubscribeErrorstatic volatile Func1<Throwable, Throwable>onSingleSubscribeErrorstatic volatile Func1<Throwable, Throwable>onCompletableSubscribeError
-
Method Summary
Modifier and Type Method Description static Action1<Throwable>getOnError()Returns the current global error handler hook action or null if it isset to the default one that signals errors to the current threadsUncaughtExceptionHandler. static voidsetOnError(Action1<Throwable> onError)Sets the global error consumer action unless a lockdown is in effect. static Func1<Observable.OnSubscribe, Observable.OnSubscribe>getOnObservableCreate()Returns the current Observable onCreate hook function or null if it isset to the default pass-through. static voidsetOnObservableCreate(Func1<Observable.OnSubscribe, Observable.OnSubscribe> onObservableCreate)Sets the Observable onCreate hook function unless a lockdown is in effect. static Func2<Observable, Observable.OnSubscribe, Observable.OnSubscribe>getOnObservableStart()Returns the current Observable onStart hook function or null if it isset to the default pass-through. static voidsetOnObservableStart(Func2<Observable, Observable.OnSubscribe, Observable.OnSubscribe> onObservableStart)Sets the hook function that is called when a subscriber subscribes to a Observableunless a lockdown is in effect. static Func1<Scheduler, Scheduler>getOnComputationScheduler()Returns the current computation scheduler hook function or null if it isset to the default pass-through. static voidsetOnComputationScheduler(Func1<Scheduler, Scheduler> onComputationScheduler)Sets the hook function for returning a scheduler when the Schedulers.computation() is calledunless a lockdown is in effect. static Func1<Scheduler, Scheduler>getOnIOScheduler()Returns the current io scheduler hook function or null if it isset to the default pass-through. static voidsetOnIOScheduler(Func1<Scheduler, Scheduler> onIOScheduler)Sets the hook function for returning a scheduler when the Schedulers.io() is calledunless a lockdown is in effect. static Func1<Scheduler, Scheduler>getOnNewThreadScheduler()Returns the current new thread scheduler hook function or null if it isset to the default pass-through. static voidsetOnNewThreadScheduler(Func1<Scheduler, Scheduler> onNewThreadScheduler)Sets the hook function for returning a scheduler when the Schedulers.newThread() is calledunless a lockdown is in effect. static Func1<Action0, Action0>getOnScheduleAction()Returns the current schedule action hook function or null if it isset to the default pass-through. static voidsetOnScheduleAction(Func1<Action0, Action0> onScheduleAction)Sets the hook function that is called before an action is scheduled, allowingdecorating that function, unless a lockdown is in effect. static Func1<Subscription, Subscription>getOnObservableReturn()Returns the current Observable onReturn hook function or null if it isset to the default pass-through. static voidsetOnObservableReturn(Func1<Subscription, Subscription> onObservableReturn)Sets a hook function that is called when the Observable.subscribe() callis about to return a Subscription unless a lockdown is in effect. static Func1<Subscription, Subscription>getOnSingleReturn()Returns the current Single onReturn hook function or null if it isset to the default pass-through. static voidsetOnSingleReturn(Func1<Subscription, Subscription> onSingleReturn)Sets a hook function that is called when the Single.subscribe() callis about to return a Subscription unless a lockdown is in effect. static Func0<out ScheduledExecutorService>getOnGenericScheduledExecutorService()Returns the current factory for creating ScheduledExecutorServices inGenericScheduledExecutorService utility. static voidsetOnGenericScheduledExecutorService(Func0<out ScheduledExecutorService> factory)Sets the hook function for returning a ScheduledExecutorService usedby the GenericScheduledExecutorService for background tasks. static Func1<Throwable, Throwable>getOnObservableSubscribeError()Returns the current Observable onSubscribeError hook function or null if it isset to the default pass-through. static voidsetOnObservableSubscribeError(Func1<Throwable, Throwable> onObservableSubscribeError)Sets a hook function that is called when the Observable.subscribe() callfails with an exception. static Func1<Throwable, Throwable>getOnSingleSubscribeError()Returns the current Single onSubscribeError hook function or null if it isset to the default pass-through. static voidsetOnSingleSubscribeError(Func1<Throwable, Throwable> onSingleSubscribeError)Sets a hook function that is called when the Single.subscribe() callfails with an exception. static Func1<Throwable, Throwable>getOnCompletableSubscribeError()Returns the current Completable onSubscribeError hook function or null if it isset to the default pass-through. static voidsetOnCompletableSubscribeError(Func1<Throwable, Throwable> onCompletableSubscribeError)Sets a hook function that is called when the Completable.subscribe() callfails with an exception. static voidreset()Reset all hook callbacks to those of the current RxJavaPlugins handlers. static <T, R> Observable.Operator<R, T>onObservableLift(Observable.Operator<R, T> operator)Hook to call before the child subscriber would subscribe to an Operator. static voidclear()Clears all hooks to be no-op (and pass-through)and onError hook to signal errors to the caller thread'sUncaughtExceptionHandler. static voidlockdown()Prevents changing the hooks. static booleanisLockdown()Returns true if the hooks can no longer be changed. static voidonError(Throwable ex)Consume undeliverable Throwables (acts as a global catch). static <T> Observable.OnSubscribe<T>onCreate(Observable.OnSubscribe<T> onSubscribe)Hook to call when an Observable is created. static ScheduleronComputationScheduler(Scheduler scheduler)Hook to call when the Schedulers.computation() is called. static ScheduleronIOScheduler(Scheduler scheduler)Hook to call when the Schedulers.io() is called. static ScheduleronNewThreadScheduler(Scheduler scheduler)Hook to call when the Schedulers.newThread() is called. static Action0onScheduledAction(Action0 action)Hook to call before the action is scheduled, allowsdecorating the original action. static <T> Observable.OnSubscribe<T>onObservableStart(Observable<T> instance, Observable.OnSubscribe<T> onSubscribe)Hook to call before the child subscriber is subscribed to the OnSubscribe action. static SubscriptiononObservableReturn(Subscription subscription)Hook to call before the Observable.subscribe() method is about to return a Subscription. static ThrowableonObservableError(Throwable error)Hook to call if the Observable.subscribe() crashes for some reason. static voidresetAssemblyTracking()Resets the assembly tracking hooks to their default delegates toRxJavaPlugins. static voidclearAssemblyTracking()Clears the assembly tracking hooks to their default pass-through behavior. static voidenableAssemblyTracking()Sets up hooks that capture the current stacktrace when a source or anoperator is instantiated, keeping it in a field for debugging purposesand alters exceptions passing along to hold onto this stacktrace. -
-
Method Detail
-
getOnError
static Action1<Throwable> getOnError()
Returns the current global error handler hook action or null if it isset to the default one that signals errors to the current threadsUncaughtExceptionHandler.
This operation is thread-safe.
-
setOnError
static void setOnError(Action1<Throwable> onError)
Sets the global error consumer action unless a lockdown is in effect.
This operation is thread-safe.
Calling with a
{@code null}parameter has the effect thaterrors are routed to the current thread's UncaughtExceptionHandler.- Parameters:
onError- the action that will receive undeliverable Throwables
-
getOnObservableCreate
static Func1<Observable.OnSubscribe, Observable.OnSubscribe> getOnObservableCreate()
Returns the current Observable onCreate hook function or null if it isset to the default pass-through.
This operation is thread-safe.
-
setOnObservableCreate
static void setOnObservableCreate(Func1<Observable.OnSubscribe, Observable.OnSubscribe> onObservableCreate)
Sets the Observable onCreate hook function unless a lockdown is in effect.
This operation is thread-safe.
Calling with a
{@code null}parameter restores the default behavior:the hook returns the same object.- Parameters:
onObservableCreate- the function that takes the original OnSubscribeand should return a OnSubscribe.
-
getOnObservableStart
static Func2<Observable, Observable.OnSubscribe, Observable.OnSubscribe> getOnObservableStart()
Returns the current Observable onStart hook function or null if it isset to the default pass-through.
This operation is thread-safe.
-
setOnObservableStart
static void setOnObservableStart(Func2<Observable, Observable.OnSubscribe, Observable.OnSubscribe> onObservableStart)
Sets the hook function that is called when a subscriber subscribes to a Observableunless a lockdown is in effect.
This operation is thread-safe.
Calling with a
{@code null}parameter restores the default behavior:the hook returns the same OnSubscribe object.- Parameters:
onObservableStart- the function that is called with the current Observable instance,its OnSubscribe function and should return a OnSubscribe functionthat gets actually subscribed to.
-
getOnComputationScheduler
static Func1<Scheduler, Scheduler> getOnComputationScheduler()
Returns the current computation scheduler hook function or null if it isset to the default pass-through.
This operation is thread-safe.
-
setOnComputationScheduler
static void setOnComputationScheduler(Func1<Scheduler, Scheduler> onComputationScheduler)
Sets the hook function for returning a scheduler when the Schedulers.computation() is calledunless a lockdown is in effect.
This operation is thread-safe.
Calling with a
{@code null}parameter restores the default behavior:the hook returns the same object.- Parameters:
onComputationScheduler- the function that receives the original computation schedulerand should return a scheduler.
-
getOnIOScheduler
static Func1<Scheduler, Scheduler> getOnIOScheduler()
Returns the current io scheduler hook function or null if it isset to the default pass-through.
This operation is thread-safe.
-
setOnIOScheduler
static void setOnIOScheduler(Func1<Scheduler, Scheduler> onIOScheduler)
Sets the hook function for returning a scheduler when the Schedulers.io() is calledunless a lockdown is in effect.
This operation is thread-safe.
Calling with a
{@code null}parameter restores the default behavior:the hook returns the same object.- Parameters:
onIOScheduler- the function that receives the original io schedulerand should return a scheduler.
-
getOnNewThreadScheduler
static Func1<Scheduler, Scheduler> getOnNewThreadScheduler()
Returns the current new thread scheduler hook function or null if it isset to the default pass-through.
This operation is thread-safe.
-
setOnNewThreadScheduler
static void setOnNewThreadScheduler(Func1<Scheduler, Scheduler> onNewThreadScheduler)
Sets the hook function for returning a scheduler when the Schedulers.newThread() is calledunless a lockdown is in effect.
This operation is thread-safe.
Calling with a
{@code null}parameter restores the default behavior:the hook returns the same object.- Parameters:
onNewThreadScheduler- the function that receives the original new thread schedulerand should return a scheduler.
-
getOnScheduleAction
static Func1<Action0, Action0> getOnScheduleAction()
Returns the current schedule action hook function or null if it isset to the default pass-through.
This operation is thread-safe.
-
setOnScheduleAction
static void setOnScheduleAction(Func1<Action0, Action0> onScheduleAction)
Sets the hook function that is called before an action is scheduled, allowingdecorating that function, unless a lockdown is in effect.
This operation is thread-safe.
Calling with a
{@code null}parameter restores the default behavior:the hook returns the same object.- Parameters:
onScheduleAction- the function that receives the original action and shouldreturn an Action0.
-
getOnObservableReturn
static Func1<Subscription, Subscription> getOnObservableReturn()
Returns the current Observable onReturn hook function or null if it isset to the default pass-through.
This operation is thread-safe.
-
setOnObservableReturn
static void setOnObservableReturn(Func1<Subscription, Subscription> onObservableReturn)
Sets a hook function that is called when the Observable.subscribe() callis about to return a Subscription unless a lockdown is in effect.
This operation is thread-safe.
Calling with a
{@code null}parameter restores the default behavior:the hook returns the same object.- Parameters:
onObservableReturn- the function that is called with the Subscriber that has beensubscribed to the OnSubscribe function and returns a Subscription that will be returned bysubscribe().
-
getOnSingleReturn
static Func1<Subscription, Subscription> getOnSingleReturn()
Returns the current Single onReturn hook function or null if it isset to the default pass-through.
This operation is thread-safe.
-
setOnSingleReturn
static void setOnSingleReturn(Func1<Subscription, Subscription> onSingleReturn)
Sets a hook function that is called when the Single.subscribe() callis about to return a Subscription unless a lockdown is in effect.
This operation is thread-safe.
Calling with a
{@code null}parameter restores the default behavior:the hook returns the same object.- Parameters:
onSingleReturn- the function that is called with the SingleSubscriber that has beensubscribed to the OnSubscribe function and returns a Subscription that will be returned bysubscribe().
-
getOnGenericScheduledExecutorService
static Func0<out ScheduledExecutorService> getOnGenericScheduledExecutorService()
Returns the current factory for creating ScheduledExecutorServices inGenericScheduledExecutorService utility.
This operation is thread-safe.
-
setOnGenericScheduledExecutorService
static void setOnGenericScheduledExecutorService(Func0<out ScheduledExecutorService> factory)
Sets the hook function for returning a ScheduledExecutorService usedby the GenericScheduledExecutorService for background tasks.
This operation is thread-safe.
Calling with a
{@code null}parameter restores the default behavior:create the default with newScheduledThreadPool.For the changes to take effect, the Schedulers has to be restarted.
- Parameters:
factory- the supplier that is called when the GenericScheduledExecutorServiceis (re)started
-
getOnObservableSubscribeError
static Func1<Throwable, Throwable> getOnObservableSubscribeError()
Returns the current Observable onSubscribeError hook function or null if it isset to the default pass-through.
This operation is thread-safe.
-
setOnObservableSubscribeError
static void setOnObservableSubscribeError(Func1<Throwable, Throwable> onObservableSubscribeError)
Sets a hook function that is called when the Observable.subscribe() callfails with an exception.
This operation is thread-safe.
Calling with a
{@code null}parameter restores the default behavior:the hook returns the same object.- Parameters:
onObservableSubscribeError- the function that is called with the crash exception and should returnan exception.
-
getOnSingleSubscribeError
static Func1<Throwable, Throwable> getOnSingleSubscribeError()
Returns the current Single onSubscribeError hook function or null if it isset to the default pass-through.
This operation is thread-safe.
-
setOnSingleSubscribeError
static void setOnSingleSubscribeError(Func1<Throwable, Throwable> onSingleSubscribeError)
Sets a hook function that is called when the Single.subscribe() callfails with an exception.
This operation is thread-safe.
Calling with a
{@code null}parameter restores the default behavior:the hook returns the same object.- Parameters:
onSingleSubscribeError- the function that is called with the crash exception and should returnan exception.
-
getOnCompletableSubscribeError
static Func1<Throwable, Throwable> getOnCompletableSubscribeError()
Returns the current Completable onSubscribeError hook function or null if it isset to the default pass-through.
This operation is thread-safe.
-
setOnCompletableSubscribeError
static void setOnCompletableSubscribeError(Func1<Throwable, Throwable> onCompletableSubscribeError)
Sets a hook function that is called when the Completable.subscribe() callfails with an exception.
This operation is thread-safe.
Calling with a
{@code null}parameter restores the default behavior:the hook returns the same object.- Parameters:
onCompletableSubscribeError- the function that is called with the crash exception and should returnan exception.
-
reset
static void reset()
Reset all hook callbacks to those of the current RxJavaPlugins handlers.
-
onObservableLift
static <T, R> Observable.Operator<R, T> onObservableLift(Observable.Operator<R, T> operator)
Hook to call before the child subscriber would subscribe to an Operator.
- Parameters:
operator- the original operator
-
clear
static void clear()
Clears all hooks to be no-op (and pass-through)and onError hook to signal errors to the caller thread'sUncaughtExceptionHandler.
-
lockdown
static void lockdown()
Prevents changing the hooks.
-
isLockdown
static boolean isLockdown()
Returns true if the hooks can no longer be changed.
-
onError
static void onError(Throwable ex)
Consume undeliverable Throwables (acts as a global catch).
- Parameters:
ex- the exception to handle
-
onCreate
static <T> Observable.OnSubscribe<T> onCreate(Observable.OnSubscribe<T> onSubscribe)
Hook to call when an Observable is created.
- Parameters:
onSubscribe- the original OnSubscribe logic
-
onComputationScheduler
static Scheduler onComputationScheduler(Scheduler scheduler)
Hook to call when the Schedulers.computation() is called.
- Parameters:
scheduler- the default computation scheduler
-
onIOScheduler
static Scheduler onIOScheduler(Scheduler scheduler)
Hook to call when the Schedulers.io() is called.
- Parameters:
scheduler- the default io scheduler
-
onNewThreadScheduler
static Scheduler onNewThreadScheduler(Scheduler scheduler)
Hook to call when the Schedulers.newThread() is called.
- Parameters:
scheduler- the default new thread scheduler
-
onScheduledAction
static Action0 onScheduledAction(Action0 action)
Hook to call before the action is scheduled, allowsdecorating the original action.
- Parameters:
action- the original action
-
onObservableStart
static <T> Observable.OnSubscribe<T> onObservableStart(Observable<T> instance, Observable.OnSubscribe<T> onSubscribe)
Hook to call before the child subscriber is subscribed to the OnSubscribe action.
- Parameters:
instance- the parent Observable instanceonSubscribe- the original OnSubscribe action
-
onObservableReturn
static Subscription onObservableReturn(Subscription subscription)
Hook to call before the Observable.subscribe() method is about to return a Subscription.
- Parameters:
subscription- the original subscription
-
onObservableError
static Throwable onObservableError(Throwable error)
Hook to call if the Observable.subscribe() crashes for some reason.
- Parameters:
error- the error
-
resetAssemblyTracking
static void resetAssemblyTracking()
Resets the assembly tracking hooks to their default delegates toRxJavaPlugins.
-
clearAssemblyTracking
static void clearAssemblyTracking()
Clears the assembly tracking hooks to their default pass-through behavior.
-
enableAssemblyTracking
static void enableAssemblyTracking()
Sets up hooks that capture the current stacktrace when a source or anoperator is instantiated, keeping it in a field for debugging purposesand alters exceptions passing along to hold onto this stacktrace.
-
-
-
-