|
2 | 2 |
|
3 | 3 | import lombok.Getter;
|
4 | 4 |
|
5 |
| -/** |
6 |
| - * Message is used to wrap the data returned by Mapper. |
7 |
| - */ |
8 |
| - |
| 5 | +/** Message is used to wrap the data returned by Mapper. */ |
9 | 6 | @Getter
|
10 | 7 | public class Message {
|
11 |
| - public static final String DROP = "U+005C__DROP__"; |
12 |
| - |
13 |
| - private final String[] keys; |
14 |
| - private final byte[] value; |
15 |
| - private final String[] tags; |
16 |
| - |
17 |
| - |
18 |
| - /** |
19 |
| - * used to create Message with value, keys and tags(used for conditional forwarding) |
20 |
| - * |
21 |
| - * @param value message value |
22 |
| - * @param keys message keys |
23 |
| - * @param tags message tags which will be used for conditional forwarding |
24 |
| - */ |
25 |
| - public Message(byte[] value, String[] keys, String[] tags) { |
26 |
| - this.keys = keys; |
27 |
| - this.value = value; |
28 |
| - this.tags = tags; |
29 |
| - } |
30 |
| - |
31 |
| - /** |
32 |
| - * used to create Message with value. |
33 |
| - * |
34 |
| - * @param value message value |
35 |
| - */ |
36 |
| - public Message(byte[] value) { |
37 |
| - this(value, null, null); |
38 |
| - } |
39 |
| - |
40 |
| - /** |
41 |
| - * used to create Message with value and keys. |
42 |
| - * |
43 |
| - * @param value message value |
44 |
| - * @param keys message keys |
45 |
| - */ |
46 |
| - public Message(byte[] value, String[] keys) { |
47 |
| - this(value, keys, null); |
48 |
| - } |
49 |
| - |
50 |
| - /** |
51 |
| - * creates a Message which will be dropped |
52 |
| - * |
53 |
| - * @return returns the Message which will be dropped |
54 |
| - */ |
55 |
| - public static Message toDrop() { |
56 |
| - return new Message(new byte[0], null, new String[]{DROP}); |
57 |
| - } |
| 8 | + private static final String[] DROP_TAGS = {"U+005C__DROP__"}; |
| 9 | + private final String[] keys; |
| 10 | + private final byte[] value; |
| 11 | + private final String[] tags; |
| 12 | + |
| 13 | + /** |
| 14 | + * used to create Message with value, keys and tags(used for conditional forwarding) |
| 15 | + * |
| 16 | + * @param value message value |
| 17 | + * @param keys message keys |
| 18 | + * @param tags message tags which will be used for conditional forwarding |
| 19 | + */ |
| 20 | + public Message(byte[] value, String[] keys, String[] tags) { |
| 21 | + // defensive copy - once the Message is created, the caller should not be able to modify it. |
| 22 | + this.keys = keys == null ? null : keys.clone(); |
| 23 | + this.value = value == null ? null : value.clone(); |
| 24 | + this.tags = tags == null ? null : tags.clone(); |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * used to create Message with value. |
| 29 | + * |
| 30 | + * @param value message value |
| 31 | + */ |
| 32 | + public Message(byte[] value) { |
| 33 | + this(value, null, null); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * used to create Message with value and keys. |
| 38 | + * |
| 39 | + * @param value message value |
| 40 | + * @param keys message keys |
| 41 | + */ |
| 42 | + public Message(byte[] value, String[] keys) { |
| 43 | + this(value, keys, null); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * creates a Message which will be dropped |
| 48 | + * |
| 49 | + * @return returns the Message which will be dropped |
| 50 | + */ |
| 51 | + public static Message toDrop() { |
| 52 | + return new Message(new byte[0], null, DROP_TAGS); |
| 53 | + } |
58 | 54 | }
|
0 commit comments