java.lang.Object
org.elasticsearch.common.util.concurrent.AbstractRunnable
org.elasticsearch.action.ActionRunnable<Response>
- All Implemented Interfaces:
Runnable
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCalls the action listenersActionListener.onFailure(Exception)method with the given exception.static <T> ActionRunnable<T> run(ActionListener<T> listener, CheckedRunnable<Exception> runnable) Creates aRunnablethat invokes the given listener withnullafter the given runnable has executed.static <T> ActionRunnable<T> supply(ActionListener<T> listener, CheckedSupplier<T, Exception> supplier) Creates aRunnablethat invokes the given listener with the return of the given supplier.static <T extends RefCounted>
ActionRunnable<T> supplyAndDecRef(ActionListener<T> listener, CheckedSupplier<T, Exception> supplier) Same assupply(ActionListener, CheckedSupplier)but the supplier always returns an object of reference counted result type which will have its reference count decremented after invoking the listener.toString()static <T> ActionRunnable<T> wrap(ActionListener<T> listener, CheckedConsumer<ActionListener<T>, Exception> consumer) static <T> ActionRunnable<T> wrapReleasing(ActionListener<T> listener, Releasable releasable, CheckedConsumer<ActionListener<T>, Exception> consumer) Like {#wrap} except with aReleasablewhich is released after executing the consumer, or if the action is rejected.Methods inherited from class org.elasticsearch.common.util.concurrent.AbstractRunnable
doRun, isForceExecution, onAfter, onRejection, run
-
Field Details
-
listener
-
-
Constructor Details
-
ActionRunnable
-
-
Method Details
-
run
public static <T> ActionRunnable<T> run(ActionListener<T> listener, CheckedRunnable<Exception> runnable) Creates aRunnablethat invokes the given listener withnullafter the given runnable has executed.- Parameters:
listener- Listener to invokerunnable- Runnable to execute- Returns:
- Wrapped
Runnable
-
supply
public static <T> ActionRunnable<T> supply(ActionListener<T> listener, CheckedSupplier<T, Exception> supplier) Creates aRunnablethat invokes the given listener with the return of the given supplier.- Parameters:
listener- Listener to invokesupplier- Supplier that provides value to pass to listener- Returns:
- Wrapped
Runnable
-
supplyAndDecRef
public static <T extends RefCounted> ActionRunnable<T> supplyAndDecRef(ActionListener<T> listener, CheckedSupplier<T, Exception> supplier) Same assupply(ActionListener, CheckedSupplier)but the supplier always returns an object of reference counted result type which will have its reference count decremented after invoking the listener. -
wrap
public static <T> ActionRunnable<T> wrap(ActionListener<T> listener, CheckedConsumer<ActionListener<T>, Exception> consumer) Creates aRunnablethat wraps the given listener and a consumer of it that is executed when theRunnableis run. InvokesActionListener.onFailure(Exception)on it if an exception is thrown on executing the consumer.- Type Parameters:
T- Type of the givenActionListener- Parameters:
listener- ActionListener to wrapconsumer- Consumer of wrappedActionListener- Returns:
- Wrapped
Runnable
-
wrapReleasing
public static <T> ActionRunnable<T> wrapReleasing(ActionListener<T> listener, Releasable releasable, CheckedConsumer<ActionListener<T>, Exception> consumer) Like {#wrap} except with aReleasablewhich is released after executing the consumer, or if the action is rejected. This is particularly useful for submitting actions holding resources to a threadpool which might have a bounded queue. -
onFailure
Calls the action listenersActionListener.onFailure(Exception)method with the given exception. This method is invoked for all exception thrown byAbstractRunnable.doRun()- Specified by:
onFailurein classAbstractRunnable
-
toString
-