Package org.elasticsearch.action
Class ResultDeduplicator<T,R>
java.lang.Object
org.elasticsearch.action.ResultDeduplicator<T,R>
- Type Parameters:
T
- Request type
Deduplicator for arbitrary keys and results that can be used to ensure a given action is only executed once at a time for a given
request.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Remove all tracked requests from this instance so that the first timeexecuteOnce(T, org.elasticsearch.action.ActionListener<R>, java.util.function.BiConsumer<T, org.elasticsearch.action.ActionListener<R>>)
is invoked with any request it triggers an actual request execution.void
executeOnce
(T request, ActionListener<R> listener, BiConsumer<T, ActionListener<R>> callback) Ensures a given request not executed multiple times when another equal request is already in-flight.int
size()
-
Constructor Details
-
ResultDeduplicator
-
-
Method Details
-
executeOnce
public void executeOnce(T request, ActionListener<R> listener, BiConsumer<T, ActionListener<R>> callback) Ensures a given request not executed multiple times when another equal request is already in-flight. If the request is not yet known to the deduplicator it will invoke the passed callback with anActionListener
that must be completed by the caller when the request completes. Once that listener is completed the request will be removed from the deduplicator's internal state. If the request is already known to the deduplicator it will keep track of the given listener and invoke it when the listener passed to the callback on first invocation is completed.- Parameters:
request
- Request to deduplicatelistener
- Listener to invoke on request completioncallback
- Callback to be invoked with request and completion listener the first time the request is added to the deduplicator
-
clear
public void clear()Remove all tracked requests from this instance so that the first timeexecuteOnce(T, org.elasticsearch.action.ActionListener<R>, java.util.function.BiConsumer<T, org.elasticsearch.action.ActionListener<R>>)
is invoked with any request it triggers an actual request execution. Use this e.g. for requests to master that need to be sent again on master failover. -
size
public int size()
-