public static class AffinityExecutor.ServiceAffinityExecutor implements AffinityExecutor
An executor backed by thread pool (which may often have a single thread) which makes it easy to schedule tasks in the future and verify code is running on the executor.
Modifier and Type | Class and Description |
---|---|
static class |
ServiceAffinityExecutor.Companion |
AffinityExecutor.DefaultImpls, AffinityExecutor.Gate, AffinityExecutor.ServiceAffinityExecutor
Modifier and Type | Field and Description |
---|---|
static ServiceAffinityExecutor.Companion |
Companion |
Constructor and Description |
---|
ServiceAffinityExecutor(java.lang.String threadName,
int numThreads)
An executor backed by thread pool (which may often have a single thread) which makes it easy to schedule
tasks in the future and verify code is running on the executor.
|
Modifier and Type | Method and Description |
---|---|
void |
afterExecute(java.lang.Runnable r,
java.lang.Throwable t) |
void |
checkOnThread()
Throws an IllegalStateException if the current thread is not one of the threads this executor is backed by.
|
void |
executeASAP(kotlin.jvm.functions.Function0<kotlin.Unit> runnable)
If isOnThread() then runnable is invoked immediately, otherwise the closure is queued onto the backing thread.
|
<T> T |
fetchFrom(kotlin.jvm.functions.Function0<? extends T> fetcher)
Runs the given function on the executor, blocking until the result is available. Be careful not to deadlock this
way! Make sure the executor can't possibly be waiting for the calling thread.
|
void |
flush()
Run the executor until there are no tasks pending and none executing.
|
boolean |
isOnThread()
Returns true if the current thread is equal to the thread this executor is backed by.
|
checkOnThread, executeASAP, fetchFrom, flush, isOnThread
public static ServiceAffinityExecutor.Companion Companion
public ServiceAffinityExecutor(java.lang.String threadName, int numThreads)
An executor backed by thread pool (which may often have a single thread) which makes it easy to schedule tasks in the future and verify code is running on the executor.
public void afterExecute(java.lang.Runnable r, java.lang.Throwable t)
public boolean isOnThread()
Returns true if the current thread is equal to the thread this executor is backed by.
public void flush()
Run the executor until there are no tasks pending and none executing.
public void checkOnThread()
Throws an IllegalStateException if the current thread is not one of the threads this executor is backed by.
public void executeASAP(kotlin.jvm.functions.Function0<kotlin.Unit> runnable)
If isOnThread() then runnable is invoked immediately, otherwise the closure is queued onto the backing thread.
public <T> T fetchFrom(kotlin.jvm.functions.Function0<? extends T> fetcher)
Runs the given function on the executor, blocking until the result is available. Be careful not to deadlock this way! Make sure the executor can't possibly be waiting for the calling thread.