Package 

Class RxJavaHooks


  • 
    public final class RxJavaHooks
    
                        

    Utility class that holds hooks for various Observable, Single and Completable lifecycle-related points as well as Scheduler hooks.

    The class features a lockdown state, see lockdown and isLockdown, to prevent further changes to the hooks.

    • Method Detail

      • getOnError

         static Action1<Throwable> getOnError()

        Returns the current global error handler hook action or null if it isset to the default one that signals errors to the current threadsUncaughtExceptionHandler.

        This operation is thread-safe.

      • setOnError

         static void setOnError(Action1<Throwable> onError)

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

        This operation is thread-safe.

        Calling with a {@code null} parameter has the effect thaterrors are routed to the current thread's UncaughtExceptionHandler.

        Parameters:
        onError - the action that will receive undeliverable Throwables
      • setOnObservableCreate

         static void setOnObservableCreate(Func1<Observable.OnSubscribe, Observable.OnSubscribe> onObservableCreate)

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

        This operation is thread-safe.

        Calling with a {@code null} parameter restores the default behavior:the hook returns the same object.

        Parameters:
        onObservableCreate - the function that takes the original OnSubscribeand should return a OnSubscribe.
      • setOnObservableStart

         static void setOnObservableStart(Func2<Observable, Observable.OnSubscribe, Observable.OnSubscribe> onObservableStart)

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

        This operation is thread-safe.

        Calling with a {@code null} parameter restores the default behavior:the hook returns the same OnSubscribe object.

        Parameters:
        onObservableStart - the function that is called with the current Observable instance,its OnSubscribe function and should return a OnSubscribe functionthat gets actually subscribed to.
      • setOnComputationScheduler

         static void setOnComputationScheduler(Func1<Scheduler, Scheduler> onComputationScheduler)

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

        This operation is thread-safe.

        Calling with a {@code null} parameter restores the default behavior:the hook returns the same object.

        Parameters:
        onComputationScheduler - the function that receives the original computation schedulerand should return a scheduler.
      • getOnIOScheduler

         static Func1<Scheduler, Scheduler> getOnIOScheduler()

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

        This operation is thread-safe.

      • setOnIOScheduler

         static void setOnIOScheduler(Func1<Scheduler, Scheduler> onIOScheduler)

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

        This operation is thread-safe.

        Calling with a {@code null} parameter restores the default behavior:the hook returns the same object.

        Parameters:
        onIOScheduler - the function that receives the original io schedulerand should return a scheduler.
      • setOnNewThreadScheduler

         static void setOnNewThreadScheduler(Func1<Scheduler, Scheduler> onNewThreadScheduler)

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

        This operation is thread-safe.

        Calling with a {@code null} parameter restores the default behavior:the hook returns the same object.

        Parameters:
        onNewThreadScheduler - the function that receives the original new thread schedulerand should return a scheduler.
      • getOnScheduleAction

         static Func1<Action0, Action0> getOnScheduleAction()

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

        This operation is thread-safe.

      • setOnScheduleAction

         static void setOnScheduleAction(Func1<Action0, Action0> onScheduleAction)

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

        This operation is thread-safe.

        Calling with a {@code null} parameter restores the default behavior:the hook returns the same object.

        Parameters:
        onScheduleAction - the function that receives the original action and shouldreturn an Action0.
      • setOnObservableReturn

         static void setOnObservableReturn(Func1<Subscription, Subscription> onObservableReturn)

        Sets a hook function that is called when the Observable.subscribe() callis about to return a Subscription unless a lockdown is in effect.

        This operation is thread-safe.

        Calling with a {@code null} parameter restores the default behavior:the hook returns the same object.

        Parameters:
        onObservableReturn - the function that is called with the Subscriber that has beensubscribed to the OnSubscribe function and returns a Subscription that will be returned bysubscribe().
      • setOnSingleReturn

         static void setOnSingleReturn(Func1<Subscription, Subscription> onSingleReturn)

        Sets a hook function that is called when the Single.subscribe() callis about to return a Subscription unless a lockdown is in effect.

        This operation is thread-safe.

        Calling with a {@code null} parameter restores the default behavior:the hook returns the same object.

        Parameters:
        onSingleReturn - the function that is called with the SingleSubscriber that has beensubscribed to the OnSubscribe function and returns a Subscription that will be returned bysubscribe().
      • setOnGenericScheduledExecutorService

         static void setOnGenericScheduledExecutorService(Func0<out ScheduledExecutorService> factory)

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

        This operation is thread-safe.

        Calling with a {@code null} parameter restores the default behavior:create the default with newScheduledThreadPool.

        For the changes to take effect, the Schedulers has to be restarted.

        Parameters:
        factory - the supplier that is called when the GenericScheduledExecutorServiceis (re)started
      • setOnObservableSubscribeError

         static void setOnObservableSubscribeError(Func1<Throwable, Throwable> onObservableSubscribeError)

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

        This operation is thread-safe.

        Calling with a {@code null} parameter restores the default behavior:the hook returns the same object.

        Parameters:
        onObservableSubscribeError - the function that is called with the crash exception and should returnan exception.
      • setOnSingleSubscribeError

         static void setOnSingleSubscribeError(Func1<Throwable, Throwable> onSingleSubscribeError)

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

        This operation is thread-safe.

        Calling with a {@code null} parameter restores the default behavior:the hook returns the same object.

        Parameters:
        onSingleSubscribeError - the function that is called with the crash exception and should returnan exception.
      • setOnCompletableSubscribeError

         static void setOnCompletableSubscribeError(Func1<Throwable, Throwable> onCompletableSubscribeError)

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

        This operation is thread-safe.

        Calling with a {@code null} parameter restores the default behavior:the hook returns the same object.

        Parameters:
        onCompletableSubscribeError - the function that is called with the crash exception and should returnan exception.
      • reset

         static void reset()

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

      • clear

         static void clear()

        Clears all hooks to be no-op (and pass-through)and onError hook to signal errors to the caller thread'sUncaughtExceptionHandler.

      • lockdown

         static void lockdown()

        Prevents changing the hooks.

      • isLockdown

         static boolean isLockdown()

        Returns true if the hooks can no longer be changed.

      • onError

         static void onError(Throwable ex)

        Consume undeliverable Throwables (acts as a global catch).

        Parameters:
        ex - the exception to handle
      • onComputationScheduler

         static Scheduler onComputationScheduler(Scheduler scheduler)

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

        Parameters:
        scheduler - the default computation scheduler
      • onIOScheduler

         static Scheduler onIOScheduler(Scheduler scheduler)

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

        Parameters:
        scheduler - the default io scheduler
      • onNewThreadScheduler

         static Scheduler onNewThreadScheduler(Scheduler scheduler)

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

        Parameters:
        scheduler - the default new thread scheduler
      • onScheduledAction

         static Action0 onScheduledAction(Action0 action)

        Hook to call before the action is scheduled, allowsdecorating the original action.

        Parameters:
        action - the original action
      • onObservableReturn

         static Subscription onObservableReturn(Subscription subscription)

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

        Parameters:
        subscription - the original subscription
      • resetAssemblyTracking

         static void resetAssemblyTracking()

        Resets the assembly tracking hooks to their default delegates toRxJavaPlugins.

      • clearAssemblyTracking

         static void clearAssemblyTracking()

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

      • enableAssemblyTracking

         static void enableAssemblyTracking()

        Sets up hooks that capture the current stacktrace when a source or anoperator is instantiated, keeping it in a field for debugging purposesand alters exceptions passing along to hold onto this stacktrace.