Skip to content

Package: Sender

Sender

nameinstructionbranchcomplexitylinemethod
send()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
send(Map)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
send(Map, byte[])
M: 18 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
send(String)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
send(String, Charset)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
send(byte[])
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
transportSender(Topic, Transport)
M: 6 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) 2017, 2020 Red Hat Inc and others
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License v1.0
6: * which accompanies this distribution, and is available at
7: * http://www.eclipse.org/legal/epl-v10.html
8: *
9: * Contributors:
10: * Red Hat Inc - initial API and implementation
11: *******************************************************************************/
12: package org.eclipse.kapua.kura.simulator.app;
13:
14: import java.nio.charset.Charset;
15: import java.nio.charset.StandardCharsets;
16: import java.util.Collections;
17: import java.util.Map;
18:
19: import org.eclipse.kapua.kura.simulator.Transport;
20: import org.eclipse.kapua.kura.simulator.payload.Metrics;
21: import org.eclipse.kapua.kura.simulator.topic.Topic;
22: import org.eclipse.kura.core.message.protobuf.KuraPayloadProto.KuraPayload;
23: import org.eclipse.kura.core.message.protobuf.KuraPayloadProto.KuraPayload.Builder;
24:
25: import com.google.protobuf.ByteString;
26:
27: public interface Sender {
28:
29: public void send(KuraPayload.Builder payload);
30:
31: public default void send(final byte[] body) {
32: send(Collections.emptyMap(), body);
33: }
34:
35: public default void send(final String body) {
36: send(Collections.emptyMap(), body.getBytes(StandardCharsets.UTF_8));
37: }
38:
39: public default void send(final String body, final Charset charset) {
40: send(Collections.emptyMap(), body.getBytes(charset));
41: }
42:
43: public default void send(final Map<String, Object> metrics) {
44: send(metrics, null);
45: }
46:
47: public default void send() {
48: send(null, (byte[]) null);
49: }
50:
51: public default void send(final Map<String, Object> metrics, final byte[] body) {
52: final Builder payload = KuraPayload.newBuilder();
53:
54:• if (metrics != null) {
55: Metrics.buildMetrics(payload, metrics);
56: }
57:
58:• if (body != null) {
59: payload.setBody(ByteString.copyFrom(body));
60: }
61:
62: send(payload);
63: }
64:
65: public static Sender transportSender(final Topic topic, final Transport transport) {
66: return new Sender() {
67:
68: @Override
69: public void send(final Builder payload) {
70: transport.sendMessage(topic, payload.build().toByteArray());
71: }
72: };
73: }
74: }