-
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
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6a0bd1a
1. ServerInfo - use try-with-resource to write
KeranYang a643050
2. sink response - avoid unnecessary boxing/unboxing
KeranYang c37c9e5
3. protected getter for Message
KeranYang ee3a3ed
4. make DROP_TAGS a static final
KeranYang c288666
5. defensive copy
KeranYang 8bc8aff
6. private constructor for utility classes
KeranYang 2feb3ed
7. don't think Message and Response should be extended
KeranYang bd7ef4d
address rohan's comments
KeranYang 5f0de33
address yashash's comments
KeranYang b138903
address yashash's comments
KeranYang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
29 changes: 14 additions & 15 deletions
29
src/main/java/io/numaproj/numaflow/accumulator/Constants.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
package io.numaproj.numaflow.accumulator; | ||
|
||
class Constants { | ||
public static final String SUCCESS = "SUCCESS"; | ||
|
||
public static final String DELIMITER = ":"; | ||
|
||
public static final int DEFAULT_MESSAGE_SIZE = 1024 * 1024 * 64; | ||
|
||
public static final String DEFAULT_SOCKET_PATH = "/var/run/numaflow/accumulator.sock"; | ||
|
||
public static final String DEFAULT_SERVER_INFO_FILE_PATH = "/var/run/numaflow/accumulator-server-info"; | ||
|
||
public static final int DEFAULT_PORT = 50051; | ||
|
||
public static final String DEFAULT_HOST = "localhost"; | ||
|
||
public static final String EOF = "EOF"; | ||
public static final String SUCCESS = "SUCCESS"; | ||
public static final String DELIMITER = ":"; | ||
public static final int DEFAULT_MESSAGE_SIZE = 1024 * 1024 * 64; | ||
public static final String DEFAULT_SOCKET_PATH = "/var/run/numaflow/accumulator.sock"; | ||
public static final String DEFAULT_SERVER_INFO_FILE_PATH = | ||
"/var/run/numaflow/accumulator-server-info"; | ||
public static final int DEFAULT_PORT = 50051; | ||
public static final String DEFAULT_HOST = "localhost"; | ||
public static final String EOF = "EOF"; | ||
|
||
// Private constructor to prevent instantiation | ||
private Constants() { | ||
throw new IllegalStateException("Utility class 'Constants' should not be instantiated"); | ||
} | ||
} |
104 changes: 50 additions & 54 deletions
104
src/main/java/io/numaproj/numaflow/accumulator/model/Message.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,61 @@ | ||
package io.numaproj.numaflow.accumulator.model; | ||
|
||
import lombok.Getter; | ||
|
||
import java.time.Instant; | ||
import java.util.Map; | ||
import lombok.Getter; | ||
|
||
/** | ||
* Message is used to wrap the data returned by Accumulator functions. | ||
*/ | ||
/** Message is used to wrap the data returned by Accumulator functions. */ | ||
@Getter | ||
public class Message { | ||
private final Instant eventTime; | ||
private final Instant watermark; | ||
private final Map<String, String> headers; | ||
private final String id; | ||
private String[] keys; | ||
private byte[] value; | ||
private String[] tags; | ||
public final class Message { | ||
private final Instant eventTime; | ||
private final Instant watermark; | ||
private final Map<String, String> headers; | ||
private final String id; | ||
private String[] keys; | ||
private byte[] value; | ||
private String[] tags; | ||
|
||
/** | ||
* Constructor for constructing message from Datum, it is advised to use the | ||
* incoming Datum to construct the message, because event time, watermark, id | ||
* and headers of the message are derived from the Datum. Only use custom | ||
* implementation of the Datum if you know what you are doing. | ||
* | ||
* @param datum {@link Datum} object | ||
*/ | ||
public Message(Datum datum) { | ||
this.keys = datum.getKeys(); | ||
this.value = datum.getValue(); | ||
this.headers = datum.getHeaders(); | ||
this.eventTime = datum.getEventTime(); | ||
this.watermark = datum.getWatermark(); | ||
this.id = datum.getID(); | ||
this.tags = null; | ||
} | ||
/** | ||
* Constructor for constructing message from Datum, it is advised to use the incoming Datum to | ||
* construct the message, because event time, watermark, id and headers of the message are derived | ||
* from the Datum. Only use custom implementation of the Datum if you know what you are doing. | ||
* | ||
* @param datum {@link Datum} object | ||
*/ | ||
public Message(Datum datum) { | ||
this.keys = datum.getKeys(); | ||
this.value = datum.getValue(); | ||
this.headers = datum.getHeaders(); | ||
this.eventTime = datum.getEventTime(); | ||
this.watermark = datum.getWatermark(); | ||
this.id = datum.getID(); | ||
this.tags = null; | ||
} | ||
|
||
/* | ||
* sets the value of the message | ||
* | ||
* @param value byte array of the value | ||
*/ | ||
public void setValue(byte[] value) { | ||
this.value = value; | ||
} | ||
/* | ||
* sets the value of the message | ||
* | ||
* @param value byte array of the value | ||
*/ | ||
public void setValue(byte[] value) { | ||
this.value = value; | ||
} | ||
|
||
/* | ||
* sets the keys of the message | ||
* | ||
* @param keys string array of the keys | ||
*/ | ||
public void setKeys(String[] keys) { | ||
this.keys = keys; | ||
} | ||
/* | ||
* sets the keys of the message | ||
* | ||
* @param keys string array of the keys | ||
*/ | ||
public void setKeys(String[] keys) { | ||
this.keys = keys; | ||
} | ||
|
||
/* | ||
* sets the tags of the message, tags are used for conditional forwarding | ||
* | ||
* @param tags string array of the tags | ||
*/ | ||
public void setTags(String[] tags) { | ||
this.tags = tags; | ||
} | ||
/* | ||
* sets the tags of the message, tags are used for conditional forwarding | ||
* | ||
* @param tags string array of the tags | ||
*/ | ||
public void setTags(String[] tags) { | ||
this.tags = tags; | ||
} | ||
} |
29 changes: 13 additions & 16 deletions
29
src/main/java/io/numaproj/numaflow/batchmapper/Constants.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
package io.numaproj.numaflow.batchmapper; | ||
|
||
class Constants { | ||
public static final int DEFAULT_MESSAGE_SIZE = 1024 * 1024 * 64; | ||
|
||
public static final String DEFAULT_SOCKET_PATH = "/var/run/numaflow/batchmap.sock"; | ||
|
||
public static final String DEFAULT_SERVER_INFO_FILE_PATH = "/var/run/numaflow/mapper-server-info"; | ||
|
||
public static final int DEFAULT_PORT = 50051; | ||
|
||
public static final String DEFAULT_HOST = "localhost"; | ||
|
||
public static final String SUCCESS = "SUCCESS"; | ||
|
||
public static final String MAP_MODE_KEY = "MAP_MODE"; | ||
|
||
public static final String MAP_MODE = "batch-map"; | ||
public static final int DEFAULT_MESSAGE_SIZE = 1024 * 1024 * 64; | ||
public static final String DEFAULT_SOCKET_PATH = "/var/run/numaflow/batchmap.sock"; | ||
public static final String DEFAULT_SERVER_INFO_FILE_PATH = "/var/run/numaflow/mapper-server-info"; | ||
public static final int DEFAULT_PORT = 50051; | ||
public static final String DEFAULT_HOST = "localhost"; | ||
public static final String SUCCESS = "SUCCESS"; | ||
public static final String MAP_MODE_KEY = "MAP_MODE"; | ||
public static final String MAP_MODE = "batch-map"; | ||
|
||
// Private constructor to prevent instantiation | ||
private Constants() { | ||
throw new IllegalStateException("Utility class 'Constants' should not be instantiated"); | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.