Top Description Fields Constructors Methods
rx.plugins

public final Class RxJavaHooks

extends Object
Class Inheritance
Imports
java.lang.Thread.UncaughtExceptionHandler, java.util.concurrent.ScheduledExecutorService, rx.*, rx.functions.*, rx.internal.operators.*

Utility 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.

Since
1.3

Field Summary

Modifier and TypeField and Description
pack-priv static volatile boolean
lockdown

Prevents changing the hook callbacks when set to true.

pack-priv static volatile Func1<Completable.OnSubscribe, Completable.OnSubscribe>
pack-priv static volatile Func1<Completable.Operator, Completable.Operator>
pack-priv static volatile Func2<Completable, Completable.OnSubscribe, Completable.OnSubscribe>
pack-priv static volatile Func1<Throwable, Throwable>
pack-priv static volatile Func1<Scheduler, Scheduler>
pack-priv static volatile Action1<Throwable>
pack-priv static volatile Func0<? extends ScheduledExecutorService>
pack-priv static volatile Func1<Scheduler, Scheduler>
pack-priv static volatile Func1<Scheduler, Scheduler>
pack-priv static volatile Func1<Observable.OnSubscribe<T>, Observable.OnSubscribe<T>>
pack-priv static volatile Func1<Observable.Operator<R, T>, Observable.Operator<R, T>>
pack-priv static volatile Func1<Subscription, Subscription>
pack-priv static volatile Func2<Observable<T>, Observable.OnSubscribe<T>, Observable.OnSubscribe<T>>
pack-priv static volatile Func1<Throwable, Throwable>
pack-priv static volatile Func1<Action0, Action0>
pack-priv static volatile Func1<Single.OnSubscribe<T>, Single.OnSubscribe<T>>
pack-priv static volatile Func1<Observable.Operator<R, T>, Observable.Operator<R, T>>
pack-priv static volatile Func1<Subscription, Subscription>
pack-priv static volatile Func2<Single<T>, Single.OnSubscribe<T>, Single.OnSubscribe<T>>
pack-priv static volatile Func1<Throwable, Throwable>

Constructor Summary

AccessConstructor and Description
private
RxJavaHooks()

Utility class.

Method Summary

Modifier and TypeMethod and Description
public 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.

public static void
clearAssemblyTracking()

Clears the assembly tracking hooks to their default pass-through behavior.

public 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.

public static Func1<Completable.OnSubscribe, Completable.OnSubscribe>

Returns:

the current hook function
getOnCompletableCreate
()

Returns the current Completable onCreate hook function or null if it is set to the default pass-through.

public static Func1<Completable.Operator, Completable.Operator>

Returns:

the current hook function
getOnCompletableLift
()

Returns the current Completable onLift hook function or null if it is set to the default pass-through.

public static Func2<Completable, Completable.OnSubscribe, Completable.OnSubscribe>

Returns:

the current hook function
getOnCompletableStart
()

Returns the current Completable onStart hook function or null if it is set to the default pass-through.

public static Func1<Throwable, Throwable>

Returns:

the current hook function
getOnCompletableSubscribeError
()

Returns the current Completable onSubscribeError hook function or null if it is set to the default pass-through.

public static Func1<Scheduler, Scheduler>

Returns:

the current hook function
getOnComputationScheduler
()

Returns the current computation scheduler hook function or null if it is set to the default pass-through.

public static Action1<Throwable>

Returns:

the current hook action
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.

public static Func0<? extends ScheduledExecutorService>

Returns:

the current factory function
getOnGenericScheduledExecutorService
()

Returns the current factory for creating ScheduledExecutorServices in GenericScheduledExecutorService utility.

public static Func1<Scheduler, Scheduler>

Returns:

the current hook function
getOnIOScheduler
()

Returns the current io scheduler hook function or null if it is set to the default pass-through.

public static Func1<Scheduler, Scheduler>

Returns:

the current hook function
getOnNewThreadScheduler
()

Returns the current new thread scheduler hook function or null if it is set to the default pass-through.

public static Func1<Observable.OnSubscribe<T>, Observable.OnSubscribe<T>>

Returns:

the current hook function
getOnObservableCreate
()

Returns the current Observable onCreate hook function or null if it is set to the default pass-through.

public static Func1<Observable.Operator<R, T>, Observable.Operator<R, T>>

Returns:

the current hook function
getOnObservableLift
()

Returns the current Observable onLift hook function or null if it is set to the default pass-through.

public static Func1<Subscription, Subscription>

Returns:

the current hook function
getOnObservableReturn
()

Returns the current Observable onReturn hook function or null if it is set to the default pass-through.

public static Func2<Observable<T>, Observable.OnSubscribe<T>, Observable.OnSubscribe<T>>

Returns:

the current hook function
getOnObservableStart
()

Returns the current Observable onStart hook function or null if it is set to the default pass-through.

public static Func1<Throwable, Throwable>

Returns:

the current hook function
getOnObservableSubscribeError
()

Returns the current Observable onSubscribeError hook function or null if it is set to the default pass-through.

public static Func1<Action0, Action0>

Returns:

the current hook function
getOnScheduleAction
()

Returns the current schedule action hook function or null if it is set to the default pass-through.

public static Func1<Single.OnSubscribe<T>, Single.OnSubscribe<T>>

Returns:

the current hook function
getOnSingleCreate
()

Returns the current Single onCreate hook function or null if it is set to the default pass-through.

public static Func1<Observable.Operator<R, T>, Observable.Operator<R, T>>

Returns:

the current hook function
getOnSingleLift
()

Returns the current Single onLift hook function or null if it is set to the default pass-through.

public static Func1<Subscription, Subscription>

Returns:

the current hook function
getOnSingleReturn
()

Returns the current Single onReturn hook function or null if it is set to the default pass-through.

public static Func2<Single<T>, Single.OnSubscribe<T>, Single.OnSubscribe<T>>

Returns:

the current hook function
getOnSingleStart
()

Returns the current Single onStart hook function or null if it is set to the default pass-through.

public static Func1<Throwable, Throwable>

Returns:

the current hook function
getOnSingleSubscribeError
()

Returns the current Single onSubscribeError hook function or null if it is set to the default pass-through.

pack-priv static void
init()

Initialize the hooks via delegating to RxJavaPlugins.

pack-priv static void
public static boolean

Returns:

true if the hooks can no longer be changed
isLockdown
()

Returns true if the hooks can no longer be changed.

public static void
lockdown()

Prevents changing the hooks.

public static Throwable

Returns:

the original error or alternative Throwable to be thrown
onCompletableError
(Throwable
the error
error
)

Hook to call if the Completable.subscribe() crashes for some reason.

public static <
the input value type
T
,
the output value type
R
>
Completable.Operator

Returns:

the original or alternative operator that will be subscribed to
onCompletableLift
(Completable.Operator
the original operator
operator
)

Hook to call before the child subscriber would subscribe to an Operator.

public static <
the value type
T
>
Completable.OnSubscribe

Returns:

the original or alternative action that will be subscribed to
onCompletableStart
(Completable
the parent Completable instance
instance
,
Completable.OnSubscribe
the original OnSubscribe action
onSubscribe
)

Hook to call before the child subscriber is subscribed to the OnSubscribe action.

public static Scheduler

Returns:

the default of alternative scheduler
onComputationScheduler
(Scheduler
the default computation scheduler
scheduler
)

Hook to call when the Schedulers.computation() is called.

public static <
the value type
T
>
Observable.OnSubscribe<T>

Returns:

the original or replacement OnSubscribe instance
onCreate
(Observable.OnSubscribe<T>
the original OnSubscribe logic
onSubscribe
)

Hook to call when an Observable is created.

public static <
the value type
T
>
Single.OnSubscribe<T>

Returns:

the original or replacement OnSubscribe instance
onCreate
(Single.OnSubscribe<T>
the original OnSubscribe logic
onSubscribe
)

Hook to call when a Single is created.

public static Completable.OnSubscribe

Returns:

the original or replacement OnSubscribe instance
onCreate
(Completable.OnSubscribe
the original OnSubscribe logic
onSubscribe
)

Hook to call when a Completable is created.

public static void
onError(Throwable
the exception to handle
ex
)

Consume undeliverable Throwables (acts as a global catch).

public static Scheduler

Returns:

the default of alternative scheduler
onIOScheduler
(Scheduler
the default io scheduler
scheduler
)

Hook to call when the Schedulers.io() is called.

public static Scheduler

Returns:

the default of alternative scheduler
onNewThreadScheduler
(Scheduler
the default new thread scheduler
scheduler
)

Hook to call when the Schedulers.newThread() is called.

public static Throwable

Returns:

the original error or alternative Throwable to be thrown
onObservableError
(Throwable
the error
error
)

Hook to call if the Observable.subscribe() crashes for some reason.

public static <
the input value type
T
,
the output value type
R
>
Observable.Operator<R, T>

Returns:

the original or alternative operator that will be subscribed to
onObservableLift
(Observable.Operator<R, T>
the original operator
operator
)

Hook to call before the child subscriber would subscribe to an Operator.

public static Subscription

Returns:

the original or alternative subscription that will be returned
onObservableReturn
(Subscription
the original subscription
subscription
)

Hook to call before the Observable.subscribe() method is about to return a Subscription.

public static <
the value type
T
>
Observable.OnSubscribe<T>

Returns:

the original or alternative action that will be subscribed to
onObservableStart
(Observable<T>
the parent Observable instance
instance
,
Observable.OnSubscribe<T>
the original OnSubscribe action
onSubscribe
)

Hook to call before the child subscriber is subscribed to the OnSubscribe action.

public static Action0

Returns:

the original or alternative action
onScheduledAction
(Action0
the original action
action
)

Hook to call before the action is scheduled, allows decorating the original action.

public static Throwable

Returns:

the original error or alternative Throwable to be thrown
onSingleError
(Throwable
the error
error
)

Hook to call if the Single.subscribe() crashes for some reason.

public static <
the input value type
T
,
the output value type
R
>
Observable.Operator<R, T>

Returns:

the original or alternative operator that will be subscribed to
onSingleLift
(Observable.Operator<R, T>
the original operator
operator
)

Hook to call before the child subscriber would subscribe to an Operator.

public static Subscription

Returns:

the original or alternative subscription that will be returned
onSingleReturn
(Subscription
the original subscription
subscription
)

Hook to call before the Single.subscribe() method is about to return a Subscription.

public static <
the value type
T
>
Single.OnSubscribe<T>

Returns:

the original or alternative action that will be subscribed to
onSingleStart
(Single<T>
the parent Single instance
instance
,
Single.OnSubscribe<T>
the original OnSubscribe action
onSubscribe
)

Hook to call before the child subscriber is subscribed to the OnSubscribe action.

public static void
reset()

Reset all hook callbacks to those of the current RxJavaPlugins handlers.

public static void
resetAssemblyTracking()

Resets the assembly tracking hooks to their default delegates to RxJavaPlugins.

public static void
setOnCompletableCreate(Func1<Completable.OnSubscribe, Completable.OnSubscribe>
the function that takes the original CompletableOnSubscribe and should return a CompletableOnSubscribe.
onCompletableCreate
)

Sets the Completable's onCreate hook function unless a lockdown is in effect.

public static void
setOnCompletableLift(Func1<Completable.Operator, Completable.Operator>
the function that is called with original Operator and should return an Operator instance.
onCompletableLift
)

Sets a hook function that is called with an operator when a Completable operator built with lift() gets subscribed to.

public static void
setOnCompletableStart(Func2<Completable, Completable.OnSubscribe, Completable.OnSubscribe>
the function that is called with the current Completable instance, its CompletableOnSubscribe function and should return a CompletableOnSubscribe function that gets actually subscribed to.
onCompletableStart
)

Sets the hook function that is called when a subscriber subscribes to a Completable unless a lockdown is in effect.

public static void
setOnCompletableSubscribeError(Func1<Throwable, Throwable>
the function that is called with the crash exception and should return an exception.
onCompletableSubscribeError
)

Sets a hook function that is called when the Completable.subscribe() call fails with an exception.

public static void
setOnComputationScheduler(Func1<Scheduler, Scheduler>
the function that receives the original computation scheduler and should return a scheduler.
onComputationScheduler
)

Sets the hook function for returning a scheduler when the Schedulers.computation() is called unless a lockdown is in effect.

public static void
setOnError(Action1<Throwable>
the action that will receive undeliverable Throwables
onError
)

Sets the global error consumer action unless a lockdown is in effect.

public static void
setOnGenericScheduledExecutorService(Func0<? extends ScheduledExecutorService>
the supplier that is called when the GenericScheduledExecutorService is (re)started
factory
)

Sets the hook function for returning a ScheduledExecutorService used by the GenericScheduledExecutorService for background tasks.

public static void
setOnIOScheduler(Func1<Scheduler, Scheduler>
the function that receives the original io scheduler and should return a scheduler.
onIOScheduler
)

Sets the hook function for returning a scheduler when the Schedulers.io() is called unless a lockdown is in effect.

public static void
setOnNewThreadScheduler(Func1<Scheduler, Scheduler>
the function that receives the original new thread scheduler and should return a scheduler.
onNewThreadScheduler
)

Sets the hook function for returning a scheduler when the Schedulers.newThread() is called unless a lockdown is in effect.

public static void
setOnObservableCreate(Func1<Observable.OnSubscribe<T>, Observable.OnSubscribe<T>>
the function that takes the original OnSubscribe and should return a OnSubscribe.
onObservableCreate
)

Sets the Observable onCreate hook function unless a lockdown is in effect.

public static void
setOnObservableLift(Func1<Observable.Operator<R, T>, Observable.Operator<R, T>>
the function that is called with original Operator and should return an Operator instance.
onObservableLift
)

Sets a hook function that is called with an operator when an Observable operator built with lift() gets subscribed to.

public static void
setOnObservableReturn(Func1<Subscription, Subscription>
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().
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.

public static void
setOnObservableStart(Func2<Observable<T>, Observable.OnSubscribe<T>, Observable.OnSubscribe<T>>
the function that is called with the current Observable instance, its OnSubscribe function and should return a OnSubscribe function that gets actually subscribed to.
onObservableStart
)

Sets the hook function that is called when a subscriber subscribes to a Observable unless a lockdown is in effect.

public static void
setOnObservableSubscribeError(Func1<Throwable, Throwable>
the function that is called with the crash exception and should return an exception.
onObservableSubscribeError
)

Sets a hook function that is called when the Observable.subscribe() call fails with an exception.

public static void
setOnScheduleAction(Func1<Action0, Action0>
the function that receives the original action and should return an Action0.
onScheduleAction
)

Sets the hook function that is called before an action is scheduled, allowing decorating that function, unless a lockdown is in effect.

public static void
setOnSingleCreate(Func1<Single.OnSubscribe<T>, Single.OnSubscribe<T>>
the function that takes the original OnSubscribe and should return a OnSubscribe.
onSingleCreate
)

Sets the Single onCreate hook function unless a lockdown is in effect.

public static void
setOnSingleLift(Func1<Observable.Operator<R, T>, Observable.Operator<R, T>>
the function that is called with original Operator and should return an Operator instance.
onSingleLift
)

Sets a hook function that is called with an operator when an Single operator built with lift() gets subscribed to.

public static void
setOnSingleReturn(Func1<Subscription, Subscription>
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().
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.

public static void
setOnSingleStart(Func2<Single<T>, Single.OnSubscribe<T>, Single.OnSubscribe<T>>
the function that is called with the current Single instance, its OnSubscribe function and should return a OnSubscribe function that gets actually subscribed to.
onSingleStart
)

Sets the hook function that is called when a subscriber subscribes to a Single unless a lockdown is in effect.

public static void
setOnSingleSubscribeError(Func1<Throwable, Throwable>
the function that is called with the crash exception and should return an exception.
onSingleSubscribeError
)

Sets a hook function that is called when the Single.subscribe() call fails with an exception.

pack-priv static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait