net.corda.node.utilities

## Class AffinityExecutor.ServiceAffinityExecutor

- net.corda.node.utilities.AffinityExecutor.ServiceAffinityExecutor

- All Implemented Interfaces:
    AffinityExecutor
  Enclosing interface:
    AffinityExecutor

      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.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `ServiceAffinityExecutor.Companion`

    - ### Nested classes/interfaces inherited from interface net.corda.node.utilities.AffinityExecutor

      `AffinityExecutor.DefaultImpls, AffinityExecutor.Gate, AffinityExecutor.ServiceAffinityExecutor`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static ServiceAffinityExecutor.Companion` | `Companion`

  - ### Constructor Summary

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

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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.

    - ### Methods inherited from interface net.corda.node.utilities.AffinityExecutor

      `checkOnThread, executeASAP, fetchFrom, flush, isOnThread`

- - ### Field Detail

    - #### Companion

          public static ServiceAffinityExecutor.Companion Companion

  - ### Constructor Detail

    - #### ServiceAffinityExecutor

          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.

  - ### Method Detail

    - #### afterExecute

          public void afterExecute(java.lang.Runnable r,
                                   java.lang.Throwable t)

    - #### isOnThread

          public boolean isOnThread()

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

    - #### flush

          public void flush()

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

    - #### checkOnThread

          public void checkOnThread()

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

    - #### executeASAP

          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.

    - #### fetchFrom

          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.