Package io.servicetalk.concurrent.api
Class DelegatingExecutor
- java.lang.Object
-
- io.servicetalk.concurrent.api.DelegatingExecutor
-
- All Implemented Interfaces:
AsyncCloseable,Executor,ListenableAsyncCloseable,Executor
public abstract class DelegatingExecutor extends java.lang.Object implements Executor
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedDelegatingExecutor(Executor delegate)New instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletablecloseAsync()Used to close/shutdown a resource.CompletablecloseAsyncGracefully()Used to close/shutdown a resource, similar toAsyncCloseable.closeAsync(), but attempts to cleanup state before abruptly closing.protected Executordelegate()Returns the delegateExecutorused.Cancellableexecute(java.lang.Runnable task)Executes the passedtaskas soon as possible.CompletableonClose()Returns aCompletablethat is notified once theListenableAsyncCloseablewas closed.Cancellableschedule(java.lang.Runnable task, long delay, java.util.concurrent.TimeUnit unit)Executes the passedtaskafterdelayamount ofunits time has passed.Cancellableschedule(java.lang.Runnable task, java.time.Duration delay)Executes the passedtaskafterdelayamount time has passed.Completablesubmit(java.lang.Runnable runnable)Create a newCompletablethat executes the passedRunnableon each subscribe.<T> Single<T>submit(java.util.concurrent.Callable<? extends T> callable)Creates a newSinglethat creates and executes the passedCallablewhen subscribed to.<T> Single<T>submitCallable(java.util.function.Supplier<? extends java.util.concurrent.Callable<? extends T>> callableSupplier)CompletablesubmitRunnable(java.util.function.Supplier<java.lang.Runnable> runnableSupplier)Creates a newCompletablethat creates and executes aRunnablewhen subscribed to.Completabletimer(long delay, java.util.concurrent.TimeUnit unit)Creates a newCompletablethat will complete after the time duration expires.Completabletimer(java.time.Duration delay)Creates a newCompletablethat will complete after the time duration expires.
-
-
-
Method Detail
-
delegate
protected Executor delegate()
Returns the delegateExecutorused.- Returns:
- The delegate
Executorused.
-
execute
public Cancellable execute(java.lang.Runnable task) throws java.util.concurrent.RejectedExecutionException
Description copied from interface:ExecutorExecutes the passedtaskas soon as possible.- Specified by:
executein interfaceExecutor- Parameters:
task- to execute.- Returns:
Cancellableto cancel the task if not yet executed.- Throws:
java.util.concurrent.RejectedExecutionException- If the task is rejected.
-
schedule
public Cancellable schedule(java.lang.Runnable task, long delay, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.RejectedExecutionException
Description copied from interface:ExecutorExecutes the passedtaskafterdelayamount ofunits 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:
schedulein interfaceExecutor- Parameters:
task- to execute.delay- The time duration that is allowed to elapse beforetaskis executed.unit- The units fordelay.- Returns:
Cancellableto cancel the task if not yet executed.- Throws:
java.util.concurrent.RejectedExecutionException- If the task is rejected.
-
schedule
public Cancellable schedule(java.lang.Runnable task, java.time.Duration delay) throws java.util.concurrent.RejectedExecutionException
Description copied from interface:ExecutorExecutes the passedtaskafterdelayamount 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:
schedulein interfaceExecutor- Parameters:
task- to execute.delay- The time duration that is allowed to elapse beforetaskis executed.- Returns:
Cancellableto cancel the task if not yet executed.- Throws:
java.util.concurrent.RejectedExecutionException- If the task is rejected.
-
timer
public Completable timer(long delay, java.util.concurrent.TimeUnit unit)
Description copied from interface:ExecutorCreates a newCompletablethat will complete after the time duration expires.- Specified by:
timerin interfaceExecutor- Parameters:
delay- The time duration which is allowed to elapse between subscribe and termination.unit- The units forduration.- Returns:
- a new
Completablethat will complete after the time duration expires. - See Also:
- ReactiveX Timer.
-
timer
public Completable timer(java.time.Duration delay)
Description copied from interface:ExecutorCreates a newCompletablethat will complete after the time duration expires.- Specified by:
timerin interfaceExecutor- Parameters:
delay- The time duration which is allowed to elapse between subscribe and termination.- Returns:
- a new
Completablethat will complete after the time duration expires. - See Also:
- ReactiveX Timer.
-
submit
public Completable submit(java.lang.Runnable runnable)
Description copied from interface:ExecutorCreate a newCompletablethat executes the passedRunnableon each subscribe.- Specified by:
submitin interfaceExecutor- Parameters:
runnable- TheRunnableto execute on each subscribe.- Returns:
- a new
Completablethat executes aRunnableon each subscribe.
-
submitRunnable
public Completable submitRunnable(java.util.function.Supplier<java.lang.Runnable> runnableSupplier)
Description copied from interface:ExecutorCreates a newCompletablethat creates and executes aRunnablewhen subscribed to.- Specified by:
submitRunnablein interfaceExecutor- Parameters:
runnableSupplier-Supplierto create a newRunnablefor every subscribe of the returnedCompletable.- Returns:
- A new
Completablethat creates and executes a newRunnableusingrunnableSupplierfor every subscribe.
-
submit
public <T> Single<T> submit(java.util.concurrent.Callable<? extends T> callable)
Description copied from interface:ExecutorCreates a newSinglethat creates and executes the passedCallablewhen subscribed to.
-
submitCallable
public <T> Single<T> submitCallable(java.util.function.Supplier<? extends java.util.concurrent.Callable<? extends T>> callableSupplier)
Description copied from interface:Executor- Specified by:
submitCallablein interfaceExecutor- Type Parameters:
T- Type of theSingle.- Parameters:
callableSupplier-Supplierto create a newCallablefor every call to subscribe to the returnedSingle.- Returns:
- A new
Singlethat creates and executes a newCallableusingcallableSupplierfor every subscribe.
-
onClose
public Completable onClose()
Description copied from interface:ListenableAsyncCloseableReturns aCompletablethat is notified once theListenableAsyncCloseablewas closed.- Specified by:
onClosein interfaceListenableAsyncCloseable- Returns:
- the
Completablethat is notified on close.
-
closeAsync
public Completable closeAsync()
Description copied from interface:AsyncCloseableUsed to close/shutdown a resource.- Specified by:
closeAsyncin interfaceAsyncCloseable- Returns:
- A
Completablethat is notified once the close is complete.
-
closeAsyncGracefully
public Completable closeAsyncGracefully()
Description copied from interface:AsyncCloseableUsed to close/shutdown a resource, similar toAsyncCloseable.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 toAsyncCloseable.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:
closeAsyncGracefullyin interfaceAsyncCloseable- Returns:
- A
Completablethat is notified once the close is complete.
-
-