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 Constructor Description DelegatingExecutor(Executor delegate)
New instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Completable
closeAsync()
Used to close/shutdown a resource.Completable
closeAsyncGracefully()
Used to close/shutdown a resource, similar toAsyncCloseable.closeAsync()
, but attempts to cleanup state before abruptly closing.Cancellable
execute(java.lang.Runnable task)
Executes the passedtask
as soon as possible.Completable
onClose()
Returns aCompletable
that is notified once theListenableAsyncCloseable
was closed.Cancellable
schedule(java.lang.Runnable task, long delay, java.util.concurrent.TimeUnit unit)
Executes the passedtask
afterdelay
amount ofunit
s time has passed.Cancellable
schedule(java.lang.Runnable task, java.time.Duration delay)
Executes the passedtask
afterdelay
amount time has passed.Completable
submit(java.lang.Runnable runnable)
Create a newCompletable
that executes the passedRunnable
on each subscribe.<T> Single<T>
submit(java.util.concurrent.Callable<? extends T> callable)
Creates a newSingle
that creates and executes the passedCallable
when subscribed to.<T> Single<T>
submitCallable(java.util.function.Supplier<? extends java.util.concurrent.Callable<? extends T>> callableSupplier)
Completable
submitRunnable(java.util.function.Supplier<java.lang.Runnable> runnableSupplier)
Creates a newCompletable
that creates and executes aRunnable
when subscribed to.Completable
timer(long delay, java.util.concurrent.TimeUnit unit)
Creates a newCompletable
that will complete after the time duration expires.Completable
timer(java.time.Duration delay)
Creates a newCompletable
that will complete after the time duration expires.
-
-
-
Method Detail
-
execute
public Cancellable execute(java.lang.Runnable task) throws java.util.concurrent.RejectedExecutionException
Description copied from interface:Executor
Executes the passedtask
as soon as possible.- Specified by:
execute
in interfaceExecutor
- Parameters:
task
- to execute.- Returns:
Cancellable
to 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:Executor
Executes the passedtask
afterdelay
amount ofunit
s 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 interfaceExecutor
- Parameters:
task
- to execute.delay
- The time duration that is allowed to elapse beforetask
is executed.unit
- The units fordelay
.- Returns:
Cancellable
to 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:Executor
Executes the passedtask
afterdelay
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 interfaceExecutor
- Parameters:
task
- to execute.delay
- The time duration that is allowed to elapse beforetask
is executed.- Returns:
Cancellable
to 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:Executor
Creates a newCompletable
that will complete after the time duration expires.- Specified by:
timer
in interfaceExecutor
- Parameters:
delay
- The time duration which is allowed to elapse between subscribe and termination.unit
- The units forduration
.- Returns:
- a new
Completable
that will complete after the time duration expires. - See Also:
- ReactiveX Timer.
-
timer
public Completable timer(java.time.Duration delay)
Description copied from interface:Executor
Creates a newCompletable
that will complete after the time duration expires.- Specified by:
timer
in interfaceExecutor
- 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:
- ReactiveX Timer.
-
submit
public Completable submit(java.lang.Runnable runnable)
Description copied from interface:Executor
Create a newCompletable
that executes the passedRunnable
on each subscribe.- Specified by:
submit
in interfaceExecutor
- Parameters:
runnable
- TheRunnable
to execute on each subscribe.- Returns:
- a new
Completable
that executes aRunnable
on each subscribe.
-
submitRunnable
public Completable submitRunnable(java.util.function.Supplier<java.lang.Runnable> runnableSupplier)
Description copied from interface:Executor
Creates a newCompletable
that creates and executes aRunnable
when subscribed to.- Specified by:
submitRunnable
in interfaceExecutor
- Parameters:
runnableSupplier
-Supplier
to create a newRunnable
for every subscribe of the returnedCompletable
.- Returns:
- A new
Completable
that creates and executes a newRunnable
usingrunnableSupplier
for every subscribe.
-
submit
public <T> Single<T> submit(java.util.concurrent.Callable<? extends T> callable)
Description copied from interface:Executor
Creates a newSingle
that creates and executes the passedCallable
when 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:
submitCallable
in interfaceExecutor
- Type Parameters:
T
- Type of theSingle
.- Parameters:
callableSupplier
-Supplier
to create a newCallable
for every call to subscribe to the returnedSingle
.- Returns:
- A new
Single
that creates and executes a newCallable
usingcallableSupplier
for every subscribe.
-
onClose
public Completable onClose()
Description copied from interface:ListenableAsyncCloseable
Returns aCompletable
that is notified once theListenableAsyncCloseable
was closed.- Specified by:
onClose
in interfaceListenableAsyncCloseable
- Returns:
- the
Completable
that is notified on close.
-
closeAsync
public Completable closeAsync()
Description copied from interface:AsyncCloseable
Used to close/shutdown a resource.- Specified by:
closeAsync
in interfaceAsyncCloseable
- 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 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:
closeAsyncGracefully
in interfaceAsyncCloseable
- Returns:
- A
Completable
that is notified once the close is complete.
-
-