Class ChainExecutor

java.lang.Object
uk.ac.ebi.utils.runcontrol.ChainExecutor
All Implemented Interfaces:
Executor

public class ChainExecutor extends Object implements Executor
An Executor that is able to chain/stack two other executors.
Author:
brandizi
Date:
6 Oct 2015
  • Constructor Details

    • ChainExecutor

      public ChainExecutor(Executor externalExecutor, Executor internalExecutor)
      See Also:
    • ChainExecutor

      public ChainExecutor(Executor internalExecutor)
      This reduces to running one executor only, so it's conceptually equivalent to use the internalExecutor straight, but it's a base to use andThen(Executor).
  • Method Details

    • execute

      public void execute(Runnable action)
      The external executor calls the run() method of the internal executor, passing the action to it. The result is that the two executors wrap their job around the action in a nested way.
      Specified by:
      execute in interface Executor
    • wrap

      public ChainExecutor wrap(Executor externalExecutor)

      This allows you to indent multiple executors, without having to write big nested expressions. This is equivalent to creating a new executor using ChainExecutor(Executor, Executor) with the current instance as internal executor. So, it wraps the current executor with a new one.

      This also implies that a composition like ex3(ex2(ex1)) here must be created via wrap( ex1 ).wrap ( ex2 ).wrap ( ex3 ).

    • andThen

      public ChainExecutor andThen(Executor nextExecutor)
      It's the reverse of wrap(Executor). Returns an executor that passes its runnable to this executor, which then invokes nextExecutor. This can be used to chain things inside-out: new ChainExecutor ( multiAttemptsExec ).andThen ( rateLimitedExec ) TODO: never tested!