Class DelegatingExecutor

java.lang.Object
io.servicetalk.concurrent.api.DelegatingExecutor
All Implemented Interfaces:
AsyncCloseable, Executor, ListenableAsyncCloseable, Executor, TimeSource

public abstract class DelegatingExecutor extends Object implements Executor
An Executor that simply delegates all calls to another Executor.
  • Constructor Details

    • DelegatingExecutor

      protected DelegatingExecutor(Executor delegate)
      New instance.
      Parameters:
      delegate - Executor to delegate all calls to.
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • delegate

      protected Executor delegate()
      Returns the delegate Executor used.
      Returns:
      The delegate Executor used.
    • execute

      public Cancellable execute(Runnable task) throws RejectedExecutionException
      Description copied from interface: Executor
      Executes the passed task as soon as possible.
      Specified by:
      execute in interface Executor
      Parameters:
      task - to execute.
      Returns:
      Cancellable to cancel the task if not yet executed.
      Throws:
      RejectedExecutionException - If the task is rejected.
    • schedule

      public Cancellable schedule(Runnable task, long delay, TimeUnit unit) throws RejectedExecutionException
      Description copied from interface: Executor
      Executes the passed task after delay amount of units time has passed.

      Note this method is not guaranteed to provide real time execution. For example implementations are free to consolidate tasks into time buckets to reduce the overhead of timer management at the cost of reduced timer fidelity.

      Specified by:
      schedule in interface Executor
      Parameters:
      task - to execute.
      delay - The time duration that is allowed to elapse before task is executed.
      unit - The units for delay.
      Returns:
      Cancellable to cancel the task if not yet executed.
      Throws:
      RejectedExecutionException - If the task is rejected.
    • schedule

      public Cancellable schedule(Runnable task, Duration delay) throws RejectedExecutionException
      Description copied from interface: Executor
      Executes the passed task after delay amount time has passed.

      Note this method is not guaranteed to provide real time execution. For example implementations are free to consolidate tasks into time buckets to reduce the overhead of timer management at the cost of reduced timer fidelity.

      Specified by:
      schedule in interface Executor
      Parameters:
      task - to execute.
      delay - The time duration that is allowed to elapse before task is executed.
      Returns:
      Cancellable to cancel the task if not yet executed.
      Throws:
      RejectedExecutionException - If the task is rejected.
    • timer

      public Completable timer(long delay, TimeUnit unit)
      Description copied from interface: Executor
      Creates a new Completable that will complete after the time duration expires.
      Specified by:
      timer in interface Executor
      Parameters:
      delay - The time duration which is allowed to elapse between subscribe and termination.
      unit - The units for duration.
      Returns:
      a new Completable that will complete after the time duration expires.
      See Also:
    • timer

      public Completable timer(Duration delay)
      Description copied from interface: Executor
      Creates a new Completable that will complete after the time duration expires.
      Specified by:
      timer in interface Executor
      Parameters:
      delay - The time duration which is allowed to elapse between subscribe and termination.
      Returns:
      a new Completable that will complete after the time duration expires.
      See Also:
    • submit

      public Completable submit(Runnable runnable)
      Description copied from interface: Executor
      Create a new Completable that executes the passed Runnable on each subscribe.
      Specified by:
      submit in interface Executor
      Parameters:
      runnable - The Runnable to execute on each subscribe.
      Returns:
      a new Completable that executes a Runnable on each subscribe.
    • submitRunnable

      public Completable submitRunnable(Supplier<Runnable> runnableSupplier)
      Description copied from interface: Executor
      Creates a new Completable that creates and executes a Runnable when subscribed to.
      Specified by:
      submitRunnable in interface Executor
      Parameters:
      runnableSupplier - Supplier to create a new Runnable for every subscribe of the returned Completable.
      Returns:
      A new Completable that creates and executes a new Runnable using runnableSupplier for every subscribe.
    • submit

      public <T> Single<T> submit(Callable<? extends T> callable)
      Description copied from interface: Executor
      Creates a new Single that creates and executes the passed Callable when subscribed to.
      Specified by:
      submit in interface Executor
      Type Parameters:
      T - Type of the Single.
      Parameters:
      callable - The Callable to execute on each subscribe.
      Returns:
      a new Single that obtains a Callable from callableSupplier and executes it on each subscribe.
    • submitCallable

      public <T> Single<T> submitCallable(Supplier<? extends Callable<? extends T>> callableSupplier)
      Description copied from interface: Executor
      Create a new Single that obtains a Callable from callableSupplier and executes on each subscribe.
      Specified by:
      submitCallable in interface Executor
      Type Parameters:
      T - Type of the Single.
      Parameters:
      callableSupplier - Supplier to create a new Callable for every call to subscribe to the returned Single.
      Returns:
      A new Single that creates and executes a new Callable using callableSupplier for every subscribe.
    • currentTime

      public long currentTime(TimeUnit unit)
      Description copied from interface: TimeSource
      Returns the internal clock time in the specified unit.
      Specified by:
      currentTime in interface Executor
      Specified by:
      currentTime in interface TimeSource
      Parameters:
      unit - the time unit to calculate
      Returns:
      the internal clock time in the specified unit.
    • onClose

      public Completable onClose()
      Description copied from interface: ListenableAsyncCloseable
      Returns a Completable that is notified once the ListenableAsyncCloseable was closed.
      Specified by:
      onClose in interface ListenableAsyncCloseable
      Returns:
      the Completable that is notified on close.
    • onClosing

      public Completable onClosing()
      Description copied from interface: ListenableAsyncCloseable
      Returns a Completable that is notified when closing begins.

      Closing begin might be when a close operation is initiated locally (e.g. subscribing to AsyncCloseable.closeAsync()) or it could also be a transport event received from a remote peer (e.g. read a connection: close header).

      For backwards compatibility this method maybe functionally equivalent to ListenableAsyncCloseable.onClose(). Therefore, provides a best-effort leading edge notification of closing, but may fall back to notification on trailing edge.

      The goal of this method is often to notify asap when closing so this method may not be offloaded and care must be taken to avoid blocking if subscribing to the return Completable.

      Specified by:
      onClosing in interface ListenableAsyncCloseable
      Returns:
      a Completable that is notified when closing begins.
    • closeAsync

      public Completable closeAsync()
      Description copied from interface: AsyncCloseable
      Used to close/shutdown a resource.
      Specified by:
      closeAsync in interface AsyncCloseable
      Returns:
      A Completable that is notified once the close is complete.
    • closeAsyncGracefully

      public Completable closeAsyncGracefully()
      Description copied from interface: AsyncCloseable
      Used to close/shutdown a resource, similar to AsyncCloseable.closeAsync(), but attempts to cleanup state before abruptly closing. This provides a hint that implementations can use to stop accepting new work and finish in flight work. This method is implemented on a "best effort" basis and may be equivalent to AsyncCloseable.closeAsync().

      Note: Implementations may or may not apply a timeout for this operation to complete, if a caller does not want to wait indefinitely, and are unsure if the implementation applies a timeout, it is advisable to apply a timeout and force a call to AsyncCloseable.closeAsync().

      Specified by:
      closeAsyncGracefully in interface AsyncCloseable
      Returns:
      A Completable that is notified once the close is complete.