Class ActionRunnable<Response>

java.lang.Object
org.opensearch.common.util.concurrent.AbstractRunnable
org.opensearch.action.ActionRunnable<Response>
All Implemented Interfaces:
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.
Opensearch.internal:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final org.opensearch.core.action.ActionListener<Response>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    ActionRunnable(org.opensearch.core.action.ActionListener<Response> listener)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Calls the action listeners ActionListener.onFailure(Exception) method with the given exception.
    static <T> ActionRunnable<T>
    run(org.opensearch.core.action.ActionListener<T> listener, org.opensearch.common.CheckedRunnable<Exception> runnable)
    Creates a Runnable that invokes the given listener with null after the given runnable has executed.
    static <T> ActionRunnable<T>
    supply(org.opensearch.core.action.ActionListener<T> listener, org.opensearch.common.CheckedSupplier<T,Exception> supplier)
    Creates a Runnable that invokes the given listener with the return of the given supplier.
    static <T> ActionRunnable<T>
    wrap(org.opensearch.core.action.ActionListener<T> listener, org.opensearch.common.CheckedConsumer<org.opensearch.core.action.ActionListener<T>,Exception> consumer)
    Creates a Runnable that wraps the given listener and a consumer of it that is executed when the Runnable is run.

    Methods inherited from class org.opensearch.common.util.concurrent.AbstractRunnable

    doRun, isForceExecution, onAfter, onRejection, run

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • listener

      protected final org.opensearch.core.action.ActionListener<Response> listener
  • Constructor Details

    • ActionRunnable

      public ActionRunnable(org.opensearch.core.action.ActionListener<Response> listener)
  • Method Details

    • run

      public static <T> ActionRunnable<T> run(org.opensearch.core.action.ActionListener<T> listener, org.opensearch.common.CheckedRunnable<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(org.opensearch.core.action.ActionListener<T> listener, org.opensearch.common.CheckedSupplier<T,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(org.opensearch.core.action.ActionListener<T> listener, org.opensearch.common.CheckedConsumer<org.opensearch.core.action.ActionListener<T>,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(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