-
Notifications
You must be signed in to change notification settings - Fork 11
refactor: apply some Java best practices #181
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
Conversation
Signed-off-by: Keran Yang <[email protected]>
Signed-off-by: Keran Yang <[email protected]>
Signed-off-by: Keran Yang <[email protected]>
Signed-off-by: Keran Yang <[email protected]>
Signed-off-by: Keran Yang <[email protected]>
Signed-off-by: Keran Yang <[email protected]>
Signed-off-by: Keran Yang <[email protected]>
src/main/java/io/numaproj/numaflow/info/ServerInfoAccessorImpl.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Keran Yang <[email protected]>
Would like to include this in our next release that work with numaflow 1.5. I am converting this to draft for now. Will merge once I get an approval from @yhl25 . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make sure these changes works with both v1.4 and v1.5 version of Numaflow
@yhl25 Sure, I will merge this and use numaflow E2E tests to verify that it works with both. |
src/main/java/io/numaproj/numaflow/accumulator/model/Message.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Keran Yang <[email protected]>
Signed-off-by: Keran Yang <[email protected]>
Applying some Java best practices that I learnt from Effective Java. Will selectively apply more as I continue reading.
We no longer need to close FileWriter by ourselves because FileWriter implements
java.lang.AutoCloseable
. The try-with-resources will automatically close it after finish writing, using the native FileWriter implementation of AutoCloseable.In class Response,
private final Boolean success;
is changed toprivate final boolean success;
such that when we new a Response object with a primitive boolean value, Java doesn't need to perform unnecessary boxing. We don't have a case where success can be null.* Mark Message getters as protected.Such that we don't expose them to users. This is technically a backward-incompatible change if an existing user uses getters. Normally, Messages are instantiated right before sending to the next processing unit. I cannot think of a use case for getter. If we don't expect user to use getter, I think we should not expose it.static final
.Such that it's shared by all
toDrop
calls. We don't need to instantiate a new string array every time user usestoDrop
.Message is an immutable class. Without defensive copying, user could modify the content of a Message unknowingly by modifying the input reference params.
A utility class should never be instantiated.
We don't expect Message and Response class to be extended.