Skip to content

Commit d086d6c

Browse files
authored
Merge pull request #759 from scalecube/rename-headers
Rename headers
2 parents 6a4d593 + c1635ee commit d086d6c

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

services-api/src/main/java/io/scalecube/services/api/ServiceMessage.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,24 @@ public final class ServiceMessage {
2020
* It is not supposed to be used by application directly and it is subject to changes in future
2121
* releases.
2222
*/
23-
public static final String HEADER_DATA_TYPE = "_type";
23+
public static final String HEADER_DATA_TYPE = "type";
2424

2525
/** Data format header. */
26-
public static final String HEADER_DATA_FORMAT = "_data_format";
26+
public static final String HEADER_DATA_FORMAT = "dataFormat";
2727

2828
/** Error type header. */
29-
public static final String ERROR_TYPE = "_error_type";
29+
public static final String HEADER_ERROR_TYPE = "errorType";
3030

31-
private Map<String, String> headers = new HashMap<>(1);
31+
/** Null value for error type. */
32+
public static final int NULL_ERROR_TYPE = -1;
33+
34+
private final Map<String, String> headers;
3235
private Object data;
3336

3437
/** Instantiates empty message for deserialization purpose. */
35-
ServiceMessage() {}
38+
ServiceMessage() {
39+
headers = new HashMap<>(2);
40+
}
3641

3742
private ServiceMessage(Builder builder) {
3843
this.data = builder.data;
@@ -63,7 +68,7 @@ public static ServiceMessage error(
6368
String qualifier, int errorType, int errorCode, String errorMessage) {
6469
return ServiceMessage.builder()
6570
.qualifier(qualifier)
66-
.header(ERROR_TYPE, String.valueOf(errorType))
71+
.header(HEADER_ERROR_TYPE, String.valueOf(errorType))
6772
.data(new ErrorData(errorCode, errorMessage))
6873
.build();
6974
}
@@ -162,18 +167,18 @@ public boolean hasData(Class<?> dataClass) {
162167
* @return <code>true</code> if error, otherwise <code>false</code>.
163168
*/
164169
public boolean isError() {
165-
return headers.containsKey(ERROR_TYPE);
170+
return headers.containsKey(HEADER_ERROR_TYPE);
166171
}
167172

168173
/**
169174
* Returns error type. Error type is an identifier of a group of errors.
170175
*
171-
* @return error type.
176+
* @return error type if set otherwise {@value NULL_ERROR_TYPE}.
172177
*/
173178
public int errorType() {
174-
String errorType = headers.get(ERROR_TYPE);
179+
String errorType = headers.get(HEADER_ERROR_TYPE);
175180
if (errorType == null) {
176-
return -1;
181+
return NULL_ERROR_TYPE;
177182
}
178183
try {
179184
return Integer.parseInt(errorType);
@@ -192,7 +197,7 @@ public String toString() {
192197

193198
public static class Builder {
194199

195-
private Map<String, String> headers = new HashMap<>();
200+
private final Map<String, String> headers = new HashMap<>(2);
196201
private Object data;
197202

198203
private Builder() {}

0 commit comments

Comments
 (0)