Skip to content

Package: Transport

Transport

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017, 2022 Red Hat Inc 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: * Red Hat Inc - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.kura.simulator;
14:
15: import java.util.function.Consumer;
16:
17: import org.eclipse.kapua.kura.simulator.payload.Message;
18: import org.eclipse.kapua.kura.simulator.topic.Topic;
19:
20: public interface Transport {
21:
22: /**
23: * Connect
24: */
25: public void connect();
26:
27: /**
28: * Disconnect gracefully <br>
29: * A later call to {@link #connect()} must be possible.
30: */
31: public void disconnect();
32:
33: /**
34: * Set the runnable which will be called when a connection was established
35: * <p>
36: * <strong>Note:</strong> When the connection is already established then
37: * this method won't be called again.
38: * </p>
39: */
40: public void whenConnected(Runnable runnable);
41:
42: /**
43: * Set the runnable which will be called when a connection was lost
44: */
45: public void whenDisconnected(Runnable runnable);
46:
47: /**
48: * Subscribe to a topic or topic pattern
49: *
50: * @param topic
51: * the topic to subscribe to
52: * @param consumer
53: * the consumer to call when a message was received
54: */
55: public void subscribe(Topic topic, Consumer<Message> consumer);
56:
57: /**
58: * Unsubscribe from a topic or topic pattern
59: *
60: * @param topic
61: * to unsubscribe from
62: */
63: public void unsubscribe(Topic topic);
64:
65: /**
66: * Send a message to a topic
67: *
68: * @param topic
69: * the topic to send the message to
70: * @param payload
71: * the payload to send
72: */
73: public void sendMessage(Topic topic, byte[] payload);
74: }