Skip to content

Commit 46bc786

Browse files
authored
Note in Javadocs that SubscribableListener fires once (elastic#128131) (elastic#128515)
Spell out that multiple completions of a `SubscribableListener` race to be chosen as the winner that is passed to subscribed listeners, such that the subscribed listeners all fire at most once.
1 parent 19f9479 commit 46bc786

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

server/src/main/java/org/elasticsearch/action/support/SubscribableListener.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@
3232
import java.util.concurrent.Executor;
3333

3434
/**
35-
* An {@link ActionListener} to which other {@link ActionListener} instances can subscribe, such that when this listener is
36-
* completed it fans-out its result to the subscribed listeners.
35+
* An {@link ActionListener} to which other {@link ActionListener} instances can subscribe, such that when this listener is completed it
36+
* fans-out its result to the subscribed listeners.
3737
* <p>
38-
* If this listener is complete, {@link #addListener} completes the subscribing listener immediately
39-
* with the result with which this listener was completed. Otherwise, the subscribing listener is retained
40-
* and completed when this listener is completed.
38+
* If this listener is complete, {@link #addListener} completes the subscribing listener immediately with the result with which this
39+
* listener was completed. Otherwise, the subscribing listener is retained and completed when this listener is completed.
4140
* <p>
42-
* Exceptions are passed to subscribed listeners without modification. {@link ListenableActionFuture} and {@link ListenableFuture} are child
43-
* classes that provide additional exception handling.
41+
* Exceptions are passed to subscribed listeners without modification. {@link ListenableActionFuture} and {@link ListenableFuture} are
42+
* subclasses which modify the exceptions passed to subscribed listeners.
43+
* <p>
44+
* If this listener is completed more than once then all results other than the first (whether successful or otherwise) are silently
45+
* discarded. All subscribed listeners will be notified of the same result, exactly once, even if several completions occur concurrently.
4446
* <p>
4547
* A sequence of async steps can be chained together using a series of {@link SubscribableListener}s, similar to {@link CompletionStage}
4648
* (without the {@code catch (Throwable t)}). Listeners can be created for each step, where the next step subscribes to the result of the

0 commit comments

Comments
 (0)