Class ActionRunnable<Response>

java.lang.Object
org.elasticsearch.common.util.concurrent.AbstractRunnable
org.elasticsearch.action.ActionRunnable<Response>
All Implemented Interfaces:
java.lang.Runnable

public abstract class ActionRunnable<Response>
extends AbstractRunnable
Base class for Runnables that need to call ActionListener.onFailure(Exception) in case an uncaught exception or error is thrown while the actual action is run.
  • Field Details

  • Constructor Details

  • Method Details

    • run

      public static <T> ActionRunnable<T> run​(ActionListener<T> listener, org.elasticsearch.common.CheckedRunnable<java.lang.Exception> runnable)
      Creates a Runnable that invokes the given listener with null after the given runnable has executed.
      Parameters:
      listener - Listener to invoke
      runnable - Runnable to execute
      Returns:
      Wrapped Runnable
    • supply

      public static <T> ActionRunnable<T> supply​(ActionListener<T> listener, CheckedSupplier<T,​java.lang.Exception> supplier)
      Creates a Runnable that invokes the given listener with the return of the given supplier.
      Parameters:
      listener - Listener to invoke
      supplier - Supplier that provides value to pass to listener
      Returns:
      Wrapped Runnable
    • wrap

      public static <T> ActionRunnable<T> wrap​(ActionListener<T> listener, org.elasticsearch.common.CheckedConsumer<ActionListener<T>,​java.lang.Exception> consumer)
      Creates a Runnable that wraps the given listener and a consumer of it that is executed when the Runnable is run. Invokes ActionListener.onFailure(Exception) on it if an exception is thrown on executing the consumer.
      Type Parameters:
      T - Type of the given ActionListener
      Parameters:
      listener - ActionListener to wrap
      consumer - Consumer of wrapped ActionListener
      Returns:
      Wrapped Runnable
    • onFailure

      public void onFailure​(java.lang.Exception e)
      Calls the action listeners ActionListener.onFailure(Exception) method with the given exception. This method is invoked for all exception thrown by AbstractRunnable.doRun()
      Specified by:
      onFailure in class AbstractRunnable