Class DelegatingExecutor
- All Implemented Interfaces:
AsyncCloseable
,Executor
,ListenableAsyncCloseable
,Executor
,TimeSource
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionUsed to close/shutdown a resource.Used to close/shutdown a resource, similar toAsyncCloseable.closeAsync()
, but attempts to cleanup state before abruptly closing.long
currentTime
(TimeUnit unit) Returns the internal clock time in the specifiedunit
.protected Executor
delegate()
Returns the delegateExecutor
used.Executes the passedtask
as soon as possible.onClose()
Returns aCompletable
that is notified once theListenableAsyncCloseable
was closed.Returns aCompletable
that is notified when closing begins.Executes the passedtask
afterdelay
amount ofunit
s time has passed.Executes the passedtask
afterdelay
amount time has passed.Create a newCompletable
that executes the passedRunnable
on each subscribe.<T> Single<T>
<T> Single<T>
submitCallable
(Supplier<? extends Callable<? extends T>> callableSupplier) submitRunnable
(Supplier<Runnable> runnableSupplier) Creates a newCompletable
that creates and executes aRunnable
when subscribed to.Creates a newCompletable
that will complete after the time duration expires.Creates a newCompletable
that will complete after the time duration expires.toString()
-
Constructor Details
-
DelegatingExecutor
New instance.- Parameters:
delegate
-Executor
to delegate all calls to.
-
-
Method Details
-
toString
-
delegate
Returns the delegateExecutor
used.- Returns:
- The delegate
Executor
used.
-
execute
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:
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 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:
RejectedExecutionException
- If the task is rejected.
-
schedule
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:
RejectedExecutionException
- If the task is rejected.
-
timer
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:
-
timer
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:
-
submit
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
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
Description copied from interface:Executor
-
submitCallable
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.
-
currentTime
Description copied from interface:TimeSource
Returns the internal clock time in the specifiedunit
.- Specified by:
currentTime
in interfaceExecutor
- Specified by:
currentTime
in interfaceTimeSource
- Parameters:
unit
- the time unit to calculate- Returns:
- the internal clock time in the specified
unit
.
-
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.
-
onClosing
Description copied from interface:ListenableAsyncCloseable
Returns aCompletable
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 aconnection: 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 interfaceListenableAsyncCloseable
- Returns:
- a
Completable
that is notified when closing begins.
-
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
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.
-