-
-
Notifications
You must be signed in to change notification settings - Fork 15.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[4.1] Futures removeListener: JavaDoc and implementation are inconsistent - duplicate listeners #5351
Labels
Comments
Splitted the proposal to new issue: #5352 |
@mickare - Thanks for bringing this to our attention. The javadocs should be updated. Let me take care. |
Scottmitch
added a commit
to Scottmitch/netty
that referenced
this issue
Jun 8, 2016
Motivation: The javaDocs for Future.removeListener do not clarify that only the first occurrence of the listener is guaranteed to be removed. Modifications: - Clarify the javaDocs for Future.removeListener[s] so it is known that the only the first occurrence of the listener will be removed. Result: Fixes netty#5351
Scottmitch
added a commit
that referenced
this issue
Jun 8, 2016
Motivation: The javaDocs for Future.removeListener do not clarify that only the first occurrence of the listener is guaranteed to be removed. Modifications: - Clarify the javaDocs for Future.removeListener[s] so it is known that the only the first occurrence of the listener will be removed. Result: Fixes #5351
liuzhengyang
pushed a commit
to liuzhengyang/netty
that referenced
this issue
Sep 10, 2017
Motivation: The javaDocs for Future.removeListener do not clarify that only the first occurrence of the listener is guaranteed to be removed. Modifications: - Clarify the javaDocs for Future.removeListener[s] so it is known that the only the first occurrence of the listener will be removed. Result: Fixes netty#5351
pulllock
pushed a commit
to pulllock/netty
that referenced
this issue
Oct 19, 2023
Motivation: The javaDocs for Future.removeListener do not clarify that only the first occurrence of the listener is guaranteed to be removed. Modifications: - Clarify the javaDocs for Future.removeListener[s] so it is known that the only the first occurrence of the listener will be removed. Result: Fixes netty#5351
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Netty version: 4.1.0.CR7
Context:
I encountered an inconsistency between the JavaDoc description and implementation of the Future.
I want to add multiple times (e.g. x 1000) the same close listener to a channel but I don't want this listener to be called multiple times.
Also I don't want to remove the listener prior to adding it. I could do this but I don't like the wasteful Java array copy calls.
JavaDoc vs Implementation
The Netty 4.1 JavaDoc on Future says:
But if I add multiple times the same listener to the future, only the first entry is removed. (see implementation)
With the current implementation in mind the JavaDoc should state that only the first occurrence of the listener is removed. Like:
More on futures (could be an independent proposal):Even more the listener is called multiple times. I think futures are part of the observer pattern. That means an observer should be notified only once an event occurs.That means there should be no duplicate listeners in the future.E.g.: the listeners array sould be changed to a set, or duplicates avoided.
Or is there a puprose, that I can not see at the moment? Like performance? But if it is performance, then would not multiple calls on the same listener effect the performance? For example:With the current implementationcloseListener
would be called as often as the methodoftenCalled
.I had just a discussion that there could be a use-case of a self-incrementing counter, that uses the future to add a future increment. This counter would need multiple entries.
Therefore I propose to add a new method "addListenerIfAbsent", that could resolve the proposal. I'll create a new issue for that.
Best regards,
Michael
The text was updated successfully, but these errors were encountered: