public final class RxJavaHooks
extends java.lang.Object
The class features a lockdown state, see lockdown()
and isLockdown()
, to
prevent further changes to the hooks.
Modifier and Type | Method and Description |
---|---|
static void |
clear()
Clears all hooks to be no-op (and pass-through)
and onError hook to signal errors to the caller thread's
UncaughtExceptionHandler.
|
static void |
clearAssemblyTracking()
Clears the assembly tracking hooks to their default pass-through behavior.
|
static void |
enableAssemblyTracking()
Sets up hooks that capture the current stacktrace when a source or an
operator is instantiated, keeping it in a field for debugging purposes
and alters exceptions passing along to hold onto this stacktrace.
|
static Func1<Completable.OnSubscribe,Completable.OnSubscribe> |
getOnCompletableCreate()
Returns the current Completable onCreate hook function or null if it is
set to the default pass-through.
|
static Func1<Completable.Operator,Completable.Operator> |
getOnCompletableLift()
Returns the current Completable onLift hook function or null if it is
set to the default pass-through.
|
static Func2<Completable,Completable.OnSubscribe,Completable.OnSubscribe> |
getOnCompletableStart()
Returns the current Completable onStart hook function or null if it is
set to the default pass-through.
|
static Func1<java.lang.Throwable,java.lang.Throwable> |
getOnCompletableSubscribeError()
Returns the current Completable onSubscribeError hook function or null if it is
set to the default pass-through.
|
static Func1<Scheduler,Scheduler> |
getOnComputationScheduler()
Returns the current computation scheduler hook function or null if it is
set to the default pass-through.
|
static Action1<java.lang.Throwable> |
getOnError()
Returns the current global error handler hook action or null if it is
set to the default one that signals errors to the current threads
UncaughtExceptionHandler.
|
static Func0<? extends java.util.concurrent.ScheduledExecutorService> |
getOnGenericScheduledExecutorService()
Returns the current factory for creating ScheduledExecutorServices in
GenericScheduledExecutorService utility.
|
static Func1<Scheduler,Scheduler> |
getOnIOScheduler()
Returns the current io scheduler hook function or null if it is
set to the default pass-through.
|
static Func1<Scheduler,Scheduler> |
getOnNewThreadScheduler()
Returns the current new thread scheduler hook function or null if it is
set to the default pass-through.
|
static Func1<Observable.OnSubscribe,Observable.OnSubscribe> |
getOnObservableCreate()
Returns the current Observable onCreate hook function or null if it is
set to the default pass-through.
|
static Func1<Observable.Operator,Observable.Operator> |
getOnObservableLift()
Returns the current Observable onLift hook function or null if it is
set to the default pass-through.
|
static Func1<Subscription,Subscription> |
getOnObservableReturn()
Returns the current Observable onReturn hook function or null if it is
set to the default pass-through.
|
static Func2<Observable,Observable.OnSubscribe,Observable.OnSubscribe> |
getOnObservableStart()
Returns the current Observable onStart hook function or null if it is
set to the default pass-through.
|
static Func1<java.lang.Throwable,java.lang.Throwable> |
getOnObservableSubscribeError()
Returns the current Observable onSubscribeError hook function or null if it is
set to the default pass-through.
|
static Func1<Action0,Action0> |
getOnScheduleAction()
Returns the current schedule action hook function or null if it is
set to the default pass-through.
|
static Func1<Single.OnSubscribe,Single.OnSubscribe> |
getOnSingleCreate()
Returns the current Single onCreate hook function or null if it is
set to the default pass-through.
|
static Func1<Observable.Operator,Observable.Operator> |
getOnSingleLift()
Returns the current Single onLift hook function or null if it is
set to the default pass-through.
|
static Func1<Subscription,Subscription> |
getOnSingleReturn()
Returns the current Single onReturn hook function or null if it is
set to the default pass-through.
|
static Func2<Single,Single.OnSubscribe,Single.OnSubscribe> |
getOnSingleStart()
Returns the current Single onStart hook function or null if it is
set to the default pass-through.
|
static Func1<java.lang.Throwable,java.lang.Throwable> |
getOnSingleSubscribeError()
Returns the current Single onSubscribeError hook function or null if it is
set to the default pass-through.
|
static boolean |
isLockdown()
Returns true if the hooks can no longer be changed.
|
static void |
lockdown()
Prevents changing the hooks.
|
static java.lang.Throwable |
onCompletableError(java.lang.Throwable error)
Hook to call if the Completable.subscribe() crashes for some reason.
|
static <T,R> Completable.Operator |
onCompletableLift(Completable.Operator operator)
Hook to call before the child subscriber would subscribe to an Operator.
|
static <T> Completable.OnSubscribe |
onCompletableStart(Completable instance,
Completable.OnSubscribe onSubscribe)
Hook to call before the child subscriber is subscribed to the OnSubscribe action.
|
static Scheduler |
onComputationScheduler(Scheduler scheduler)
Hook to call when the Schedulers.computation() is called.
|
static Completable.OnSubscribe |
onCreate(Completable.OnSubscribe onSubscribe)
Hook to call when a Completable is created.
|
static <T> Observable.OnSubscribe<T> |
onCreate(Observable.OnSubscribe<T> onSubscribe)
Hook to call when an Observable is created.
|
static <T> Single.OnSubscribe<T> |
onCreate(Single.OnSubscribe<T> onSubscribe)
Hook to call when a Single is created.
|
static void |
onError(java.lang.Throwable ex)
Consume undeliverable Throwables (acts as a global catch).
|
static Scheduler |
onIOScheduler(Scheduler scheduler)
Hook to call when the Schedulers.io() is called.
|
static Scheduler |
onNewThreadScheduler(Scheduler scheduler)
Hook to call when the Schedulers.newThread() is called.
|
static java.lang.Throwable |
onObservableError(java.lang.Throwable error)
Hook to call if the Observable.subscribe() crashes for some reason.
|
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 Subscription |
onObservableReturn(Subscription subscription)
Hook to call before the Observable.subscribe() method is about to return a Subscription.
|
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 Action0 |
onScheduledAction(Action0 action)
Hook to call before the action is scheduled, allows
decorating the original action.
|
static java.lang.Throwable |
onSingleError(java.lang.Throwable error)
Hook to call if the Single.subscribe() crashes for some reason.
|
static <T,R> Observable.Operator<R,T> |
onSingleLift(Observable.Operator<R,T> operator)
Hook to call before the child subscriber would subscribe to an Operator.
|
static Subscription |
onSingleReturn(Subscription subscription)
Hook to call before the Single.subscribe() method is about to return a Subscription.
|
static <T> Single.OnSubscribe<T> |
onSingleStart(Single<T> instance,
Single.OnSubscribe<T> onSubscribe)
Hook to call before the child subscriber is subscribed to the OnSubscribe action.
|
static void |
reset()
Reset all hook callbacks to those of the current RxJavaPlugins handlers.
|
static void |
resetAssemblyTracking()
Resets the assembly tracking hooks to their default delegates to
RxJavaPlugins.
|
static void |
setOnCompletableCreate(Func1<Completable.OnSubscribe,Completable.OnSubscribe> onCompletableCreate)
Sets the Completable's onCreate hook function unless a lockdown is in effect.
|
static void |
setOnCompletableLift(Func1<Completable.Operator,Completable.Operator> onCompletableLift)
Sets a hook function that is called with an operator when a Completable operator built with
lift() gets subscribed to.
|
static void |
setOnCompletableStart(Func2<Completable,Completable.OnSubscribe,Completable.OnSubscribe> onCompletableStart)
Sets the hook function that is called when a subscriber subscribes to a Completable
unless a lockdown is in effect.
|
static void |
setOnCompletableSubscribeError(Func1<java.lang.Throwable,java.lang.Throwable> onCompletableSubscribeError)
Sets a hook function that is called when the Completable.subscribe() call
fails with an exception.
|
static void |
setOnComputationScheduler(Func1<Scheduler,Scheduler> onComputationScheduler)
Sets the hook function for returning a scheduler when the Schedulers.computation() is called
unless a lockdown is in effect.
|
static void |
setOnError(Action1<java.lang.Throwable> onError)
Sets the global error consumer action unless a lockdown is in effect.
|
static void |
setOnGenericScheduledExecutorService(Func0<? extends java.util.concurrent.ScheduledExecutorService> factory)
Sets the hook function for returning a ScheduledExecutorService used
by the GenericScheduledExecutorService for background tasks.
|
static void |
setOnIOScheduler(Func1<Scheduler,Scheduler> onIOScheduler)
Sets the hook function for returning a scheduler when the Schedulers.io() is called
unless a lockdown is in effect.
|
static void |
setOnNewThreadScheduler(Func1<Scheduler,Scheduler> onNewThreadScheduler)
Sets the hook function for returning a scheduler when the Schedulers.newThread() is called
unless a lockdown is in effect.
|
static void |
setOnObservableCreate(Func1<Observable.OnSubscribe,Observable.OnSubscribe> onObservableCreate)
Sets the Observable onCreate hook function unless a lockdown is in effect.
|
static void |
setOnObservableLift(Func1<Observable.Operator,Observable.Operator> onObservableLift)
Sets a hook function that is called with an operator when an Observable operator built with
lift() gets subscribed to.
|
static void |
setOnObservableReturn(Func1<Subscription,Subscription> onObservableReturn)
Sets a hook function that is called when the Observable.subscribe() call
is about to return a Subscription unless a lockdown is in effect.
|
static void |
setOnObservableStart(Func2<Observable,Observable.OnSubscribe,Observable.OnSubscribe> onObservableStart)
Sets the hook function that is called when a subscriber subscribes to a Observable
unless a lockdown is in effect.
|
static void |
setOnObservableSubscribeError(Func1<java.lang.Throwable,java.lang.Throwable> onObservableSubscribeError)
Sets a hook function that is called when the Observable.subscribe() call
fails with an exception.
|
static void |
setOnScheduleAction(Func1<Action0,Action0> onScheduleAction)
Sets the hook function that is called before an action is scheduled, allowing
decorating that function, unless a lockdown is in effect.
|
static void |
setOnSingleCreate(Func1<Single.OnSubscribe,Single.OnSubscribe> onSingleCreate)
Sets the Single onCreate hook function unless a lockdown is in effect.
|
static void |
setOnSingleLift(Func1<Observable.Operator,Observable.Operator> onSingleLift)
Sets a hook function that is called with an operator when an Single operator built with
lift() gets subscribed to.
|
static void |
setOnSingleReturn(Func1<Subscription,Subscription> onSingleReturn)
Sets a hook function that is called when the Single.subscribe() call
is about to return a Subscription unless a lockdown is in effect.
|
static void |
setOnSingleStart(Func2<Single,Single.OnSubscribe,Single.OnSubscribe> onSingleStart)
Sets the hook function that is called when a subscriber subscribes to a Single
unless a lockdown is in effect.
|
static void |
setOnSingleSubscribeError(Func1<java.lang.Throwable,java.lang.Throwable> onSingleSubscribeError)
Sets a hook function that is called when the Single.subscribe() call
fails with an exception.
|
public static void reset()
clear()
public static void clear()
reset()
public static void lockdown()
public static boolean isLockdown()
public static void onError(java.lang.Throwable ex)
ex
- the exception to handlepublic static <T> Observable.OnSubscribe<T> onCreate(Observable.OnSubscribe<T> onSubscribe)
T
- the value typeonSubscribe
- the original OnSubscribe logicpublic static <T> Single.OnSubscribe<T> onCreate(Single.OnSubscribe<T> onSubscribe)
T
- the value typeonSubscribe
- the original OnSubscribe logicpublic static Completable.OnSubscribe onCreate(Completable.OnSubscribe onSubscribe)
onSubscribe
- the original OnSubscribe logicpublic static Scheduler onComputationScheduler(Scheduler scheduler)
scheduler
- the default computation schedulerpublic static Scheduler onIOScheduler(Scheduler scheduler)
scheduler
- the default io schedulerpublic static Scheduler onNewThreadScheduler(Scheduler scheduler)
scheduler
- the default new thread schedulerpublic static Action0 onScheduledAction(Action0 action)
action
- the original actionpublic static <T> Observable.OnSubscribe<T> onObservableStart(Observable<T> instance, Observable.OnSubscribe<T> onSubscribe)
T
- the value typeinstance
- the parent Observable instanceonSubscribe
- the original OnSubscribe actionpublic static Subscription onObservableReturn(Subscription subscription)
subscription
- the original subscriptionpublic static java.lang.Throwable onObservableError(java.lang.Throwable error)
error
- the errorpublic static <T,R> Observable.Operator<R,T> onObservableLift(Observable.Operator<R,T> operator)
T
- the input value typeR
- the output value typeoperator
- the original operatorpublic static <T> Single.OnSubscribe<T> onSingleStart(Single<T> instance, Single.OnSubscribe<T> onSubscribe)
T
- the value typeinstance
- the parent Single instanceonSubscribe
- the original OnSubscribe actionpublic static Subscription onSingleReturn(Subscription subscription)
subscription
- the original subscriptionpublic static java.lang.Throwable onSingleError(java.lang.Throwable error)
error
- the errorpublic static <T,R> Observable.Operator<R,T> onSingleLift(Observable.Operator<R,T> operator)
T
- the input value typeR
- the output value typeoperator
- the original operatorpublic static <T> Completable.OnSubscribe onCompletableStart(Completable instance, Completable.OnSubscribe onSubscribe)
T
- the value typeinstance
- the parent Completable instanceonSubscribe
- the original OnSubscribe actionpublic static java.lang.Throwable onCompletableError(java.lang.Throwable error)
error
- the errorpublic static <T,R> Completable.Operator onCompletableLift(Completable.Operator operator)
T
- the input value typeR
- the output value typeoperator
- the original operatorpublic static void setOnError(Action1<java.lang.Throwable> onError)
This operation is thread-safe.
Calling with a null
parameter has the effect that
errors are routed to the current thread's Thread.UncaughtExceptionHandler
.
onError
- the action that will receive undeliverable Throwablespublic static void setOnCompletableCreate(Func1<Completable.OnSubscribe,Completable.OnSubscribe> onCompletableCreate)
This operation is thread-safe.
Calling with a null
parameter restores the default behavior:
the hook returns the same object.
onCompletableCreate
- the function that takes the original CompletableOnSubscribe
and should return a CompletableOnSubscribe.public static void setOnObservableCreate(Func1<Observable.OnSubscribe,Observable.OnSubscribe> onObservableCreate)
This operation is thread-safe.
Calling with a null
parameter restores the default behavior:
the hook returns the same object.
onObservableCreate
- the function that takes the original OnSubscribe
and should return a OnSubscribe.public static void setOnSingleCreate(Func1<Single.OnSubscribe,Single.OnSubscribe> onSingleCreate)
This operation is thread-safe.
Calling with a null
parameter restores the default behavior:
the hook returns the same object.
onSingleCreate
- the function that takes the original OnSubscribe
and should return a OnSubscribe.public static void setOnComputationScheduler(Func1<Scheduler,Scheduler> onComputationScheduler)
This operation is thread-safe.
Calling with a null
parameter restores the default behavior:
the hook returns the same object.
onComputationScheduler
- the function that receives the original computation scheduler
and should return a scheduler.public static void setOnIOScheduler(Func1<Scheduler,Scheduler> onIOScheduler)
This operation is thread-safe.
Calling with a null
parameter restores the default behavior:
the hook returns the same object.
onIOScheduler
- the function that receives the original io scheduler
and should return a scheduler.public static void setOnNewThreadScheduler(Func1<Scheduler,Scheduler> onNewThreadScheduler)
This operation is thread-safe.
Calling with a null
parameter restores the default behavior:
the hook returns the same object.
onNewThreadScheduler
- the function that receives the original new thread scheduler
and should return a scheduler.public static void setOnScheduleAction(Func1<Action0,Action0> onScheduleAction)
This operation is thread-safe.
Calling with a null
parameter restores the default behavior:
the hook returns the same object.
onScheduleAction
- the function that receives the original action and should
return an Action0.public static void setOnCompletableStart(Func2<Completable,Completable.OnSubscribe,Completable.OnSubscribe> onCompletableStart)
This operation is thread-safe.
Calling with a null
parameter restores the default behavior:
the hook returns the same CompletableOnSubscribe object.
onCompletableStart
- the function that is called with the current Completable instance,
its CompletableOnSubscribe function and should return a CompletableOnSubscribe function
that gets actually subscribed to.public static void setOnObservableStart(Func2<Observable,Observable.OnSubscribe,Observable.OnSubscribe> onObservableStart)
This operation is thread-safe.
Calling with a null
parameter restores the default behavior:
the hook returns the same OnSubscribe object.
onObservableStart
- the function that is called with the current Observable instance,
its OnSubscribe function and should return a OnSubscribe function
that gets actually subscribed to.public static void setOnSingleStart(Func2<Single,Single.OnSubscribe,Single.OnSubscribe> onSingleStart)
This operation is thread-safe.
Calling with a null
parameter restores the default behavior:
the hook returns the same OnSubscribe object.
onSingleStart
- the function that is called with the current Single instance,
its OnSubscribe function and should return a OnSubscribe function
that gets actually subscribed to.public static void setOnObservableReturn(Func1<Subscription,Subscription> onObservableReturn)
This operation is thread-safe.
Calling with a null
parameter restores the default behavior:
the hook returns the same object.
onObservableReturn
- the function that is called with the Subscriber that has been
subscribed to the OnSubscribe function and returns a Subscription that will be returned by
subscribe().public static void setOnSingleReturn(Func1<Subscription,Subscription> onSingleReturn)
This operation is thread-safe.
Calling with a null
parameter restores the default behavior:
the hook returns the same object.
onSingleReturn
- the function that is called with the SingleSubscriber that has been
subscribed to the OnSubscribe function and returns a Subscription that will be returned by
subscribe().public static void setOnSingleSubscribeError(Func1<java.lang.Throwable,java.lang.Throwable> onSingleSubscribeError)
This operation is thread-safe.
Calling with a null
parameter restores the default behavior:
the hook returns the same object.
onSingleSubscribeError
- the function that is called with the crash exception and should return
an exception.public static Func1<java.lang.Throwable,java.lang.Throwable> getOnSingleSubscribeError()
This operation is thread-safe.
public static void setOnCompletableSubscribeError(Func1<java.lang.Throwable,java.lang.Throwable> onCompletableSubscribeError)
This operation is thread-safe.
Calling with a null
parameter restores the default behavior:
the hook returns the same object.
onCompletableSubscribeError
- the function that is called with the crash exception and should return
an exception.public static Func1<java.lang.Throwable,java.lang.Throwable> getOnCompletableSubscribeError()
This operation is thread-safe.
public static void setOnObservableSubscribeError(Func1<java.lang.Throwable,java.lang.Throwable> onObservableSubscribeError)
This operation is thread-safe.
Calling with a null
parameter restores the default behavior:
the hook returns the same object.
onObservableSubscribeError
- the function that is called with the crash exception and should return
an exception.public static Func1<java.lang.Throwable,java.lang.Throwable> getOnObservableSubscribeError()
This operation is thread-safe.
public static void setOnObservableLift(Func1<Observable.Operator,Observable.Operator> onObservableLift)
This operation is thread-safe.
Calling with a null
parameter restores the default behavior:
the hook returns the same object.
onObservableLift
- the function that is called with original Operator and should
return an Operator instance.public static Func1<Observable.Operator,Observable.Operator> getOnObservableLift()
This operation is thread-safe.
public static void setOnSingleLift(Func1<Observable.Operator,Observable.Operator> onSingleLift)
This operation is thread-safe.
Calling with a null
parameter restores the default behavior:
the hook returns the same object.
onSingleLift
- the function that is called with original Operator and should
return an Operator instance.public static Func1<Observable.Operator,Observable.Operator> getOnSingleLift()
This operation is thread-safe.
public static void setOnCompletableLift(Func1<Completable.Operator,Completable.Operator> onCompletableLift)
This operation is thread-safe.
Calling with a null
parameter restores the default behavior:
the hook returns the same object.
onCompletableLift
- the function that is called with original Operator and should
return an Operator instance.public static Func1<Completable.Operator,Completable.Operator> getOnCompletableLift()
This operation is thread-safe.
public static Func1<Scheduler,Scheduler> getOnComputationScheduler()
This operation is thread-safe.
public static Action1<java.lang.Throwable> getOnError()
This operation is thread-safe.
public static Func1<Scheduler,Scheduler> getOnIOScheduler()
This operation is thread-safe.
public static Func1<Scheduler,Scheduler> getOnNewThreadScheduler()
This operation is thread-safe.
public static Func1<Observable.OnSubscribe,Observable.OnSubscribe> getOnObservableCreate()
This operation is thread-safe.
public static Func1<Action0,Action0> getOnScheduleAction()
This operation is thread-safe.
public static Func1<Single.OnSubscribe,Single.OnSubscribe> getOnSingleCreate()
This operation is thread-safe.
public static Func1<Completable.OnSubscribe,Completable.OnSubscribe> getOnCompletableCreate()
This operation is thread-safe.
public static Func2<Completable,Completable.OnSubscribe,Completable.OnSubscribe> getOnCompletableStart()
This operation is thread-safe.
public static Func2<Observable,Observable.OnSubscribe,Observable.OnSubscribe> getOnObservableStart()
This operation is thread-safe.
public static Func2<Single,Single.OnSubscribe,Single.OnSubscribe> getOnSingleStart()
This operation is thread-safe.
public static Func1<Subscription,Subscription> getOnObservableReturn()
This operation is thread-safe.
public static Func1<Subscription,Subscription> getOnSingleReturn()
This operation is thread-safe.
public static void resetAssemblyTracking()
public static void clearAssemblyTracking()
public static void enableAssemblyTracking()
public static void setOnGenericScheduledExecutorService(Func0<? extends java.util.concurrent.ScheduledExecutorService> factory)
This operation is thread-safe.
Calling with a null
parameter restores the default behavior:
create the default with Executors.newScheduledThreadPool(int, java.util.concurrent.ThreadFactory)
.
For the changes to take effect, the Schedulers has to be restarted.
factory
- the supplier that is called when the GenericScheduledExecutorService
is (re)startedpublic static Func0<? extends java.util.concurrent.ScheduledExecutorService> getOnGenericScheduledExecutorService()
This operation is thread-safe.