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

MINOR: Implement toStringBase to avoid duplicated code #14391

Closed
wants to merge 2 commits into from

Conversation

philipnee
Copy link
Contributor

This is a follow up of #14386.

The goal of this PR is to refactor the toString method to reduce duplicated code.


protected ApplicationEvent(Type type) {
protected ApplicationEvent(Type type, String owner) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

As a simplification, this is not needed I would say. We could just remove the owner var and constructor param, and leave only a simple toStringBase like this:

protected String toStringBase() {
        return "owner='" + getClass().getSimpleName() + '\'' +
            ", type=" + type;
 }

It would end up returning the simple name of the child class, which is what we want in the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe we could get rid of owner after all, and just have the calling class to print its name so that we could follow a more conventional toString(). Here's an example of how it might look like after getting rid of owner. Would this work?

ListOffsetsApplicationEvent{type=LIST_OFFSETS, future=java.util.concurrent.CompletableFuture@bdd2027[Not completed], timestampsToSearch={}, requireTimestamps=false}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure, the point was to avoid the duplicated info in the toString, result of including the class name in the base class and in the child implementations. See my previous comment related to this down below.

@@ -26,8 +26,17 @@ public class AssignmentChangeApplicationEvent extends ApplicationEvent {
final long currentTimeMs;

public AssignmentChangeApplicationEvent(final Map<TopicPartition, OffsetAndMetadata> offsets, final long currentTimeMs) {
super(Type.ASSIGNMENT_CHANGE);
super(Type.ASSIGNMENT_CHANGE, AssignmentChangeApplicationEvent.class.getSimpleName());
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would then change back to how it was if we agree on using the getClass().getSimpleName() in the toStringBase

return getClass().getSimpleName() + " {" +
"timestampsToSearch=" + timestampsToSearch + ", " +
"requireTimestamps=" + requireTimestamps + '}';
return "ListOffsetsApplicationEvent{" +
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it intentional to explicitly include "ListOffsetsApplicationEvent" here? it is in the "owner" section of the toStringBase too.

Copy link
Collaborator

Choose a reason for hiding this comment

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

(Similar for all other events that are explicitly including the class name and then calling the toStringBase)

@philipnee
Copy link
Contributor Author

Apparently @kirktrue implemented those in his previous commit. So closing this.

@philipnee philipnee closed this Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants