Class RxJavaPlugins
- java.lang.Object
-
- io.reactivex.rxjava3.plugins.RxJavaPlugins
-
public final class RxJavaPlugins extends java.lang.Object
Utility class to inject handlers to certain standard RxJava operations.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static @Nullable Consumer<? super java.lang.Throwable>
errorHandler
(package private) static boolean
failNonBlockingScheduler
If true, attempting to run a blockingX operation on a (by default) computation or single scheduler will throw an IllegalStateException.(package private) static boolean
lockdown
Prevents changing the plugins.(package private) static @Nullable BooleanSupplier
onBeforeBlocking
(package private) static @Nullable Function<? super Completable,? extends Completable>
onCompletableAssembly
(package private) static @Nullable BiFunction<? super Completable,? super CompletableObserver,? extends CompletableObserver>
onCompletableSubscribe
(package private) static @Nullable Function<? super Scheduler,? extends Scheduler>
onComputationHandler
(package private) static @Nullable Function<? super ConnectableFlowable,? extends ConnectableFlowable>
onConnectableFlowableAssembly
(package private) static @Nullable Function<? super ConnectableObservable,? extends ConnectableObservable>
onConnectableObservableAssembly
(package private) static @Nullable Function<? super Flowable,? extends Flowable>
onFlowableAssembly
(package private) static @Nullable BiFunction<? super Flowable,? super org.reactivestreams.Subscriber,? extends org.reactivestreams.Subscriber>
onFlowableSubscribe
(package private) static @Nullable Function<? super Supplier<Scheduler>,? extends Scheduler>
onInitComputationHandler
(package private) static @Nullable Function<? super Supplier<Scheduler>,? extends Scheduler>
onInitIoHandler
(package private) static @Nullable Function<? super Supplier<Scheduler>,? extends Scheduler>
onInitNewThreadHandler
(package private) static @Nullable Function<? super Supplier<Scheduler>,? extends Scheduler>
onInitSingleHandler
(package private) static @Nullable Function<? super Scheduler,? extends Scheduler>
onIoHandler
(package private) static @Nullable Function<? super Maybe,? extends Maybe>
onMaybeAssembly
(package private) static @Nullable BiFunction<? super Maybe,? super MaybeObserver,? extends MaybeObserver>
onMaybeSubscribe
(package private) static @Nullable Function<? super Scheduler,? extends Scheduler>
onNewThreadHandler
(package private) static @Nullable Function<? super Observable,? extends Observable>
onObservableAssembly
(package private) static @Nullable BiFunction<? super Observable,? super Observer,? extends Observer>
onObservableSubscribe
(package private) static @Nullable Function<? super ParallelFlowable,? extends ParallelFlowable>
onParallelAssembly
(package private) static @Nullable BiFunction<? super ParallelFlowable,? super org.reactivestreams.Subscriber[],? extends org.reactivestreams.Subscriber[]>
onParallelSubscribe
(package private) static @Nullable Function<? super java.lang.Runnable,? extends java.lang.Runnable>
onScheduleHandler
(package private) static @Nullable Function<? super Single,? extends Single>
onSingleAssembly
(package private) static @Nullable Function<? super Scheduler,? extends Scheduler>
onSingleHandler
(package private) static @Nullable BiFunction<? super Single,? super SingleObserver,? extends SingleObserver>
onSingleSubscribe
-
Constructor Summary
Constructors Modifier Constructor Description private
RxJavaPlugins()
Helper class, no instances.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static <@NonNull T,@NonNull U,@NonNull R>
Rapply(@NonNull BiFunction<@NonNull T,@NonNull U,@NonNull R> f, @NonNull T t, @NonNull U u)
Wraps the call to the function in try-catch and propagates thrown checked exceptions as RuntimeException.(package private) static <@NonNull T,@NonNull R>
Rapply(@NonNull Function<@NonNull T,@NonNull R> f, @NonNull T t)
Wraps the call to the function in try-catch and propagates thrown checked exceptions as RuntimeException.(package private) static @NonNull Scheduler
applyRequireNonNull(@NonNull Function<? super Supplier<Scheduler>,? extends Scheduler> f, Supplier<Scheduler> s)
Wraps the call to the Scheduler creation function in try-catch and propagates thrown checked exceptions as RuntimeException and enforces that result is not null.(package private) static @NonNull Scheduler
callRequireNonNull(@NonNull Supplier<Scheduler> s)
Wraps the call to the Scheduler creation supplier in try-catch and propagates thrown checked exceptions as RuntimeException and enforces that result is not null.static @NonNull Scheduler
createComputationScheduler(@NonNull java.util.concurrent.ThreadFactory threadFactory)
Create an instance of the defaultScheduler
used forSchedulers.computation()
except usingthreadFactory
for thread creation.static @NonNull Scheduler
createExecutorScheduler(@NonNull java.util.concurrent.Executor executor, boolean interruptibleWorker, boolean fair)
Create an instance of aScheduler
by wrapping an existingExecutor
.static @NonNull Scheduler
createIoScheduler(@NonNull java.util.concurrent.ThreadFactory threadFactory)
Create an instance of the defaultScheduler
used forSchedulers.io()
except usingthreadFactory
for thread creation.static @NonNull Scheduler
createNewThreadScheduler(@NonNull java.util.concurrent.ThreadFactory threadFactory)
Create an instance of the defaultScheduler
used forSchedulers.newThread()
except usingthreadFactory
for thread creation.static @NonNull Scheduler
createSingleScheduler(@NonNull java.util.concurrent.ThreadFactory threadFactory)
Create an instance of the defaultScheduler
used forSchedulers.single()
except usingthreadFactory
for thread creation.static @Nullable Function<? super Scheduler,? extends Scheduler>
getComputationSchedulerHandler()
Returns the current hook function.static @Nullable Consumer<? super java.lang.Throwable>
getErrorHandler()
Returns the a hook consumer.static @Nullable Function<? super Supplier<Scheduler>,? extends Scheduler>
getInitComputationSchedulerHandler()
Returns the current hook function.static @Nullable Function<? super Supplier<Scheduler>,? extends Scheduler>
getInitIoSchedulerHandler()
Returns the current hook function.static @Nullable Function<? super Supplier<Scheduler>,? extends Scheduler>
getInitNewThreadSchedulerHandler()
Returns the current hook function.static @Nullable Function<? super Supplier<Scheduler>,? extends Scheduler>
getInitSingleSchedulerHandler()
Returns the current hook function.static @Nullable Function<? super Scheduler,? extends Scheduler>
getIoSchedulerHandler()
Returns the current hook function.static @Nullable Function<? super Scheduler,? extends Scheduler>
getNewThreadSchedulerHandler()
Returns the current hook function.static @Nullable BooleanSupplier
getOnBeforeBlocking()
Returns the current blocking handler or null if no custom handler is set.static @Nullable Function<? super Completable,? extends Completable>
getOnCompletableAssembly()
Returns the current hook function.static @Nullable BiFunction<? super Completable,? super CompletableObserver,? extends CompletableObserver>
getOnCompletableSubscribe()
Returns the current hook function.static @Nullable Function<? super ConnectableFlowable,? extends ConnectableFlowable>
getOnConnectableFlowableAssembly()
Returns the current hook function.static @Nullable Function<? super ConnectableObservable,? extends ConnectableObservable>
getOnConnectableObservableAssembly()
Returns the current hook function.static @Nullable Function<? super Flowable,? extends Flowable>
getOnFlowableAssembly()
Returns the current hook function.static @Nullable BiFunction<? super Flowable,? super org.reactivestreams.Subscriber,? extends org.reactivestreams.Subscriber>
getOnFlowableSubscribe()
Returns the current hook function.static @Nullable Function<? super Maybe,? extends Maybe>
getOnMaybeAssembly()
Returns the current hook function.static @Nullable BiFunction<? super Maybe,? super MaybeObserver,? extends MaybeObserver>
getOnMaybeSubscribe()
Returns the current hook function.static @Nullable Function<? super Observable,? extends Observable>
getOnObservableAssembly()
Returns the current hook function.static @Nullable BiFunction<? super Observable,? super Observer,? extends Observer>
getOnObservableSubscribe()
Returns the current hook function.static @Nullable Function<? super ParallelFlowable,? extends ParallelFlowable>
getOnParallelAssembly()
Returns the current hook function.static @Nullable BiFunction<? super ParallelFlowable,? super org.reactivestreams.Subscriber[],? extends org.reactivestreams.Subscriber[]>
getOnParallelSubscribe()
Returns the current hook function.static @Nullable Function<? super Single,? extends Single>
getOnSingleAssembly()
Returns the current hook function.static @Nullable BiFunction<? super Single,? super SingleObserver,? extends SingleObserver>
getOnSingleSubscribe()
Returns the current hook function.static @Nullable Function<? super java.lang.Runnable,? extends java.lang.Runnable>
getScheduleHandler()
Returns the current hook function.static @Nullable Function<? super Scheduler,? extends Scheduler>
getSingleSchedulerHandler()
Returns the current hook function.static @NonNull Scheduler
initComputationScheduler(@NonNull Supplier<Scheduler> defaultScheduler)
Calls the associated hook function.static @NonNull Scheduler
initIoScheduler(@NonNull Supplier<Scheduler> defaultScheduler)
Calls the associated hook function.static @NonNull Scheduler
initNewThreadScheduler(@NonNull Supplier<Scheduler> defaultScheduler)
Calls the associated hook function.static @NonNull Scheduler
initSingleScheduler(@NonNull Supplier<Scheduler> defaultScheduler)
Calls the associated hook function.(package private) static boolean
isBug(java.lang.Throwable error)
Checks if the given error is one of the already named bug cases that should pass throughonError(Throwable)
as is.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 @NonNull Completable
onAssembly(@NonNull Completable source)
Calls the associated hook function.static <@NonNull T>
@NonNull Flowable<T>onAssembly(@NonNull Flowable<@NonNull T> source)
Calls the associated hook function.static <@NonNull T>
@NonNull Maybe<T>onAssembly(@NonNull Maybe<@NonNull T> source)
Calls the associated hook function.static <@NonNull T>
@NonNull Observable<T>onAssembly(@NonNull Observable<@NonNull T> source)
Calls the associated hook function.static <@NonNull T>
@NonNull Single<T>onAssembly(@NonNull Single<@NonNull T> source)
Calls the associated hook function.static <@NonNull T>
@NonNull ConnectableFlowable<T>onAssembly(@NonNull ConnectableFlowable<@NonNull T> source)
Calls the associated hook function.static <@NonNull T>
@NonNull ConnectableObservable<T>onAssembly(@NonNull ConnectableObservable<@NonNull T> source)
Calls the associated hook function.static <@NonNull T>
@NonNull ParallelFlowable<T>onAssembly(@NonNull ParallelFlowable<@NonNull 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 @NonNull Scheduler
onComputationScheduler(@NonNull Scheduler defaultScheduler)
Calls the associated hook function.static void
onError(@NonNull java.lang.Throwable error)
Called when an undeliverable error occurs.static @NonNull Scheduler
onIoScheduler(@NonNull Scheduler defaultScheduler)
Calls the associated hook function.static @NonNull Scheduler
onNewThreadScheduler(@NonNull Scheduler defaultScheduler)
Calls the associated hook function.static @NonNull java.lang.Runnable
onSchedule(@NonNull java.lang.Runnable run)
Called when a task is scheduled.static @NonNull Scheduler
onSingleScheduler(@NonNull Scheduler defaultScheduler)
Calls the associated hook function.static @NonNull CompletableObserver
onSubscribe(@NonNull Completable source, @NonNull CompletableObserver observer)
Calls the associated hook function.static <@NonNull T>
@NonNull org.reactivestreams.Subscriber<? super T>onSubscribe(@NonNull Flowable<@NonNull T> source, @NonNull org.reactivestreams.Subscriber<? super @NonNull T> subscriber)
Calls the associated hook function.static <@NonNull T>
@NonNull MaybeObserver<? super T>onSubscribe(@NonNull Maybe<@NonNull T> source, @NonNull MaybeObserver<? super @NonNull T> observer)
Calls the associated hook function.static <@NonNull T>
@NonNull Observer<? super T>onSubscribe(@NonNull Observable<@NonNull T> source, @NonNull Observer<? super @NonNull T> observer)
Calls the associated hook function.static <@NonNull T>
@NonNull SingleObserver<? super T>onSubscribe(@NonNull Single<@NonNull T> source, @NonNull SingleObserver<? super @NonNull T> observer)
Calls the associated hook function.static <@NonNull T>
@NonNull org.reactivestreams.Subscriber<? super T>[]onSubscribe(@NonNull ParallelFlowable<@NonNull T> source, @NonNull org.reactivestreams.Subscriber<? super @NonNull T>[] subscribers)
Calls the associated hook function.static void
reset()
Removes all handlers and resets to default behavior.static void
setComputationSchedulerHandler(@Nullable Function<? super Scheduler,? extends Scheduler> handler)
Sets the specific hook function.static void
setErrorHandler(@Nullable Consumer<? super java.lang.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(@Nullable Function<? super Supplier<Scheduler>,? extends Scheduler> handler)
Sets the specific hook function.static void
setInitIoSchedulerHandler(@Nullable Function<? super Supplier<Scheduler>,? extends Scheduler> handler)
Sets the specific hook function.static void
setInitNewThreadSchedulerHandler(@Nullable Function<? super Supplier<Scheduler>,? extends Scheduler> handler)
Sets the specific hook function.static void
setInitSingleSchedulerHandler(@Nullable Function<? super Supplier<Scheduler>,? extends Scheduler> handler)
Sets the specific hook function.static void
setIoSchedulerHandler(@Nullable Function<? super Scheduler,? extends Scheduler> handler)
Sets the specific hook function.static void
setNewThreadSchedulerHandler(@Nullable Function<? super Scheduler,? extends Scheduler> handler)
Sets the specific hook function.static void
setOnBeforeBlocking(@Nullable 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(@Nullable Function<? super Completable,? extends Completable> onCompletableAssembly)
Sets the specific hook function.static void
setOnCompletableSubscribe(@Nullable BiFunction<? super Completable,? super CompletableObserver,? extends CompletableObserver> onCompletableSubscribe)
Sets the specific hook function.static void
setOnConnectableFlowableAssembly(@Nullable Function<? super ConnectableFlowable,? extends ConnectableFlowable> onConnectableFlowableAssembly)
Sets the specific hook function.static void
setOnConnectableObservableAssembly(@Nullable Function<? super ConnectableObservable,? extends ConnectableObservable> onConnectableObservableAssembly)
Sets the specific hook function.static void
setOnFlowableAssembly(@Nullable Function<? super Flowable,? extends Flowable> onFlowableAssembly)
Sets the specific hook function.static void
setOnFlowableSubscribe(@Nullable BiFunction<? super Flowable,? super org.reactivestreams.Subscriber,? extends org.reactivestreams.Subscriber> onFlowableSubscribe)
Sets the specific hook function.static void
setOnMaybeAssembly(@Nullable Function<? super Maybe,? extends Maybe> onMaybeAssembly)
Sets the specific hook function.static void
setOnMaybeSubscribe(@Nullable BiFunction<? super Maybe,@NonNull MaybeObserver,? extends MaybeObserver> onMaybeSubscribe)
Sets the specific hook function.static void
setOnObservableAssembly(@Nullable Function<? super Observable,? extends Observable> onObservableAssembly)
Sets the specific hook function.static void
setOnObservableSubscribe(@Nullable BiFunction<? super Observable,? super Observer,? extends Observer> onObservableSubscribe)
Sets the specific hook function.static void
setOnParallelAssembly(@Nullable Function<? super ParallelFlowable,? extends ParallelFlowable> handler)
Sets the specific hook function.static void
setOnParallelSubscribe(@Nullable BiFunction<? super ParallelFlowable,? super org.reactivestreams.Subscriber[],? extends org.reactivestreams.Subscriber[]> handler)
Sets the specific hook function.static void
setOnSingleAssembly(@Nullable Function<? super Single,? extends Single> onSingleAssembly)
Sets the specific hook function.static void
setOnSingleSubscribe(@Nullable BiFunction<? super Single,? super SingleObserver,? extends SingleObserver> onSingleSubscribe)
Sets the specific hook function.static void
setScheduleHandler(@Nullable Function<? super java.lang.Runnable,? extends java.lang.Runnable> handler)
Sets the specific hook function.static void
setSingleSchedulerHandler(@Nullable Function<? super Scheduler,? extends Scheduler> handler)
Sets the specific hook function.(package private) static void
uncaught(@NonNull java.lang.Throwable error)
(package private) static void
unlock()
Revokes the lockdown, only for testing purposes.
-
-
-
Field Detail
-
onScheduleHandler
@Nullable static volatile @Nullable Function<? super java.lang.Runnable,? extends java.lang.Runnable> onScheduleHandler
-
onInitComputationHandler
@Nullable static volatile @Nullable Function<? super Supplier<Scheduler>,? extends Scheduler> onInitComputationHandler
-
onInitSingleHandler
@Nullable static volatile @Nullable Function<? super Supplier<Scheduler>,? extends Scheduler> onInitSingleHandler
-
onInitIoHandler
@Nullable static volatile @Nullable Function<? super Supplier<Scheduler>,? extends Scheduler> onInitIoHandler
-
onInitNewThreadHandler
@Nullable static volatile @Nullable Function<? super Supplier<Scheduler>,? extends Scheduler> onInitNewThreadHandler
-
onComputationHandler
@Nullable static volatile @Nullable Function<? super Scheduler,? extends Scheduler> onComputationHandler
-
onSingleHandler
@Nullable static volatile @Nullable Function<? super Scheduler,? extends Scheduler> onSingleHandler
-
onIoHandler
@Nullable static volatile @Nullable Function<? super Scheduler,? extends Scheduler> onIoHandler
-
onNewThreadHandler
@Nullable static volatile @Nullable Function<? super Scheduler,? extends Scheduler> onNewThreadHandler
-
onFlowableAssembly
@Nullable static volatile @Nullable Function<? super Flowable,? extends Flowable> onFlowableAssembly
-
onConnectableFlowableAssembly
@Nullable static volatile @Nullable Function<? super ConnectableFlowable,? extends ConnectableFlowable> onConnectableFlowableAssembly
-
onObservableAssembly
@Nullable static volatile @Nullable Function<? super Observable,? extends Observable> onObservableAssembly
-
onConnectableObservableAssembly
@Nullable static volatile @Nullable Function<? super ConnectableObservable,? extends ConnectableObservable> onConnectableObservableAssembly
-
onMaybeAssembly
@Nullable static volatile @Nullable Function<? super Maybe,? extends Maybe> onMaybeAssembly
-
onSingleAssembly
@Nullable static volatile @Nullable Function<? super Single,? extends Single> onSingleAssembly
-
onCompletableAssembly
@Nullable static volatile @Nullable Function<? super Completable,? extends Completable> onCompletableAssembly
-
onParallelAssembly
@Nullable static volatile @Nullable Function<? super ParallelFlowable,? extends ParallelFlowable> onParallelAssembly
-
onFlowableSubscribe
@Nullable static volatile @Nullable BiFunction<? super Flowable,? super org.reactivestreams.Subscriber,? extends org.reactivestreams.Subscriber> onFlowableSubscribe
-
onMaybeSubscribe
@Nullable static volatile @Nullable BiFunction<? super Maybe,? super MaybeObserver,? extends MaybeObserver> onMaybeSubscribe
-
onObservableSubscribe
@Nullable static volatile @Nullable BiFunction<? super Observable,? super Observer,? extends Observer> onObservableSubscribe
-
onSingleSubscribe
@Nullable static volatile @Nullable BiFunction<? super Single,? super SingleObserver,? extends SingleObserver> onSingleSubscribe
-
onCompletableSubscribe
@Nullable static volatile @Nullable BiFunction<? super Completable,? super CompletableObserver,? extends CompletableObserver> onCompletableSubscribe
-
onParallelSubscribe
@Nullable static volatile @Nullable BiFunction<? super ParallelFlowable,? super org.reactivestreams.Subscriber[],? extends org.reactivestreams.Subscriber[]> onParallelSubscribe
-
onBeforeBlocking
@Nullable static volatile @Nullable BooleanSupplier onBeforeBlocking
-
lockdown
static volatile boolean lockdown
Prevents changing the plugins.
-
failNonBlockingScheduler
static volatile boolean failNonBlockingScheduler
If true, attempting to run a blockingX operation on a (by default) computation or single scheduler will throw an IllegalStateException.
-
-
Method Detail
-
lockdown
public static void lockdown()
Prevents changing the plugins from then on.This allows container-like environments to prevent clients messing with plugins.
-
isLockdown
public static boolean isLockdown()
Returns true if the plugins were locked down.- Returns:
- true if the plugins were locked down
-
setFailOnNonBlockingScheduler
public 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.History: 2.0.5 - experimental
- Parameters:
enable
- enable or disable the feature- Since:
- 2.1
-
isFailOnNonBlockingScheduler
public static boolean isFailOnNonBlockingScheduler()
Returns true if the blockingX operators fail with an IllegalStateException on a non-blocking scheduler such as computation or single.History: 2.0.5 - experimental
- Returns:
- true if the blockingX operators fail on a non-blocking scheduler
- Since:
- 2.1
-
getComputationSchedulerHandler
@Nullable public static @Nullable Function<? super Scheduler,? extends Scheduler> getComputationSchedulerHandler()
Returns the current hook function.- Returns:
- the hook function, may be null
-
getErrorHandler
@Nullable public static @Nullable Consumer<? super java.lang.Throwable> getErrorHandler()
Returns the a hook consumer.- Returns:
- the hook consumer, may be null
-
getInitComputationSchedulerHandler
@Nullable public static @Nullable Function<? super Supplier<Scheduler>,? extends Scheduler> getInitComputationSchedulerHandler()
Returns the current hook function.- Returns:
- the hook function, may be null
-
getInitIoSchedulerHandler
@Nullable public static @Nullable Function<? super Supplier<Scheduler>,? extends Scheduler> getInitIoSchedulerHandler()
Returns the current hook function.- Returns:
- the hook function, may be null
-
getInitNewThreadSchedulerHandler
@Nullable public static @Nullable Function<? super Supplier<Scheduler>,? extends Scheduler> getInitNewThreadSchedulerHandler()
Returns the current hook function.- Returns:
- the hook function, may be null
-
getInitSingleSchedulerHandler
@Nullable public static @Nullable Function<? super Supplier<Scheduler>,? extends Scheduler> getInitSingleSchedulerHandler()
Returns the current hook function.- Returns:
- the hook function, may be null
-
getIoSchedulerHandler
@Nullable public static @Nullable Function<? super Scheduler,? extends Scheduler> getIoSchedulerHandler()
Returns the current hook function.- Returns:
- the hook function, may be null
-
getNewThreadSchedulerHandler
@Nullable public static @Nullable Function<? super Scheduler,? extends Scheduler> getNewThreadSchedulerHandler()
Returns the current hook function.- Returns:
- the hook function, may be null
-
getScheduleHandler
@Nullable public static @Nullable Function<? super java.lang.Runnable,? extends java.lang.Runnable> getScheduleHandler()
Returns the current hook function.- Returns:
- the hook function, may be null
-
getSingleSchedulerHandler
@Nullable public static @Nullable Function<? super Scheduler,? extends Scheduler> getSingleSchedulerHandler()
Returns the current hook function.- Returns:
- the hook function, may be null
-
initComputationScheduler
@NonNull public static @NonNull Scheduler initComputationScheduler(@NonNull @NonNull Supplier<Scheduler> defaultScheduler)
Calls the associated hook function.- Parameters:
defaultScheduler
- aSupplier
which returns the hook's input value- Returns:
- the value returned by the hook, not null
- Throws:
java.lang.NullPointerException
- if the supplier parameter or its result are null
-
initIoScheduler
@NonNull public static @NonNull Scheduler initIoScheduler(@NonNull @NonNull Supplier<Scheduler> defaultScheduler)
Calls the associated hook function.- Parameters:
defaultScheduler
- aSupplier
which returns the hook's input value- Returns:
- the value returned by the hook, not null
- Throws:
java.lang.NullPointerException
- if the supplier parameter or its result are null
-
initNewThreadScheduler
@NonNull public static @NonNull Scheduler initNewThreadScheduler(@NonNull @NonNull Supplier<Scheduler> defaultScheduler)
Calls the associated hook function.- Parameters:
defaultScheduler
- aSupplier
which returns the hook's input value- Returns:
- the value returned by the hook, not null
- Throws:
java.lang.NullPointerException
- if the supplier parameter or its result are null
-
initSingleScheduler
@NonNull public static @NonNull Scheduler initSingleScheduler(@NonNull @NonNull Supplier<Scheduler> defaultScheduler)
Calls the associated hook function.- Parameters:
defaultScheduler
- aSupplier
which returns the hook's input value- Returns:
- the value returned by the hook, not null
- Throws:
java.lang.NullPointerException
- if the supplier parameter or its result are null
-
onComputationScheduler
@NonNull public static @NonNull Scheduler onComputationScheduler(@NonNull @NonNull Scheduler defaultScheduler)
Calls the associated hook function.- Parameters:
defaultScheduler
- the hook's input value- Returns:
- the value returned by the hook
-
onError
public static void onError(@NonNull @NonNull java.lang.Throwable error)
Called when an undeliverable error occurs.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 itsDisposable
/Subscription
or has already terminated with anonError()
oronComplete()
signal.By default, this global error handler prints the stacktrace via
Throwable.printStackTrace()
and callsThread.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.- Parameters:
error
- the error to report- See Also:
getErrorHandler()
,setErrorHandler(Consumer)
, Error handling Wiki
-
isBug
static boolean isBug(java.lang.Throwable error)
Checks if the given error is one of the already named bug cases that should pass throughonError(Throwable)
as is.- Parameters:
error
- the error to check- Returns:
- true if the error should pass through, false if it may be wrapped into an UndeliverableException
-
onIoScheduler
@NonNull public static @NonNull Scheduler onIoScheduler(@NonNull @NonNull Scheduler defaultScheduler)
Calls the associated hook function.- Parameters:
defaultScheduler
- the hook's input value- Returns:
- the value returned by the hook
-
onNewThreadScheduler
@NonNull public static @NonNull Scheduler onNewThreadScheduler(@NonNull @NonNull Scheduler defaultScheduler)
Calls the associated hook function.- Parameters:
defaultScheduler
- the hook's input value- Returns:
- the value returned by the hook
-
onSchedule
@NonNull public static @NonNull java.lang.Runnable onSchedule(@NonNull @NonNull java.lang.Runnable run)
Called when a task is scheduled.- Parameters:
run
- the runnable instance- Returns:
- the replacement runnable
-
onSingleScheduler
@NonNull public static @NonNull Scheduler onSingleScheduler(@NonNull @NonNull Scheduler defaultScheduler)
Calls the associated hook function.- Parameters:
defaultScheduler
- the hook's input value- Returns:
- the value returned by the hook
-
reset
public static void reset()
Removes all handlers and resets to default behavior.
-
setComputationSchedulerHandler
public static void setComputationSchedulerHandler(@Nullable @Nullable Function<? super Scheduler,? extends Scheduler> handler)
Sets the specific hook function.- Parameters:
handler
- the hook function to set, null allowed
-
setErrorHandler
public static void setErrorHandler(@Nullable @Nullable Consumer<? super java.lang.Throwable> handler)
Sets the specific hook function.- Parameters:
handler
- the hook function to set, null allowed
-
setInitComputationSchedulerHandler
public static void setInitComputationSchedulerHandler(@Nullable @Nullable Function<? super Supplier<Scheduler>,? extends Scheduler> handler)
Sets the specific hook function.- Parameters:
handler
- the hook function to set, null allowed, but the function may not return null
-
setInitIoSchedulerHandler
public static void setInitIoSchedulerHandler(@Nullable @Nullable Function<? super Supplier<Scheduler>,? extends Scheduler> handler)
Sets the specific hook function.- Parameters:
handler
- the hook function to set, null allowed, but the function may not return null
-
setInitNewThreadSchedulerHandler
public static void setInitNewThreadSchedulerHandler(@Nullable @Nullable Function<? super Supplier<Scheduler>,? extends Scheduler> handler)
Sets the specific hook function.- Parameters:
handler
- the hook function to set, null allowed, but the function may not return null
-
setInitSingleSchedulerHandler
public static void setInitSingleSchedulerHandler(@Nullable @Nullable Function<? super Supplier<Scheduler>,? extends Scheduler> handler)
Sets the specific hook function.- Parameters:
handler
- the hook function to set, null allowed, but the function may not return null
-
setIoSchedulerHandler
public static void setIoSchedulerHandler(@Nullable @Nullable Function<? super Scheduler,? extends Scheduler> handler)
Sets the specific hook function.- Parameters:
handler
- the hook function to set, null allowed
-
setNewThreadSchedulerHandler
public static void setNewThreadSchedulerHandler(@Nullable @Nullable Function<? super Scheduler,? extends Scheduler> handler)
Sets the specific hook function.- Parameters:
handler
- the hook function to set, null allowed
-
setScheduleHandler
public static void setScheduleHandler(@Nullable @Nullable Function<? super java.lang.Runnable,? extends java.lang.Runnable> handler)
Sets the specific hook function.- Parameters:
handler
- the hook function to set, null allowed
-
setSingleSchedulerHandler
public static void setSingleSchedulerHandler(@Nullable @Nullable Function<? super Scheduler,? extends Scheduler> handler)
Sets the specific hook function.- Parameters:
handler
- the hook function to set, null allowed
-
unlock
static void unlock()
Revokes the lockdown, only for testing purposes.
-
getOnCompletableAssembly
@Nullable public static @Nullable Function<? super Completable,? extends Completable> getOnCompletableAssembly()
Returns the current hook function.- Returns:
- the hook function, may be null
-
getOnCompletableSubscribe
@Nullable public static @Nullable BiFunction<? super Completable,? super CompletableObserver,? extends CompletableObserver> getOnCompletableSubscribe()
Returns the current hook function.- Returns:
- the hook function, may be null
-
getOnFlowableAssembly
@Nullable public static @Nullable Function<? super Flowable,? extends Flowable> getOnFlowableAssembly()
Returns the current hook function.- Returns:
- the hook function, may be null
-
getOnConnectableFlowableAssembly
@Nullable public static @Nullable Function<? super ConnectableFlowable,? extends ConnectableFlowable> getOnConnectableFlowableAssembly()
Returns the current hook function.- Returns:
- the hook function, may be null
-
getOnFlowableSubscribe
@Nullable public static @Nullable BiFunction<? super Flowable,? super org.reactivestreams.Subscriber,? extends org.reactivestreams.Subscriber> getOnFlowableSubscribe()
Returns the current hook function.- Returns:
- the hook function, may be null
-
getOnMaybeSubscribe
@Nullable public static @Nullable BiFunction<? super Maybe,? super MaybeObserver,? extends MaybeObserver> getOnMaybeSubscribe()
Returns the current hook function.- Returns:
- the hook function, may be null
-
getOnMaybeAssembly
@Nullable public static @Nullable Function<? super Maybe,? extends Maybe> getOnMaybeAssembly()
Returns the current hook function.- Returns:
- the hook function, may be null
-
getOnSingleAssembly
@Nullable public static @Nullable Function<? super Single,? extends Single> getOnSingleAssembly()
Returns the current hook function.- Returns:
- the hook function, may be null
-
getOnSingleSubscribe
@Nullable public static @Nullable BiFunction<? super Single,? super SingleObserver,? extends SingleObserver> getOnSingleSubscribe()
Returns the current hook function.- Returns:
- the hook function, may be null
-
getOnObservableAssembly
@Nullable public static @Nullable Function<? super Observable,? extends Observable> getOnObservableAssembly()
Returns the current hook function.- Returns:
- the hook function, may be null
-
getOnConnectableObservableAssembly
@Nullable public static @Nullable Function<? super ConnectableObservable,? extends ConnectableObservable> getOnConnectableObservableAssembly()
Returns the current hook function.- Returns:
- the hook function, may be null
-
getOnObservableSubscribe
@Nullable public static @Nullable BiFunction<? super Observable,? super Observer,? extends Observer> getOnObservableSubscribe()
Returns the current hook function.- Returns:
- the hook function, may be null
-
setOnCompletableAssembly
public static void setOnCompletableAssembly(@Nullable @Nullable Function<? super Completable,? extends Completable> onCompletableAssembly)
Sets the specific hook function.- Parameters:
onCompletableAssembly
- the hook function to set, null allowed
-
setOnCompletableSubscribe
public static void setOnCompletableSubscribe(@Nullable @Nullable BiFunction<? super Completable,? super CompletableObserver,? extends CompletableObserver> onCompletableSubscribe)
Sets the specific hook function.- Parameters:
onCompletableSubscribe
- the hook function to set, null allowed
-
setOnFlowableAssembly
public static void setOnFlowableAssembly(@Nullable @Nullable Function<? super Flowable,? extends Flowable> onFlowableAssembly)
Sets the specific hook function.- Parameters:
onFlowableAssembly
- the hook function to set, null allowed
-
setOnMaybeAssembly
public static void setOnMaybeAssembly(@Nullable @Nullable Function<? super Maybe,? extends Maybe> onMaybeAssembly)
Sets the specific hook function.- Parameters:
onMaybeAssembly
- the hook function to set, null allowed
-
setOnConnectableFlowableAssembly
public static void setOnConnectableFlowableAssembly(@Nullable @Nullable Function<? super ConnectableFlowable,? extends ConnectableFlowable> onConnectableFlowableAssembly)
Sets the specific hook function.- Parameters:
onConnectableFlowableAssembly
- the hook function to set, null allowed
-
setOnFlowableSubscribe
public static void setOnFlowableSubscribe(@Nullable @Nullable BiFunction<? super Flowable,? super org.reactivestreams.Subscriber,? extends org.reactivestreams.Subscriber> onFlowableSubscribe)
Sets the specific hook function.- Parameters:
onFlowableSubscribe
- the hook function to set, null allowed
-
setOnMaybeSubscribe
public static void setOnMaybeSubscribe(@Nullable @Nullable BiFunction<? super Maybe,@NonNull MaybeObserver,? extends MaybeObserver> onMaybeSubscribe)
Sets the specific hook function.- Parameters:
onMaybeSubscribe
- the hook function to set, null allowed
-
setOnObservableAssembly
public static void setOnObservableAssembly(@Nullable @Nullable Function<? super Observable,? extends Observable> onObservableAssembly)
Sets the specific hook function.- Parameters:
onObservableAssembly
- the hook function to set, null allowed
-
setOnConnectableObservableAssembly
public static void setOnConnectableObservableAssembly(@Nullable @Nullable Function<? super ConnectableObservable,? extends ConnectableObservable> onConnectableObservableAssembly)
Sets the specific hook function.- Parameters:
onConnectableObservableAssembly
- the hook function to set, null allowed
-
setOnObservableSubscribe
public static void setOnObservableSubscribe(@Nullable @Nullable BiFunction<? super Observable,? super Observer,? extends Observer> onObservableSubscribe)
Sets the specific hook function.- Parameters:
onObservableSubscribe
- the hook function to set, null allowed
-
setOnSingleAssembly
public static void setOnSingleAssembly(@Nullable @Nullable Function<? super Single,? extends Single> onSingleAssembly)
Sets the specific hook function.- Parameters:
onSingleAssembly
- the hook function to set, null allowed
-
setOnSingleSubscribe
public static void setOnSingleSubscribe(@Nullable @Nullable BiFunction<? super Single,? super SingleObserver,? extends SingleObserver> onSingleSubscribe)
Sets the specific hook function.- Parameters:
onSingleSubscribe
- the hook function to set, null allowed
-
onSubscribe
@NonNull public static <@NonNull T> @NonNull org.reactivestreams.Subscriber<? super T> onSubscribe(@NonNull @NonNull Flowable<@NonNull T> source, @NonNull @NonNull org.reactivestreams.Subscriber<? super @NonNull T> subscriber)
Calls the associated hook function.- Type Parameters:
T
- the value type- Parameters:
source
- the hook's input valuesubscriber
- the subscriber- Returns:
- the value returned by the hook
-
onSubscribe
@NonNull public static <@NonNull T> @NonNull Observer<? super T> onSubscribe(@NonNull @NonNull Observable<@NonNull T> source, @NonNull @NonNull Observer<? super @NonNull T> observer)
Calls the associated hook function.- Type Parameters:
T
- the value type- Parameters:
source
- the hook's input valueobserver
- the observer- Returns:
- the value returned by the hook
-
onSubscribe
@NonNull public static <@NonNull T> @NonNull SingleObserver<? super T> onSubscribe(@NonNull @NonNull Single<@NonNull T> source, @NonNull @NonNull SingleObserver<? super @NonNull T> observer)
Calls the associated hook function.- Type Parameters:
T
- the value type- Parameters:
source
- the hook's input valueobserver
- the observer- Returns:
- the value returned by the hook
-
onSubscribe
@NonNull public static @NonNull CompletableObserver onSubscribe(@NonNull @NonNull Completable source, @NonNull @NonNull CompletableObserver observer)
Calls the associated hook function.- Parameters:
source
- the hook's input valueobserver
- the observer- Returns:
- the value returned by the hook
-
onSubscribe
@NonNull public static <@NonNull T> @NonNull MaybeObserver<? super T> onSubscribe(@NonNull @NonNull Maybe<@NonNull T> source, @NonNull @NonNull MaybeObserver<? super @NonNull T> observer)
Calls the associated hook function.- Type Parameters:
T
- the value type- Parameters:
source
- the hook's input valueobserver
- the subscriber- Returns:
- the value returned by the hook
-
onSubscribe
@NonNull public static <@NonNull T> @NonNull org.reactivestreams.Subscriber<? super T>[] onSubscribe(@NonNull @NonNull ParallelFlowable<@NonNull T> source, @NonNull @NonNull org.reactivestreams.Subscriber<? super @NonNull T>[] subscribers)
Calls the associated hook function.- Type Parameters:
T
- the value type- Parameters:
source
- the hook's input valuesubscribers
- the array of subscribers- Returns:
- the value returned by the hook
-
onAssembly
@NonNull public static <@NonNull T> @NonNull Maybe<T> onAssembly(@NonNull @NonNull Maybe<@NonNull T> source)
Calls the associated hook function.- Type Parameters:
T
- the value type- Parameters:
source
- the hook's input value- Returns:
- the value returned by the hook
-
onAssembly
@NonNull public static <@NonNull T> @NonNull Flowable<T> onAssembly(@NonNull @NonNull Flowable<@NonNull T> source)
Calls the associated hook function.- Type Parameters:
T
- the value type- Parameters:
source
- the hook's input value- Returns:
- the value returned by the hook
-
onAssembly
@NonNull public static <@NonNull T> @NonNull ConnectableFlowable<T> onAssembly(@NonNull @NonNull ConnectableFlowable<@NonNull T> source)
Calls the associated hook function.- Type Parameters:
T
- the value type- Parameters:
source
- the hook's input value- Returns:
- the value returned by the hook
-
onAssembly
@NonNull public static <@NonNull T> @NonNull Observable<T> onAssembly(@NonNull @NonNull Observable<@NonNull T> source)
Calls the associated hook function.- Type Parameters:
T
- the value type- Parameters:
source
- the hook's input value- Returns:
- the value returned by the hook
-
onAssembly
@NonNull public static <@NonNull T> @NonNull ConnectableObservable<T> onAssembly(@NonNull @NonNull ConnectableObservable<@NonNull T> source)
Calls the associated hook function.- Type Parameters:
T
- the value type- Parameters:
source
- the hook's input value- Returns:
- the value returned by the hook
-
onAssembly
@NonNull public static <@NonNull T> @NonNull Single<T> onAssembly(@NonNull @NonNull Single<@NonNull T> source)
Calls the associated hook function.- Type Parameters:
T
- the value type- Parameters:
source
- the hook's input value- Returns:
- the value returned by the hook
-
onAssembly
@NonNull public static @NonNull Completable onAssembly(@NonNull @NonNull Completable source)
Calls the associated hook function.- Parameters:
source
- the hook's input value- Returns:
- the value returned by the hook
-
setOnParallelAssembly
public static void setOnParallelAssembly(@Nullable @Nullable Function<? super ParallelFlowable,? extends ParallelFlowable> handler)
Sets the specific hook function.History: 2.0.6 - experimental; 2.1 - beta
- Parameters:
handler
- the hook function to set, null allowed- Since:
- 2.2
-
getOnParallelAssembly
@Nullable public static @Nullable Function<? super ParallelFlowable,? extends ParallelFlowable> getOnParallelAssembly()
Returns the current hook function.History: 2.0.6 - experimental; 2.1 - beta
- Returns:
- the hook function, may be null
- Since:
- 2.2
-
setOnParallelSubscribe
public static void setOnParallelSubscribe(@Nullable @Nullable BiFunction<? super ParallelFlowable,? super org.reactivestreams.Subscriber[],? extends org.reactivestreams.Subscriber[]> handler)
Sets the specific hook function.History: 3.0.11 - experimental
- Parameters:
handler
- the hook function to set, null allowed- Since:
- 3.1.0
-
getOnParallelSubscribe
@Nullable public static @Nullable BiFunction<? super ParallelFlowable,? super org.reactivestreams.Subscriber[],? extends org.reactivestreams.Subscriber[]> getOnParallelSubscribe()
Returns the current hook function.History: 3.0.11 - experimental
- Returns:
- the hook function, may be null
- Since:
- 3.1.0
-
onAssembly
@NonNull public static <@NonNull T> @NonNull ParallelFlowable<T> onAssembly(@NonNull @NonNull ParallelFlowable<@NonNull T> source)
Calls the associated hook function.History: 2.0.6 - experimental; 2.1 - beta
- Type Parameters:
T
- the value type of the source- Parameters:
source
- the hook's input value- Returns:
- the value returned by the hook
- Since:
- 2.2
-
onBeforeBlocking
public 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.History: 2.0.5 - experimental
- Returns:
- true if the blocking should be prevented
- Since:
- 2.1
- See Also:
setFailOnNonBlockingScheduler(boolean)
-
setOnBeforeBlocking
public static void setOnBeforeBlocking(@Nullable @Nullable 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.History: 2.0.5 - experimental
- Parameters:
handler
- the handler to set, null resets to the default handler that always returns false- Since:
- 2.1
- See Also:
onBeforeBlocking()
-
getOnBeforeBlocking
@Nullable public static @Nullable BooleanSupplier getOnBeforeBlocking()
Returns the current blocking handler or null if no custom handler is set.History: 2.0.5 - experimental
- Returns:
- the current blocking handler or null if not specified
- Since:
- 2.1
-
createComputationScheduler
@NonNull public static @NonNull Scheduler createComputationScheduler(@NonNull @NonNull java.util.concurrent.ThreadFactory threadFactory)
Create an instance of the defaultScheduler
used forSchedulers.computation()
except usingthreadFactory
for thread creation.History: 2.0.5 - experimental
- Parameters:
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.- Returns:
- the created Scheduler instance
- Since:
- 2.1
-
createIoScheduler
@NonNull public static @NonNull Scheduler createIoScheduler(@NonNull @NonNull java.util.concurrent.ThreadFactory threadFactory)
Create an instance of the defaultScheduler
used forSchedulers.io()
except usingthreadFactory
for thread creation.History: 2.0.5 - experimental
- Parameters:
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.- Returns:
- the created Scheduler instance
- Since:
- 2.1
-
createNewThreadScheduler
@NonNull public static @NonNull Scheduler createNewThreadScheduler(@NonNull @NonNull java.util.concurrent.ThreadFactory threadFactory)
Create an instance of the defaultScheduler
used forSchedulers.newThread()
except usingthreadFactory
for thread creation.History: 2.0.5 - experimental
- Parameters:
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.- Returns:
- the created Scheduler instance
- Since:
- 2.1
-
createSingleScheduler
@NonNull public static @NonNull Scheduler createSingleScheduler(@NonNull @NonNull java.util.concurrent.ThreadFactory threadFactory)
Create an instance of the defaultScheduler
used forSchedulers.single()
except usingthreadFactory
for thread creation.History: 2.0.5 - experimental
- Parameters:
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.- Returns:
- the created Scheduler instance
- Since:
- 2.1
-
createExecutorScheduler
@NonNull public static @NonNull Scheduler createExecutorScheduler(@NonNull @NonNull java.util.concurrent.Executor executor, boolean interruptibleWorker, boolean fair)
Create an instance of aScheduler
by wrapping an existingExecutor
.This method allows creating an
Executor
-backedScheduler
before theSchedulers
class would initialize the standardScheduler
s.- Parameters:
executor
- theExecutor
to wrap and turn into aScheduler
.interruptibleWorker
- iftrue
, the tasks submitted to theScheduler.Worker
will be interrupted when the task is disposed.fair
- iftrue
, tasks submitted to theScheduler
orWorker
will be executed by the underlyingExecutor
one after the other, still in a FIFO and non-overlapping manner, but allows interleaving with other tasks submitted to the underlyingExecutor
. Iffalse
, the underlying FIFO scheme will execute as many tasks as it can before giving up the underlyingExecutor
thread.- Returns:
- the new
Scheduler
wrapping theExecutor
- Since:
- 3.1.0
-
apply
@NonNull static <@NonNull T,@NonNull R> R apply(@NonNull @NonNull Function<@NonNull T,@NonNull R> f, @NonNull @NonNull T t)
Wraps the call to the function in try-catch and propagates thrown checked exceptions as RuntimeException.- Type Parameters:
T
- the input typeR
- the output type- Parameters:
f
- the function to call, not null (not verified)t
- the parameter value to the function- Returns:
- the result of the function call
-
apply
@NonNull static <@NonNull T,@NonNull U,@NonNull R> R apply(@NonNull @NonNull BiFunction<@NonNull T,@NonNull U,@NonNull R> f, @NonNull @NonNull T t, @NonNull @NonNull U u)
Wraps the call to the function in try-catch and propagates thrown checked exceptions as RuntimeException.- Type Parameters:
T
- the first input typeU
- the second input typeR
- the output type- Parameters:
f
- the function to call, not null (not verified)t
- the first parameter value to the functionu
- the second parameter value to the function- Returns:
- the result of the function call
-
callRequireNonNull
@NonNull static @NonNull Scheduler callRequireNonNull(@NonNull @NonNull Supplier<Scheduler> s)
Wraps the call to the Scheduler creation supplier in try-catch and propagates thrown checked exceptions as RuntimeException and enforces that result is not null.
-
applyRequireNonNull
@NonNull static @NonNull Scheduler applyRequireNonNull(@NonNull @NonNull Function<? super Supplier<Scheduler>,? extends Scheduler> f, Supplier<Scheduler> s)
Wraps the call to the Scheduler creation function in try-catch and propagates thrown checked exceptions as RuntimeException and enforces that result is not null.- Parameters:
f
- the function to call, not null (not verified). Cannot return nulls
- the parameter value to the function- Returns:
- the result of the function call, not null
- Throws:
java.lang.NullPointerException
- if the function parameter returns null
-
-