Skip to content

Package: KapuaPayload

KapuaPayload

nameinstructionbranchcomplexitylinemethod
hasBody()
M: 11 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
toDisplayString()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.message;
14:
15: import org.eclipse.kapua.commons.util.Payloads;
16: import org.eclipse.kapua.message.xml.MessageXmlRegistry;
17: import org.eclipse.kapua.message.xml.MetricsXmlAdapter;
18: import org.eclipse.kapua.model.xml.BinaryXmlAdapter;
19:
20: import javax.xml.bind.annotation.XmlAccessType;
21: import javax.xml.bind.annotation.XmlAccessorType;
22: import javax.xml.bind.annotation.XmlElement;
23: import javax.xml.bind.annotation.XmlRootElement;
24: import javax.xml.bind.annotation.XmlTransient;
25: import javax.xml.bind.annotation.XmlType;
26: import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
27: import java.util.Map;
28:
29: /**
30: * {@link KapuaPayload} definition.
31: *
32: * @since 1.0.0
33: */
34: @XmlRootElement(name = "payload")
35: @XmlAccessorType(XmlAccessType.PROPERTY)
36: @XmlType(propOrder = {"metrics", "body"}, factoryClass = MessageXmlRegistry.class, factoryMethod = "newPayload")
37: public interface KapuaPayload extends Payload {
38:
39: /**
40: * Get the metrics map
41: *
42: * @return
43: * @since 1.0.0
44: */
45: @XmlElement(name = "metrics")
46: @XmlJavaTypeAdapter(MetricsXmlAdapter.class)
47: Map<String, Object> getMetrics();
48:
49: /**
50: * Set the metrics map
51: *
52: * @param metrics
53: * @since 1.0.0
54: */
55: void setMetrics(Map<String, Object> metrics);
56:
57: /**
58: * Get the message body
59: *
60: * @return
61: * @since 1.0.0
62: */
63: @XmlElement(name = "body")
64: @XmlJavaTypeAdapter(BinaryXmlAdapter.class)
65: byte[] getBody();
66:
67: /**
68: * Set the message body
69: *
70: * @param body
71: * @since 1.0.0
72: */
73: void setBody(byte[] body);
74:
75: /**
76: * Says whether or not the {@link #getBody()} has value.
77: * <p>
78: * Checks for {@code null} and size equals to 0
79: *
80: * @return {@code true} if {@link #getBody()} is not {@code null} and {@link #getBody()}{@code length > 0}, {@code false} otherwise.
81: * @since 1.2.0
82: */
83: default boolean hasBody() {
84:• return getBody() != null && getBody().length > 0;
85: }
86:
87: /**
88: * Returns a string for displaying the {@link KapuaPayload} content.
89: *
90: * @return A {@link String} used for displaying the content of the {@link KapuaPayload}, never returns {@code null}
91: * @since 1.0.0
92: */
93: @XmlTransient
94: default String toDisplayString() {
95: return Payloads.toDisplayString(getMetrics());
96: }
97: }