Class OffloaderAwareExecutor
- java.lang.Object
-
- io.servicetalk.concurrent.api.internal.OffloaderAwareExecutor
-
- All Implemented Interfaces:
AsyncCloseable
,Executor
,ListenableAsyncCloseable
,Executor
,SignalOffloaderFactory
public final class OffloaderAwareExecutor extends java.lang.Object implements Executor, SignalOffloaderFactory
AnExecutor
which is also aSignalOffloaderFactory
and hence can influence a specificSignalOffloader
used by thisExecutor
.
-
-
Constructor Summary
Constructors Constructor Description OffloaderAwareExecutor(Executor delegate, SignalOffloaderFactory offloaderFactory)
New instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Completable
closeAsync()
Used to close/shutdown a resource.static Executor
ensureThreadAffinity(Executor executor)
Cancellable
execute(java.lang.Runnable task)
Executes the passedtask
as soon as possible.boolean
hasThreadAffinity()
Returnstrue
if and only if allSignalOffloader
instances will always provide thread affinity.SignalOffloader
newSignalOffloader(Executor executor)
Creates a newSignalOffloader
.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.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.servicetalk.concurrent.api.AsyncCloseable
closeAsyncGracefully
-
Methods inherited from interface io.servicetalk.concurrent.api.Executor
submit, submit, submitCallable, submitRunnable, timer, timer
-
-
-
-
Constructor Detail
-
OffloaderAwareExecutor
public OffloaderAwareExecutor(Executor delegate, SignalOffloaderFactory offloaderFactory)
New instance.- Parameters:
delegate
- ActualExecutor
to use.offloaderFactory
-SignalOffloaderFactory
to use.
-
-
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.
-
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.
-
newSignalOffloader
public SignalOffloader newSignalOffloader(Executor executor)
Description copied from interface:SignalOffloaderFactory
Creates a newSignalOffloader
.- Specified by:
newSignalOffloader
in interfaceSignalOffloaderFactory
- Parameters:
executor
-Executor
to be used by the returnedSignalOffloader
.- Returns:
- A new
SignalOffloader
.
-
hasThreadAffinity
public boolean hasThreadAffinity()
Description copied from interface:SignalOffloaderFactory
Returnstrue
if and only if allSignalOffloader
instances will always provide thread affinity. ASignalOffloader
providing thread affinity will offload all signals using a single thread.- Specified by:
hasThreadAffinity
in interfaceSignalOffloaderFactory
- Returns:
true
if and only if allSignalOffloader
instances will always provide thread affinity.
-
-