net.corda.node.utilities

## Class AffinityExecutor.Gate

- net.corda.node.utilities.AffinityExecutor.Gate

- All Implemented Interfaces:
    AffinityExecutor
  Enclosing interface:
    AffinityExecutor

      public static class AffinityExecutor.Gate
      implements AffinityExecutor

  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.

- - ### Nested Class Summary

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

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

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Gate(boolean alwaysQueue)` 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.
    `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.

  - ### Method Summary

    All Methods Instance Methods Concrete 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` | `execute(java.lang.Runnable command)`
    `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.
    `int` | `getTaskQueueSize()`
    `boolean` | `isOnThread()` Returns true if the current thread is equal to the thread this executor is backed by.
    `void` | `waitAndRun()`

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

      `checkOnThread, executeASAP, fetchFrom, flush, isOnThread`

- - ### Constructor Detail

    - #### Gate

          public Gate(boolean alwaysQueue)

      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.

      Parameters:
        `alwaysQueue` - If true, executeASAP will never short-circuit and will always queue up.

    - #### Gate

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

  - ### Method Detail

    - #### isOnThread

          public boolean isOnThread()

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

    - #### execute

          public void execute(java.lang.Runnable command)

    - #### waitAndRun

          public void waitAndRun()

    - #### getTaskQueueSize

          public int getTaskQueueSize()

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