Skip to content
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

Cleanup more ActionListener Delegation Spots #69662

Merged

Conversation

original-brownbear
Copy link
Member

Cleaning up some of the remaining spots where the short-wrapper methods
could be used.

Cleaning up the remaining spots where the short-wrapper methods
could be used that I could find.
@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Feb 28, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR looks fine, but I have a general comment about it and recent PRs around delegation.

The concept of delegation is good here. We often have listeners that need to be wrapped to append some response or failure logic. The problem I see is with the multitude of options now available. Looking at ActionListener now, there are quite a few abstract classes for dealing with delegation. Several examples in this PR use ActionListener.Delegating. That seems to be so that the delegate is a member that is available for use within onResponse. But I find this confusing because it's difficult to understand when one class or lambda method should be used over another.

I guess my general question is where is the end goal here? While the raw lines of code have been reduced, IMO the complexity has grown considerably in understanding which utilities are available for composing action listeners.

@original-brownbear
Copy link
Member Author

Thanks for taking a look + sorry for the delay here @rjernst I completely missed your review :(

I guess my general question is where is the end goal here? While the raw lines of code have been reduced, IMO the complexity has grown considerably in understanding which utilities are available for composing action listeners.

The goal here isn't just in reducing LoC and cosmetics. It's mostly to get a tighter handler on what callbacks can throw where via assertions that were recently added like #69420 and to force certain patterns on these listeners. We had a number of bugs from not having these assertions where completely unexpected failures in these listeners would just be logged somewhere (sometimes even at debug) while also causing a memory leak.

But I find this confusing because it's difficult to understand when one class or lambda method should be used over another.

That's a fair criticism. I guess I mostly go with the lambda version so long as there's not need to reference this on the listener. But admittedly in a few spots I broke with that rule when the body of the handling method was very large to make things easier to read (IMO).

The problem I see is with the multitude of options now available.

++ I think ideally we should try and move to a world where things with clearly defined behavior like Delegating survive, while things like org.elasticsearch.action.ActionListener#wrap(org.elasticsearch.common.CheckedConsumer<Response,? extends java.lang.Exception>, java.util.function.Consumer<java.lang.Exception>) that continually cause trouble via double invocations (onResponse can call onFailure causing runAfter etc. to behave strangely and such) go away step-by-step by making them stricter in regards to exception handling like we did in e.g. #50886.

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation @original-brownbear. The vision and this PR LGTM.

@original-brownbear
Copy link
Member Author

@elasticmachine update branch

@original-brownbear
Copy link
Member Author

Thanks Ryan!

@original-brownbear original-brownbear merged commit b6a3698 into elastic:master Mar 16, 2021
@original-brownbear original-brownbear deleted the shorter-listeners-2 branch March 16, 2021 07:47
original-brownbear added a commit to original-brownbear/elasticsearch that referenced this pull request Mar 16, 2021
Cleaning up the remaining spots where the short-wrapper methods
could be used that I could find.
original-brownbear added a commit that referenced this pull request Mar 16, 2021
Cleaning up the remaining spots where the short-wrapper methods
could be used that I could find.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Core Core issues without another label >non-issue Team:Core/Infra Meta label for core/infra team v7.13.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants