]> git.basschouten.com Git - openhab-addons.git/blob
9be448f51657596accbfe624468947b92f18b3dc
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.mqtt.discovery;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16
17 /**
18  *
19  * The {@link MQTTTopicDiscoveryService} service is responsible for subscribing to a topic on
20  * all currently available broker connections as well as later on appearing broker connections.
21  *
22  * @author David Graeff - Initial contribution
23  */
24 @NonNullByDefault
25 public interface MQTTTopicDiscoveryService {
26     /**
27      * Subscribe to the given topic and get notified of messages on that topic via the listener.
28      * Subscribing happens on a best-effort strategy. Any errors on any connections are suppressed.
29      *
30      * @param listener A listener. Need to be a strong reference.
31      * @param topic The topic. Can contain wildcards.
32      */
33     void subscribe(MQTTTopicDiscoveryParticipant listener, String topic);
34
35     /**
36      * Unsubscribe the given listener.
37      *
38      * @param listener A listener that has subscribed before.
39      */
40     void unsubscribe(MQTTTopicDiscoveryParticipant listener);
41
42     /**
43      * Publish a message to all connected brokers
44      *
45      * @param topic The topic
46      * @param payload The message payload
47      * @param qos The quality of service for this message
48      * @param retain Set to true to retain the message on the broker
49      */
50     void publish(String topic, byte[] payload, int qos, boolean retain);
51 }