Package org.elasticsearch.action
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
Runnable
s 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 Modifier and Type Field Description protected ActionListener<Response>
listener
-
Constructor Summary
Constructors Constructor Description ActionRunnable(ActionListener<Response> listener)
-
Method Summary
Modifier and Type Method Description void
onFailure(java.lang.Exception e)
Calls the action listenersActionListener.onFailure(Exception)
method with the given exception.static <T> ActionRunnable<T>
run(ActionListener<T> listener, org.elasticsearch.common.CheckedRunnable<java.lang.Exception> runnable)
Creates aRunnable
that invokes the given listener withnull
after the given runnable has executed.static <T> ActionRunnable<T>
supply(ActionListener<T> listener, CheckedSupplier<T,java.lang.Exception> supplier)
Creates aRunnable
that invokes the given listener with the return of the given supplier.java.lang.String
toString()
static <T> ActionRunnable<T>
wrap(ActionListener<T> listener, org.elasticsearch.common.CheckedConsumer<ActionListener<T>,java.lang.Exception> consumer)
Creates aRunnable
that wraps the given listener and a consumer of it that is executed when theRunnable
is run.Methods inherited from class org.elasticsearch.common.util.concurrent.AbstractRunnable
doRun, isForceExecution, onAfter, onRejection, run
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
listener
-
-
Constructor Details
-
ActionRunnable
-
-
Method Details
-
run
public static <T> ActionRunnable<T> run(ActionListener<T> listener, org.elasticsearch.common.CheckedRunnable<java.lang.Exception> runnable)Creates aRunnable
that invokes the given listener withnull
after 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,java.lang.Exception> supplier)Creates aRunnable
that 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
-
wrap
public static <T> ActionRunnable<T> wrap(ActionListener<T> listener, org.elasticsearch.common.CheckedConsumer<ActionListener<T>,java.lang.Exception> consumer)Creates aRunnable
that wraps the given listener and a consumer of it that is executed when theRunnable
is 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
-
onFailure
public void onFailure(java.lang.Exception e)Calls the action listenersActionListener.onFailure(Exception)
method with the given exception. This method is invoked for all exception thrown byAbstractRunnable.doRun()
- Specified by:
onFailure
in classAbstractRunnable
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-