Top Description Fields Constructors Methods
io.reactivex.rxjava3.plugins

public final Class RxJavaPlugins

extends Object
Class Inheritance
Imports
java.lang.Thread.UncaughtExceptionHandler, java.util.Objects, java.util.concurrent.*, org.reactivestreams.Subscriber, io.reactivex.rxjava3.annotations.*, io.reactivex.rxjava3.core.*, io.reactivex.rxjava3.exceptions.*, io.reactivex.rxjava3.flowables.ConnectableFlowable, io.reactivex.rxjava3.functions.*, io.reactivex.rxjava3.internal.schedulers.*, io.reactivex.rxjava3.internal.util.ExceptionHelper, io.reactivex.rxjava3.observables.ConnectableObservable, io.reactivex.rxjava3.parallel.ParallelFlowable, io.reactivex.rxjava3.schedulers.Schedulers

Utility class to inject handlers to certain standard RxJava operations.

Field Summary

Modifier and TypeField and Description
pack-priv static volatile @Nullable Consumer<? super Throwable>
pack-priv static volatile boolean
failNonBlockingScheduler

If true, attempting to run a blockingX operation on a (by default) computation or single scheduler will throw an IllegalStateException.

pack-priv static volatile boolean
lockdown

Prevents changing the plugins.

pack-priv static volatile @Nullable BooleanSupplier
pack-priv static volatile @Nullable Function<? super Completable, ? extends Completable>
pack-priv static volatile @Nullable BiFunction<? super Completable, @NonNull ? super CompletableObserver, @NonNull ? extends CompletableObserver>
pack-priv static volatile @Nullable Function<? super Scheduler, ? extends Scheduler>
pack-priv static volatile @Nullable Function<? super ConnectableFlowable<T>, ? extends ConnectableFlowable<T>>
pack-priv static volatile @Nullable Function<? super ConnectableObservable<T>, ? extends ConnectableObservable<T>>
pack-priv static volatile @Nullable Function<? super Flowable<T>, ? extends Flowable<T>>
pack-priv static volatile @Nullable BiFunction<? super Flowable<T>, @NonNull ? super Subscriber<T>, @NonNull ? extends Subscriber<T>>
pack-priv static volatile @Nullable Function<? super Supplier<Scheduler>, ? extends Scheduler>
pack-priv static volatile @Nullable Function<? super Supplier<Scheduler>, ? extends Scheduler>
pack-priv static volatile @Nullable Function<? super Supplier<Scheduler>, ? extends Scheduler>
pack-priv static volatile @Nullable Function<? super Supplier<Scheduler>, ? extends Scheduler>
pack-priv static volatile @Nullable Function<? super Scheduler, ? extends Scheduler>
pack-priv static volatile @Nullable Function<? super Maybe<T>, ? extends Maybe<T>>
pack-priv static volatile @Nullable BiFunction<? super Maybe<T>, @NonNull ? super MaybeObserver<T>, @NonNull ? extends MaybeObserver<T>>
pack-priv static volatile @Nullable Function<? super Scheduler, ? extends Scheduler>
pack-priv static volatile @Nullable Function<? super Observable<T>, ? extends Observable<T>>
pack-priv static volatile @Nullable BiFunction<? super Observable<T>, @NonNull ? super Observer<T>, @NonNull ? extends Observer<T>>
pack-priv static volatile @Nullable Function<? super ParallelFlowable<T>, ? extends ParallelFlowable<T>>
pack-priv static volatile @Nullable BiFunction<? super ParallelFlowable<T>, @NonNull ? super Subscriber<T>[], @NonNull ? extends Subscriber<T>[]>
pack-priv static volatile @Nullable Function<? super Runnable, ? extends Runnable>
pack-priv static volatile @Nullable Function<? super Single<T>, ? extends Single<T>>
pack-priv static volatile @Nullable Function<? super Scheduler, ? extends Scheduler>
pack-priv static volatile @Nullable BiFunction<? super Single<T>, @NonNull ? super SingleObserver<T>, @NonNull ? extends SingleObserver<T>>

Constructor Summary

AccessConstructor and Description
private
RxJavaPlugins()

Helper class, no instances.

Method Summary

Modifier and TypeMethod and Description
pack-priv static <
the input type
T
,
the output type
R
>
R

Returns:

the result of the function call
apply
(@NonNull Function<T, R>
the function to call, not null (not verified)
f
,
T
the parameter value to the function
t
)

Wraps the call to the function in try-catch and propagates thrown checked exceptions as RuntimeException.

pack-priv static <
the first input type
T
,
the second input type
U
,
the output type
R
>
R

Returns:

the result of the function call
apply
(@NonNull BiFunction<T, U, R>
the function to call, not null (not verified)
f
,
T
the first parameter value to the function
t
,
U
the second parameter value to the function
u
)

Wraps the call to the function in try-catch and propagates thrown checked exceptions as RuntimeException.

pack-priv static @NonNull Scheduler

Returns:

the result of the function call, not null
applyRequireNonNull
(@NonNull Function<? super Supplier<Scheduler>, ? extends Scheduler>
the function to call, not null (not verified). Cannot return null
f
,
Supplier<Scheduler>
the parameter value to the function
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.

pack-priv static @NonNull Scheduler

Returns:

the result of the supplier call, not null
callRequireNonNull
(@NonNull Supplier<Scheduler>
the Supplier which returns a Scheduler, not null (not verified). Cannot return null
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.

public static @NonNull Scheduler

Returns:

the created Scheduler instance
createComputationScheduler
(@NonNull 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.
threadFactory
)

Create an instance of the default Scheduler used for Schedulers#computation() except using threadFactory for thread creation.

public static @NonNull Scheduler

Returns:

the new Scheduler wrapping the Executor
createExecutorScheduler
(@NonNull Executor
the Executor to wrap and turn into a Scheduler.
executor
,
boolean
if true, the tasks submitted to the Scheduler.Worker will be interrupted when the task is disposed.
interruptibleWorker
,
boolean
if true, tasks submitted to the Scheduler or Worker will be executed by the underlying Executor one after the other, still in a FIFO and non-overlapping manner, but allows interleaving with other tasks submitted to the underlying Executor. If false, the underlying FIFO scheme will execute as many tasks as it can before giving up the underlying Executor thread.
fair
)

Create an instance of a Scheduler by wrapping an existing Executor.

public static @NonNull Scheduler

Returns:

the created Scheduler instance
createIoScheduler
(@NonNull 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.
threadFactory
)

Create an instance of the default Scheduler used for Schedulers#io() except using threadFactory for thread creation.

public static @NonNull Scheduler

Returns:

the created Scheduler instance
createNewThreadScheduler
(@NonNull 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.
threadFactory
)

Create an instance of the default Scheduler used for Schedulers#newThread() except using threadFactory for thread creation.

public static @NonNull Scheduler

Returns:

the created Scheduler instance
createSingleScheduler
(@NonNull 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.
threadFactory
)

Create an instance of the default Scheduler used for Schedulers#single() except using threadFactory for thread creation.

public static @Nullable Function<? super Scheduler, ? extends Scheduler>

Returns:

the hook function, may be null
getComputationSchedulerHandler
()

Returns the current hook function.

public static @Nullable Consumer<? super Throwable>

Returns:

the hook consumer, may be null
getErrorHandler
()

Returns the a hook consumer.

public static @Nullable Function<? super Supplier<Scheduler>, ? extends Scheduler>

Returns:

the hook function, may be null
getInitComputationSchedulerHandler
()

Returns the current hook function.

public static @Nullable Function<? super Supplier<Scheduler>, ? extends Scheduler>

Returns:

the hook function, may be null
getInitIoSchedulerHandler
()

Returns the current hook function.

public static @Nullable Function<? super Supplier<Scheduler>, ? extends Scheduler>

Returns:

the hook function, may be null
getInitNewThreadSchedulerHandler
()

Returns the current hook function.

public static @Nullable Function<? super Supplier<Scheduler>, ? extends Scheduler>

Returns:

the hook function, may be null
getInitSingleSchedulerHandler
()

Returns the current hook function.

public static @Nullable Function<? super Scheduler, ? extends Scheduler>

Returns:

the hook function, may be null
getIoSchedulerHandler
()

Returns the current hook function.

public static @Nullable Function<? super Scheduler, ? extends Scheduler>

Returns:

the hook function, may be null
getNewThreadSchedulerHandler
()

Returns the current hook function.

public static @Nullable BooleanSupplier

Returns:

the current blocking handler or null if not specified
getOnBeforeBlocking
()

Returns the current blocking handler or null if no custom handler is set.

public static @Nullable Function<? super Completable, ? extends Completable>

Returns:

the hook function, may be null
getOnCompletableAssembly
()

Returns the current hook function.

public static @Nullable BiFunction<? super Completable, @NonNull ? super CompletableObserver, @NonNull ? extends CompletableObserver>

Returns:

the hook function, may be null
getOnCompletableSubscribe
()

Returns the current hook function.

public static @Nullable Function<? super ConnectableFlowable<T>, ? extends ConnectableFlowable<T>>

Returns:

the hook function, may be null
getOnConnectableFlowableAssembly
()

Returns the current hook function.

public static @Nullable Function<? super ConnectableObservable<T>, ? extends ConnectableObservable<T>>

Returns:

the hook function, may be null
getOnConnectableObservableAssembly
()

Returns the current hook function.

public static @Nullable Function<? super Flowable<T>, ? extends Flowable<T>>

Returns:

the hook function, may be null
getOnFlowableAssembly
()

Returns the current hook function.

public static @Nullable BiFunction<? super Flowable<T>, @NonNull ? super Subscriber<T>, @NonNull ? extends Subscriber<T>>

Returns:

the hook function, may be null
getOnFlowableSubscribe
()

Returns the current hook function.

public static @Nullable Function<? super Maybe<T>, ? extends Maybe<T>>

Returns:

the hook function, may be null
getOnMaybeAssembly
()

Returns the current hook function.

public static @Nullable BiFunction<? super Maybe<T>, @NonNull ? super MaybeObserver<T>, @NonNull ? extends MaybeObserver<T>>

Returns:

the hook function, may be null
getOnMaybeSubscribe
()

Returns the current hook function.

public static @Nullable Function<? super Observable<T>, ? extends Observable<T>>

Returns:

the hook function, may be null
getOnObservableAssembly
()

Returns the current hook function.

public static @Nullable BiFunction<? super Observable<T>, @NonNull ? super Observer<T>, @NonNull ? extends Observer<T>>

Returns:

the hook function, may be null
getOnObservableSubscribe
()

Returns the current hook function.

public static @Nullable Function<? super ParallelFlowable<T>, ? extends ParallelFlowable<T>>

Returns:

the hook function, may be null
getOnParallelAssembly
()

Returns the current hook function.

public static @Nullable BiFunction<? super ParallelFlowable<T>, @NonNull ? super Subscriber<T>[], @NonNull ? extends Subscriber<T>[]>

Returns:

the hook function, may be null
getOnParallelSubscribe
()

Returns the current hook function.

public static @Nullable Function<? super Single<T>, ? extends Single<T>>

Returns:

the hook function, may be null
getOnSingleAssembly
()

Returns the current hook function.

public static @Nullable BiFunction<? super Single<T>, @NonNull ? super SingleObserver<T>, @NonNull ? extends SingleObserver<T>>

Returns:

the hook function, may be null
getOnSingleSubscribe
()

Returns the current hook function.

public static @Nullable Function<? super Runnable, ? extends Runnable>

Returns:

the hook function, may be null
getScheduleHandler
()

Returns the current hook function.

public static @Nullable Function<? super Scheduler, ? extends Scheduler>

Returns:

the hook function, may be null
getSingleSchedulerHandler
()

Returns the current hook function.

public static @NonNull Scheduler

Returns:

the value returned by the hook, not null
initComputationScheduler
(@NonNull Supplier<Scheduler>
a Supplier which returns the hook's input value
defaultScheduler
)

Calls the associated hook function.

public static @NonNull Scheduler

Returns:

the value returned by the hook, not null
initIoScheduler
(@NonNull Supplier<Scheduler>
a Supplier which returns the hook's input value
defaultScheduler
)

Calls the associated hook function.

public static @NonNull Scheduler

Returns:

the value returned by the hook, not null
initNewThreadScheduler
(@NonNull Supplier<Scheduler>
a Supplier which returns the hook's input value
defaultScheduler
)

Calls the associated hook function.

public static @NonNull Scheduler

Returns:

the value returned by the hook, not null
initSingleScheduler
(@NonNull Supplier<Scheduler>
a Supplier which returns the hook's input value
defaultScheduler
)

Calls the associated hook function.

pack-priv static boolean

Returns:

true if the error should pass through, false if it may be wrapped into an UndeliverableException
isBug
(Throwable
the error to check
error
)

Checks if the given error is one of the already named bug cases that should pass through onError(Throwable) as is.

public static boolean

Returns:

true if the blockingX operators fail on a non-blocking scheduler
isFailOnNonBlockingScheduler
()

Returns true if the blockingX operators fail with an IllegalStateException on a non-blocking scheduler such as computation or single.

public static boolean

Returns:

true if the plugins were locked down
isLockdown
()

Returns true if the plugins were locked down.

public static void
lockdown()

Prevents changing the plugins from then on.

public static <
the value type
T
>
@NonNull Maybe<T>

Returns:

the value returned by the hook
onAssembly
(@NonNull Maybe<T>
the hook's input value
source
)

Calls the associated hook function.

public static <
the value type
T
>
@NonNull Flowable<T>

Returns:

the value returned by the hook
onAssembly
(@NonNull Flowable<T>
the hook's input value
source
)

Calls the associated hook function.

public static <
the value type
T
>
@NonNull ConnectableFlowable<T>

Returns:

the value returned by the hook
onAssembly
(@NonNull ConnectableFlowable<T>
the hook's input value
source
)

Calls the associated hook function.

public static <
the value type
T
>
@NonNull Observable<T>

Returns:

the value returned by the hook
onAssembly
(@NonNull Observable<T>
the hook's input value
source
)

Calls the associated hook function.

public static <
the value type
T
>
@NonNull ConnectableObservable<T>

Returns:

the value returned by the hook
onAssembly
(@NonNull ConnectableObservable<T>
the hook's input value
source
)

Calls the associated hook function.

public static <
the value type
T
>
@NonNull Single<T>

Returns:

the value returned by the hook
onAssembly
(@NonNull Single<T>
the hook's input value
source
)

Calls the associated hook function.

public static @NonNull Completable

Returns:

the value returned by the hook
onAssembly
(@NonNull Completable
the hook's input value
source
)

Calls the associated hook function.

public static <
the value type of the source
T
>
@NonNull ParallelFlowable<T>

Returns:

the value returned by the hook
onAssembly
(@NonNull ParallelFlowable<T>
the hook's input value
source
)

Calls the associated hook function.

public static boolean

Returns:

true if the blocking should be prevented
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.

public static @NonNull Scheduler

Returns:

the value returned by the hook
onComputationScheduler
(@NonNull Scheduler
the hook's input value
defaultScheduler
)

Calls the associated hook function.

public static void
onError(@NonNull Throwable
the error to report
error
)

Called when an undeliverable error occurs.

public static @NonNull Scheduler

Returns:

the value returned by the hook
onIoScheduler
(@NonNull Scheduler
the hook's input value
defaultScheduler
)

Calls the associated hook function.

public static @NonNull Scheduler

Returns:

the value returned by the hook
onNewThreadScheduler
(@NonNull Scheduler
the hook's input value
defaultScheduler
)

Calls the associated hook function.

public static @NonNull Runnable

Returns:

the replacement runnable
onSchedule
(@NonNull Runnable
the runnable instance
run
)

Called when a task is scheduled.

public static @NonNull Scheduler

Returns:

the value returned by the hook
onSingleScheduler
(@NonNull Scheduler
the hook's input value
defaultScheduler
)

Calls the associated hook function.

public static <
the value type
T
>
@NonNull Subscriber<? super T>

Returns:

the value returned by the hook
onSubscribe
(@NonNull Flowable<T>
the hook's input value
source
,
@NonNull Subscriber<? super T>
the subscriber
subscriber
)

Calls the associated hook function.

public static <
the value type
T
>
@NonNull Observer<? super T>

Returns:

the value returned by the hook
onSubscribe
(@NonNull Observable<T>
the hook's input value
source
,
@NonNull Observer<? super T>
the observer
observer
)

Calls the associated hook function.

public static <
the value type
T
>
@NonNull SingleObserver<? super T>

Returns:

the value returned by the hook
onSubscribe
(@NonNull Single<T>
the hook's input value
source
,
@NonNull SingleObserver<? super T>
the observer
observer
)

Calls the associated hook function.

public static @NonNull CompletableObserver

Returns:

the value returned by the hook
onSubscribe
(@NonNull Completable
the hook's input value
source
,
@NonNull CompletableObserver
the observer
observer
)

Calls the associated hook function.

public static <
the value type
T
>
@NonNull MaybeObserver<? super T>

Returns:

the value returned by the hook
onSubscribe
(@NonNull Maybe<T>
the hook's input value
source
,
@NonNull MaybeObserver<? super T>
the subscriber
observer
)

Calls the associated hook function.

public static <
the value type
T
>
@NonNull Subscriber<? super T>[]

Returns:

the value returned by the hook
onSubscribe
(@NonNull ParallelFlowable<T>
the hook's input value
source
,
@NonNull Subscriber<? super T>[]
the array of subscribers
subscribers
)

Calls the associated hook function.

public static void
reset()

Removes all handlers and resets to default behavior.

public static void
setComputationSchedulerHandler(@Nullable Function<? super Scheduler, ? extends Scheduler>
the hook function to set, null allowed
handler
)

Sets the specific hook function.

public static void
setErrorHandler(@Nullable Consumer<? super Throwable>
the hook function to set, null allowed
handler
)

Sets the specific hook function.

public static void
setFailOnNonBlockingScheduler(boolean
enable or disable the feature
enable
)

Enables or disables the blockingX operators to fail with an IllegalStateException on a non-blocking scheduler such as computation or single.

public static void
setInitComputationSchedulerHandler(@Nullable Function<? super Supplier<Scheduler>, ? extends Scheduler>
the hook function to set, null allowed, but the function may not return null
handler
)

Sets the specific hook function.

public static void
setInitIoSchedulerHandler(@Nullable Function<? super Supplier<Scheduler>, ? extends Scheduler>
the hook function to set, null allowed, but the function may not return null
handler
)

Sets the specific hook function.

public static void
setInitNewThreadSchedulerHandler(@Nullable Function<? super Supplier<Scheduler>, ? extends Scheduler>
the hook function to set, null allowed, but the function may not return null
handler
)

Sets the specific hook function.

public static void
setInitSingleSchedulerHandler(@Nullable Function<? super Supplier<Scheduler>, ? extends Scheduler>
the hook function to set, null allowed, but the function may not return null
handler
)

Sets the specific hook function.

public static void
setIoSchedulerHandler(@Nullable Function<? super Scheduler, ? extends Scheduler>
the hook function to set, null allowed
handler
)

Sets the specific hook function.

public static void
setNewThreadSchedulerHandler(@Nullable Function<? super Scheduler, ? extends Scheduler>
the hook function to set, null allowed
handler
)

Sets the specific hook function.

public static void
setOnBeforeBlocking(@Nullable BooleanSupplier
the handler to set, null resets to the default handler that always returns false
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.

public static void
setOnCompletableAssembly(@Nullable Function<? super Completable, ? extends Completable>
the hook function to set, null allowed
onCompletableAssembly
)

Sets the specific hook function.

public static void
setOnCompletableSubscribe(@Nullable BiFunction<? super Completable, @NonNull ? super CompletableObserver, @NonNull ? extends CompletableObserver>
the hook function to set, null allowed
onCompletableSubscribe
)

Sets the specific hook function.

public static void
setOnConnectableFlowableAssembly(@Nullable Function<? super ConnectableFlowable<T>, ? extends ConnectableFlowable<T>>
the hook function to set, null allowed
onConnectableFlowableAssembly
)

Sets the specific hook function.

public static void
setOnConnectableObservableAssembly(@Nullable Function<? super ConnectableObservable<T>, ? extends ConnectableObservable<T>>
the hook function to set, null allowed
onConnectableObservableAssembly
)

Sets the specific hook function.

public static void
setOnFlowableAssembly(@Nullable Function<? super Flowable<T>, ? extends Flowable<T>>
the hook function to set, null allowed
onFlowableAssembly
)

Sets the specific hook function.

public static void
setOnFlowableSubscribe(@Nullable BiFunction<? super Flowable<T>, @NonNull ? super Subscriber<T>, @NonNull ? extends Subscriber<T>>
the hook function to set, null allowed
onFlowableSubscribe
)

Sets the specific hook function.

public static void
setOnMaybeAssembly(@Nullable Function<? super Maybe<T>, ? extends Maybe<T>>
the hook function to set, null allowed
onMaybeAssembly
)

Sets the specific hook function.

public static void
setOnMaybeSubscribe(@Nullable BiFunction<? super Maybe<T>, @NonNull MaybeObserver<T>, @NonNull ? extends MaybeObserver<T>>
the hook function to set, null allowed
onMaybeSubscribe
)

Sets the specific hook function.

public static void
setOnObservableAssembly(@Nullable Function<? super Observable<T>, ? extends Observable<T>>
the hook function to set, null allowed
onObservableAssembly
)

Sets the specific hook function.

public static void
setOnObservableSubscribe(@Nullable BiFunction<? super Observable<T>, @NonNull ? super Observer<T>, @NonNull ? extends Observer<T>>
the hook function to set, null allowed
onObservableSubscribe
)

Sets the specific hook function.

public static void
setOnParallelAssembly(@Nullable Function<? super ParallelFlowable<T>, ? extends ParallelFlowable<T>>
the hook function to set, null allowed
handler
)

Sets the specific hook function.

public static void
setOnParallelSubscribe(@Nullable BiFunction<? super ParallelFlowable<T>, @NonNull ? super Subscriber<T>[], @NonNull ? extends Subscriber<T>[]>
the hook function to set, null allowed
handler
)

Sets the specific hook function.

public static void
setOnSingleAssembly(@Nullable Function<? super Single<T>, ? extends Single<T>>
the hook function to set, null allowed
onSingleAssembly
)

Sets the specific hook function.

public static void
setOnSingleSubscribe(@Nullable BiFunction<? super Single<T>, @NonNull ? super SingleObserver<T>, @NonNull ? extends SingleObserver<T>>
the hook function to set, null allowed
onSingleSubscribe
)

Sets the specific hook function.

public static void
setScheduleHandler(@Nullable Function<? super Runnable, ? extends Runnable>
the hook function to set, null allowed
handler
)

Sets the specific hook function.

public static void
setSingleSchedulerHandler(@Nullable Function<? super Scheduler, ? extends Scheduler>
the hook function to set, null allowed
handler
)

Sets the specific hook function.

pack-priv static void
pack-priv static void
unlock()

Revokes the lockdown, only for testing purposes.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait