net.corda.node.utilities

## Interface AffinityExecutor

- All Known Implementing Classes:
    AffinityExecutor.Gate, AffinityExecutor.ServiceAffinityExecutor

      public AffinityExecutor

  An extended executor interface that supports thread affinity assertions and short circuiting. This can be useful for ensuring code runs on the right thread, and also for unit testing.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Interface and Description
    --- | ---
    `static class` | `AffinityExecutor.DefaultImpls` An extended executor interface that supports thread affinity assertions and short circuiting. This can be useful for ensuring code runs on the right thread, and also for unit testing.
    `static class` | `AffinityExecutor.Gate` An executor useful for unit tests: allows the current thread to block until a command arrives from another thread, which is then executed. Inbound closures/commands stack up until they are cleared by looping.
    `static class` | `AffinityExecutor.ServiceAffinityExecutor` 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.

  - ### Method Summary

    All Methods Instance Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `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.

- - ### Method Detail

    - #### isOnThread

          boolean isOnThread()

      Returns true if the current thread is equal to the thread this executor is backed by.

    - #### checkOnThread

          void checkOnThread()

      Throws an IllegalStateException if the current thread is not one of the threads this executor is backed by.

    - #### executeASAP

          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.

    - #### fetchFrom

          <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.

    - #### flush

          void flush()

      Run the executor until there are no tasks pending and none executing.