Skip to content

MINOR: Implement toStringBase to avoid duplicated code#14391

Closed
philipnee wants to merge 2 commits into
apache:trunkfrom
philipnee:minor-to-string-base
Closed

MINOR: Implement toStringBase to avoid duplicated code#14391
philipnee wants to merge 2 commits into
apache:trunkfrom
philipnee:minor-to-string-base

Conversation

@philipnee

Copy link
Copy Markdown
Contributor

This is a follow up of #14386.

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

@philipnee philipnee added the ctr Consumer Threading Refactor (KIP-848) label Sep 15, 2023
protected final String owner;

protected ApplicationEvent(Type type) {
protected ApplicationEvent(Type type, String owner) {

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
Member

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.


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

Copy link
Copy Markdown
Member

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
Copy Markdown
Member

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
Copy Markdown
Member

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
Copy Markdown
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

ctr Consumer Threading Refactor (KIP-848)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants