public final class RxJavaPlugins extends Object
Modifier and Type | Method and Description |
---|---|
static Scheduler |
createComputationScheduler(ThreadFactory threadFactory)
Create an instance of the default
Scheduler used for Schedulers.computation()
except using threadFactory for thread creation. |
static Scheduler |
createIoScheduler(ThreadFactory threadFactory)
Create an instance of the default
Scheduler used for Schedulers.io()
except using threadFactory for thread creation. |
static Scheduler |
createNewThreadScheduler(ThreadFactory threadFactory)
Create an instance of the default
Scheduler used for Schedulers.newThread()
except using threadFactory for thread creation. |
static Scheduler |
createSingleScheduler(ThreadFactory threadFactory)
Create an instance of the default
Scheduler used for Schedulers.single()
except using threadFactory for thread creation. |
static Function<? super Scheduler,? extends Scheduler> |
getComputationSchedulerHandler()
Returns the current hook function.
|
static Consumer<? super Throwable> |
getErrorHandler()
Returns the a hook consumer.
|
static Function<? super Supplier<Scheduler>,? extends Scheduler> |
getInitComputationSchedulerHandler()
Returns the current hook function.
|
static Function<? super Supplier<Scheduler>,? extends Scheduler> |
getInitIoSchedulerHandler()
Returns the current hook function.
|
static Function<? super Supplier<Scheduler>,? extends Scheduler> |
getInitNewThreadSchedulerHandler()
Returns the current hook function.
|
static Function<? super Supplier<Scheduler>,? extends Scheduler> |
getInitSingleSchedulerHandler()
Returns the current hook function.
|
static Function<? super Scheduler,? extends Scheduler> |
getIoSchedulerHandler()
Returns the current hook function.
|
static Function<? super Scheduler,? extends Scheduler> |
getNewThreadSchedulerHandler()
Returns the current hook function.
|
static BooleanSupplier |
getOnBeforeBlocking()
Returns the current blocking handler or null if no custom handler
is set.
|
static Function<? super Completable,? extends Completable> |
getOnCompletableAssembly()
Returns the current hook function.
|
static BiFunction<? super Completable,? super CompletableObserver,? extends CompletableObserver> |
getOnCompletableSubscribe()
Returns the current hook function.
|
static Function<? super ConnectableFlowable,? extends ConnectableFlowable> |
getOnConnectableFlowableAssembly()
Returns the current hook function.
|
static Function<? super ConnectableObservable,? extends ConnectableObservable> |
getOnConnectableObservableAssembly()
Returns the current hook function.
|
static Function<? super Flowable,? extends Flowable> |
getOnFlowableAssembly()
Returns the current hook function.
|
static BiFunction<? super Flowable,? super Subscriber,? extends Subscriber> |
getOnFlowableSubscribe()
Returns the current hook function.
|
static Function<? super Maybe,? extends Maybe> |
getOnMaybeAssembly()
Returns the current hook function.
|
static BiFunction<? super Maybe,? super MaybeObserver,? extends MaybeObserver> |
getOnMaybeSubscribe()
Returns the current hook function.
|
static Function<? super Observable,? extends Observable> |
getOnObservableAssembly()
Returns the current hook function.
|
static BiFunction<? super Observable,? super Observer,? extends Observer> |
getOnObservableSubscribe()
Returns the current hook function.
|
static Function<? super ParallelFlowable,? extends ParallelFlowable> |
getOnParallelAssembly()
Returns the current hook function.
|
static Function<? super Single,? extends Single> |
getOnSingleAssembly()
Returns the current hook function.
|
static BiFunction<? super Single,? super SingleObserver,? extends SingleObserver> |
getOnSingleSubscribe()
Returns the current hook function.
|
static Function<? super Runnable,? extends Runnable> |
getScheduleHandler()
Returns the current hook function.
|
static Function<? super Scheduler,? extends Scheduler> |
getSingleSchedulerHandler()
Returns the current hook function.
|
static Scheduler |
initComputationScheduler(Supplier<Scheduler> defaultScheduler)
Calls the associated hook function.
|
static Scheduler |
initIoScheduler(Supplier<Scheduler> defaultScheduler)
Calls the associated hook function.
|
static Scheduler |
initNewThreadScheduler(Supplier<Scheduler> defaultScheduler)
Calls the associated hook function.
|
static Scheduler |
initSingleScheduler(Supplier<Scheduler> defaultScheduler)
Calls the associated hook function.
|
static boolean |
isFailOnNonBlockingScheduler()
Returns true if the blockingX operators fail
with an IllegalStateException on a non-blocking scheduler
such as computation or single.
|
static boolean |
isLockdown()
Returns true if the plugins were locked down.
|
static void |
lockdown()
Prevents changing the plugins from then on.
|
static Completable |
onAssembly(Completable source)
Calls the associated hook function.
|
static <T> ConnectableFlowable<T> |
onAssembly(ConnectableFlowable<T> source)
Calls the associated hook function.
|
static <T> ConnectableObservable<T> |
onAssembly(ConnectableObservable<T> source)
Calls the associated hook function.
|
static <T> Flowable<T> |
onAssembly(Flowable<T> source)
Calls the associated hook function.
|
static <T> Maybe<T> |
onAssembly(Maybe<T> source)
Calls the associated hook function.
|
static <T> Observable<T> |
onAssembly(Observable<T> source)
Calls the associated hook function.
|
static <T> ParallelFlowable<T> |
onAssembly(ParallelFlowable<T> source)
Calls the associated hook function.
|
static <T> Single<T> |
onAssembly(Single<T> source)
Calls the associated hook function.
|
static boolean |
onBeforeBlocking()
Called before an operator attempts a blocking operation
such as awaiting a condition or signal
and should return true to indicate the operator
should not block but throw an IllegalArgumentException.
|
static Scheduler |
onComputationScheduler(Scheduler defaultScheduler)
Calls the associated hook function.
|
static void |
onError(Throwable error)
Called when an undeliverable error occurs.
|
static Scheduler |
onIoScheduler(Scheduler defaultScheduler)
Calls the associated hook function.
|
static Scheduler |
onNewThreadScheduler(Scheduler defaultScheduler)
Calls the associated hook function.
|
static Runnable |
onSchedule(Runnable run)
Called when a task is scheduled.
|
static Scheduler |
onSingleScheduler(Scheduler defaultScheduler)
Calls the associated hook function.
|
static CompletableObserver |
onSubscribe(Completable source,
CompletableObserver observer)
Calls the associated hook function.
|
static <T> Subscriber<? super T> |
onSubscribe(Flowable<T> source,
Subscriber<? super T> subscriber)
Calls the associated hook function.
|
static <T> MaybeObserver<? super T> |
onSubscribe(Maybe<T> source,
MaybeObserver<? super T> observer)
Calls the associated hook function.
|
static <T> Observer<? super T> |
onSubscribe(Observable<T> source,
Observer<? super T> observer)
Calls the associated hook function.
|
static <T> SingleObserver<? super T> |
onSubscribe(Single<T> source,
SingleObserver<? super T> observer)
Calls the associated hook function.
|
static void |
reset()
Removes all handlers and resets to default behavior.
|
static void |
setComputationSchedulerHandler(Function<? super Scheduler,? extends Scheduler> handler)
Sets the specific hook function.
|
static void |
setErrorHandler(Consumer<? super Throwable> handler)
Sets the specific hook function.
|
static void |
setFailOnNonBlockingScheduler(boolean enable)
Enables or disables the blockingX operators to fail
with an IllegalStateException on a non-blocking
scheduler such as computation or single.
|
static void |
setInitComputationSchedulerHandler(Function<? super Supplier<Scheduler>,? extends Scheduler> handler)
Sets the specific hook function.
|
static void |
setInitIoSchedulerHandler(Function<? super Supplier<Scheduler>,? extends Scheduler> handler)
Sets the specific hook function.
|
static void |
setInitNewThreadSchedulerHandler(Function<? super Supplier<Scheduler>,? extends Scheduler> handler)
Sets the specific hook function.
|
static void |
setInitSingleSchedulerHandler(Function<? super Supplier<Scheduler>,? extends Scheduler> handler)
Sets the specific hook function.
|
static void |
setIoSchedulerHandler(Function<? super Scheduler,? extends Scheduler> handler)
Sets the specific hook function.
|
static void |
setNewThreadSchedulerHandler(Function<? super Scheduler,? extends Scheduler> handler)
Sets the specific hook function.
|
static void |
setOnBeforeBlocking(BooleanSupplier handler)
Set the handler that is called when an operator attempts a blocking
await; the handler should return true to prevent the blocking
and to signal an IllegalStateException instead.
|
static void |
setOnCompletableAssembly(Function<? super Completable,? extends Completable> onCompletableAssembly)
Sets the specific hook function.
|
static void |
setOnCompletableSubscribe(BiFunction<? super Completable,? super CompletableObserver,? extends CompletableObserver> onCompletableSubscribe)
Sets the specific hook function.
|
static void |
setOnConnectableFlowableAssembly(Function<? super ConnectableFlowable,? extends ConnectableFlowable> onConnectableFlowableAssembly)
Sets the specific hook function.
|
static void |
setOnConnectableObservableAssembly(Function<? super ConnectableObservable,? extends ConnectableObservable> onConnectableObservableAssembly)
Sets the specific hook function.
|
static void |
setOnFlowableAssembly(Function<? super Flowable,? extends Flowable> onFlowableAssembly)
Sets the specific hook function.
|
static void |
setOnFlowableSubscribe(BiFunction<? super Flowable,? super Subscriber,? extends Subscriber> onFlowableSubscribe)
Sets the specific hook function.
|
static void |
setOnMaybeAssembly(Function<? super Maybe,? extends Maybe> onMaybeAssembly)
Sets the specific hook function.
|
static void |
setOnMaybeSubscribe(BiFunction<? super Maybe,MaybeObserver,? extends MaybeObserver> onMaybeSubscribe)
Sets the specific hook function.
|
static void |
setOnObservableAssembly(Function<? super Observable,? extends Observable> onObservableAssembly)
Sets the specific hook function.
|
static void |
setOnObservableSubscribe(BiFunction<? super Observable,? super Observer,? extends Observer> onObservableSubscribe)
Sets the specific hook function.
|
static void |
setOnParallelAssembly(Function<? super ParallelFlowable,? extends ParallelFlowable> handler)
Sets the specific hook function.
|
static void |
setOnSingleAssembly(Function<? super Single,? extends Single> onSingleAssembly)
Sets the specific hook function.
|
static void |
setOnSingleSubscribe(BiFunction<? super Single,? super SingleObserver,? extends SingleObserver> onSingleSubscribe)
Sets the specific hook function.
|
static void |
setScheduleHandler(Function<? super Runnable,? extends Runnable> handler)
Sets the specific hook function.
|
static void |
setSingleSchedulerHandler(Function<? super Scheduler,? extends Scheduler> handler)
Sets the specific hook function.
|
public static void lockdown()
This allows container-like environments to prevent clients messing with plugins.
public static boolean isLockdown()
public static void setFailOnNonBlockingScheduler(boolean enable)
History: 2.0.5 - experimental
enable
- enable or disable the featurepublic static boolean isFailOnNonBlockingScheduler()
History: 2.0.5 - experimental
@Nullable public static Function<? super Scheduler,? extends Scheduler> getComputationSchedulerHandler()
@Nullable public static Consumer<? super Throwable> getErrorHandler()
@Nullable public static Function<? super Supplier<Scheduler>,? extends Scheduler> getInitComputationSchedulerHandler()
@Nullable public static Function<? super Supplier<Scheduler>,? extends Scheduler> getInitIoSchedulerHandler()
@Nullable public static Function<? super Supplier<Scheduler>,? extends Scheduler> getInitNewThreadSchedulerHandler()
@Nullable public static Function<? super Supplier<Scheduler>,? extends Scheduler> getInitSingleSchedulerHandler()
@Nullable public static Function<? super Scheduler,? extends Scheduler> getIoSchedulerHandler()
@Nullable public static Function<? super Scheduler,? extends Scheduler> getNewThreadSchedulerHandler()
@Nullable public static Function<? super Runnable,? extends Runnable> getScheduleHandler()
@Nullable public static Function<? super Scheduler,? extends Scheduler> getSingleSchedulerHandler()
@NonNull public static Scheduler initComputationScheduler(@NonNull Supplier<Scheduler> defaultScheduler)
defaultScheduler
- a Supplier
which returns the hook's input valueNullPointerException
- if the supplier parameter or its result are null@NonNull public static Scheduler initIoScheduler(@NonNull Supplier<Scheduler> defaultScheduler)
defaultScheduler
- a Supplier
which returns the hook's input valueNullPointerException
- if the supplier parameter or its result are null@NonNull public static Scheduler initNewThreadScheduler(@NonNull Supplier<Scheduler> defaultScheduler)
defaultScheduler
- a Supplier
which returns the hook's input valueNullPointerException
- if the supplier parameter or its result are null@NonNull public static Scheduler initSingleScheduler(@NonNull Supplier<Scheduler> defaultScheduler)
defaultScheduler
- a Supplier
which returns the hook's input valueNullPointerException
- if the supplier parameter or its result are null@NonNull public static Scheduler onComputationScheduler(@NonNull Scheduler defaultScheduler)
defaultScheduler
- the hook's input valuepublic static void onError(@NonNull Throwable error)
Undeliverable errors are those Observer.onError()
invocations that are not allowed to happen on
the given consumer type (Observer
, Subscriber
, etc.) due to protocol restrictions
because the consumer has either disposed/cancelled its Disposable
/Subscription
or
has already terminated with an onError()
or onComplete()
signal.
By default, this global error handler prints the stacktrace via Throwable.printStackTrace()
and calls Thread.UncaughtExceptionHandler.uncaughtException(Thread, Throwable)
on the current thread.
Note that on some platforms, the platform runtime terminates the current application with an error if such
uncaught exceptions happen. In this case, it is recommended the application installs a global error
handler via the setErrorHandler(Consumer)
plugin method.
error
- the error to reportgetErrorHandler()
,
setErrorHandler(Consumer)
,
Error handling Wiki@NonNull public static Scheduler onIoScheduler(@NonNull Scheduler defaultScheduler)
defaultScheduler
- the hook's input value@NonNull public static Scheduler onNewThreadScheduler(@NonNull Scheduler defaultScheduler)
defaultScheduler
- the hook's input value@NonNull public static Runnable onSchedule(@NonNull Runnable run)
run
- the runnable instance@NonNull public static Scheduler onSingleScheduler(@NonNull Scheduler defaultScheduler)
defaultScheduler
- the hook's input valuepublic static void reset()
public static void setComputationSchedulerHandler(@Nullable Function<? super Scheduler,? extends Scheduler> handler)
handler
- the hook function to set, null allowedpublic static void setErrorHandler(@Nullable Consumer<? super Throwable> handler)
handler
- the hook function to set, null allowedpublic static void setInitComputationSchedulerHandler(@Nullable Function<? super Supplier<Scheduler>,? extends Scheduler> handler)
handler
- the hook function to set, null allowed, but the function may not return nullpublic static void setInitIoSchedulerHandler(@Nullable Function<? super Supplier<Scheduler>,? extends Scheduler> handler)
handler
- the hook function to set, null allowed, but the function may not return nullpublic static void setInitNewThreadSchedulerHandler(@Nullable Function<? super Supplier<Scheduler>,? extends Scheduler> handler)
handler
- the hook function to set, null allowed, but the function may not return nullpublic static void setInitSingleSchedulerHandler(@Nullable Function<? super Supplier<Scheduler>,? extends Scheduler> handler)
handler
- the hook function to set, null allowed, but the function may not return nullpublic static void setIoSchedulerHandler(@Nullable Function<? super Scheduler,? extends Scheduler> handler)
handler
- the hook function to set, null allowedpublic static void setNewThreadSchedulerHandler(@Nullable Function<? super Scheduler,? extends Scheduler> handler)
handler
- the hook function to set, null allowedpublic static void setScheduleHandler(@Nullable Function<? super Runnable,? extends Runnable> handler)
handler
- the hook function to set, null allowedpublic static void setSingleSchedulerHandler(@Nullable Function<? super Scheduler,? extends Scheduler> handler)
handler
- the hook function to set, null allowed@Nullable public static Function<? super Completable,? extends Completable> getOnCompletableAssembly()
@Nullable public static BiFunction<? super Completable,? super CompletableObserver,? extends CompletableObserver> getOnCompletableSubscribe()
@Nullable public static Function<? super Flowable,? extends Flowable> getOnFlowableAssembly()
@Nullable public static Function<? super ConnectableFlowable,? extends ConnectableFlowable> getOnConnectableFlowableAssembly()
@Nullable public static BiFunction<? super Flowable,? super Subscriber,? extends Subscriber> getOnFlowableSubscribe()
@Nullable public static BiFunction<? super Maybe,? super MaybeObserver,? extends MaybeObserver> getOnMaybeSubscribe()
@Nullable public static Function<? super Maybe,? extends Maybe> getOnMaybeAssembly()
@Nullable public static Function<? super Single,? extends Single> getOnSingleAssembly()
@Nullable public static BiFunction<? super Single,? super SingleObserver,? extends SingleObserver> getOnSingleSubscribe()
@Nullable public static Function<? super Observable,? extends Observable> getOnObservableAssembly()
@Nullable public static Function<? super ConnectableObservable,? extends ConnectableObservable> getOnConnectableObservableAssembly()
@Nullable public static BiFunction<? super Observable,? super Observer,? extends Observer> getOnObservableSubscribe()
public static void setOnCompletableAssembly(@Nullable Function<? super Completable,? extends Completable> onCompletableAssembly)
onCompletableAssembly
- the hook function to set, null allowedpublic static void setOnCompletableSubscribe(@Nullable BiFunction<? super Completable,? super CompletableObserver,? extends CompletableObserver> onCompletableSubscribe)
onCompletableSubscribe
- the hook function to set, null allowedpublic static void setOnFlowableAssembly(@Nullable Function<? super Flowable,? extends Flowable> onFlowableAssembly)
onFlowableAssembly
- the hook function to set, null allowedpublic static void setOnMaybeAssembly(@Nullable Function<? super Maybe,? extends Maybe> onMaybeAssembly)
onMaybeAssembly
- the hook function to set, null allowedpublic static void setOnConnectableFlowableAssembly(@Nullable Function<? super ConnectableFlowable,? extends ConnectableFlowable> onConnectableFlowableAssembly)
onConnectableFlowableAssembly
- the hook function to set, null allowedpublic static void setOnFlowableSubscribe(@Nullable BiFunction<? super Flowable,? super Subscriber,? extends Subscriber> onFlowableSubscribe)
onFlowableSubscribe
- the hook function to set, null allowedpublic static void setOnMaybeSubscribe(@Nullable BiFunction<? super Maybe,MaybeObserver,? extends MaybeObserver> onMaybeSubscribe)
onMaybeSubscribe
- the hook function to set, null allowedpublic static void setOnObservableAssembly(@Nullable Function<? super Observable,? extends Observable> onObservableAssembly)
onObservableAssembly
- the hook function to set, null allowedpublic static void setOnConnectableObservableAssembly(@Nullable Function<? super ConnectableObservable,? extends ConnectableObservable> onConnectableObservableAssembly)
onConnectableObservableAssembly
- the hook function to set, null allowedpublic static void setOnObservableSubscribe(@Nullable BiFunction<? super Observable,? super Observer,? extends Observer> onObservableSubscribe)
onObservableSubscribe
- the hook function to set, null allowedpublic static void setOnSingleAssembly(@Nullable Function<? super Single,? extends Single> onSingleAssembly)
onSingleAssembly
- the hook function to set, null allowedpublic static void setOnSingleSubscribe(@Nullable BiFunction<? super Single,? super SingleObserver,? extends SingleObserver> onSingleSubscribe)
onSingleSubscribe
- the hook function to set, null allowed@NonNull public static <T> Subscriber<? super T> onSubscribe(@NonNull Flowable<T> source, @NonNull Subscriber<? super T> subscriber)
T
- the value typesource
- the hook's input valuesubscriber
- the subscriber@NonNull public static <T> Observer<? super T> onSubscribe(@NonNull Observable<T> source, @NonNull Observer<? super T> observer)
T
- the value typesource
- the hook's input valueobserver
- the observer@NonNull public static <T> SingleObserver<? super T> onSubscribe(@NonNull Single<T> source, @NonNull SingleObserver<? super T> observer)
T
- the value typesource
- the hook's input valueobserver
- the observer@NonNull public static CompletableObserver onSubscribe(@NonNull Completable source, @NonNull CompletableObserver observer)
source
- the hook's input valueobserver
- the observer@NonNull public static <T> MaybeObserver<? super T> onSubscribe(@NonNull Maybe<T> source, @NonNull MaybeObserver<? super T> observer)
T
- the value typesource
- the hook's input valueobserver
- the subscriber@NonNull public static <T> Maybe<T> onAssembly(@NonNull Maybe<T> source)
T
- the value typesource
- the hook's input value@NonNull public static <T> Flowable<T> onAssembly(@NonNull Flowable<T> source)
T
- the value typesource
- the hook's input value@NonNull public static <T> ConnectableFlowable<T> onAssembly(@NonNull ConnectableFlowable<T> source)
T
- the value typesource
- the hook's input value@NonNull public static <T> Observable<T> onAssembly(@NonNull Observable<T> source)
T
- the value typesource
- the hook's input value@NonNull public static <T> ConnectableObservable<T> onAssembly(@NonNull ConnectableObservable<T> source)
T
- the value typesource
- the hook's input value@NonNull public static <T> Single<T> onAssembly(@NonNull Single<T> source)
T
- the value typesource
- the hook's input value@NonNull public static Completable onAssembly(@NonNull Completable source)
source
- the hook's input valuepublic static void setOnParallelAssembly(@Nullable Function<? super ParallelFlowable,? extends ParallelFlowable> handler)
History: 2.0.6 - experimental; 2.1 - beta
handler
- the hook function to set, null allowed@Nullable public static Function<? super ParallelFlowable,? extends ParallelFlowable> getOnParallelAssembly()
History: 2.0.6 - experimental; 2.1 - beta
@NonNull public static <T> ParallelFlowable<T> onAssembly(@NonNull ParallelFlowable<T> source)
History: 2.0.6 - experimental; 2.1 - beta
T
- the value type of the sourcesource
- the hook's input valuepublic static boolean onBeforeBlocking()
History: 2.0.5 - experimental
setFailOnNonBlockingScheduler(boolean)
public static void setOnBeforeBlocking(@Nullable BooleanSupplier handler)
History: 2.0.5 - experimental
handler
- the handler to set, null resets to the default handler
that always returns falseonBeforeBlocking()
@Nullable public static BooleanSupplier getOnBeforeBlocking()
History: 2.0.5 - experimental
@NonNull public static Scheduler createComputationScheduler(@NonNull ThreadFactory threadFactory)
Scheduler
used for Schedulers.computation()
except using threadFactory
for thread creation.
History: 2.0.5 - experimental
threadFactory
- thread factory to use for creating worker threads. Note that this takes precedence over any
system properties for configuring new thread creation. Cannot be null.@NonNull public static Scheduler createIoScheduler(@NonNull ThreadFactory threadFactory)
Scheduler
used for Schedulers.io()
except using threadFactory
for thread creation.
History: 2.0.5 - experimental
threadFactory
- thread factory to use for creating worker threads. Note that this takes precedence over any
system properties for configuring new thread creation. Cannot be null.@NonNull public static Scheduler createNewThreadScheduler(@NonNull ThreadFactory threadFactory)
Scheduler
used for Schedulers.newThread()
except using threadFactory
for thread creation.
History: 2.0.5 - experimental
threadFactory
- thread factory to use for creating worker threads. Note that this takes precedence over any
system properties for configuring new thread creation. Cannot be null.@NonNull public static Scheduler createSingleScheduler(@NonNull ThreadFactory threadFactory)
Scheduler
used for Schedulers.single()
except using threadFactory
for thread creation.
History: 2.0.5 - experimental
threadFactory
- thread factory to use for creating worker threads. Note that this takes precedence over any
system properties for configuring new thread creation. Cannot be null.