goiri commented on a change in pull request #2327:
URL: https://github.com/apache/hadoop/pull/2327#discussion_r496355570
##########
File path:
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/CallerContext.java
##########
@@ -113,8 +113,9 @@ public String toString() {
/** The caller context builder. */
public static final class Builder {
+ private static final String colon = ":";
Review comment:
The name should be capitalized.
I would also call it something like FIELD_SEPARATOR or
KEY_VALUE_SEPARATOR_CHAR.
##########
File path:
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/CallerContext.java
##########
@@ -140,6 +141,14 @@ public Builder setSignature(byte[] signature) {
return this;
}
+ public String getContext() {
+ return sb.length() > 0 ? sb.toString() : null;
+ }
+
+ public byte[] getSignature() {
Review comment:
Simple javadoc.
##########
File path:
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/CallerContext.java
##########
@@ -109,11 +113,25 @@ public String toString() {
/** The caller context builder. */
public static final class Builder {
- private final String context;
+ private static final String colon = ":";
+ private final String separator;
+ private final StringBuilder sb = new StringBuilder();
private byte[] signature;
public Builder(String context) {
- this.context = context;
+ separator = HADOOP_CALLER_CONTEXT_SEPARATOR_DEFAULT;
+ if (isValid(context)) {
+ sb.append(context);
+ }
+ }
+
+ public Builder(Configuration conf) {
+ separator = conf.get(HADOOP_CALLER_CONTEXT_SEPARATOR_KEY,
+ HADOOP_CALLER_CONTEXT_SEPARATOR_DEFAULT);
+ }
+
+ private boolean isValid(String context) {
+ return context != null && context.length() > 0;
Review comment:
This is technically not "context" but "item".
Good to have a javadoc explaining what we don't allow.
##########
File path:
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/CallerContext.java
##########
@@ -109,11 +113,25 @@ public String toString() {
/** The caller context builder. */
public static final class Builder {
- private final String context;
+ private static final String colon = ":";
+ private final String separator;
Review comment:
something a little more descriptive like: fieldSeparator
##########
File path:
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/CallerContext.java
##########
@@ -123,6 +141,45 @@ public Builder setSignature(byte[] signature) {
return this;
}
+ public String getContext() {
+ return sb.length() > 0 ? sb.toString() : null;
+ }
+
+ public byte[] getSignature() {
+ return signature;
+ }
+
+ /**
+ * Append new item to the context.
+ * @param item
+ * @return builder
+ */
+ public Builder append(String item) {
+ if (isValid(item)) {
+ if (sb.length() > 0) {
+ sb.append(separator);
+ }
+ sb.append(item);
+ }
+ return this;
+ }
+
+ /**
+ * Append new item which contains key and value to the context.
+ * @param key
Review comment:
Expand a little. Same for the item one.
##########
File path:
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/CallerContext.java
##########
@@ -140,6 +141,14 @@ public Builder setSignature(byte[] signature) {
return this;
}
+ public String getContext() {
Review comment:
I think it would be a good place to have a javadoc describing what the
context would look like and give examples.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]