Interface MqttService


  • @NonNullByDefault
    public interface MqttService
    This service allows you to enumerate system-wide configured Mqtt broker connections. You do not need this service if you want to manage own/local Mqtt broker connections. If you add a broker connection, it will be available immediately for all MqttService users. A removed broker connection may still be in use by consuming services. Added/removed connections are not permanent. Use MqttBrokerConnectionServiceInstance to configure permanent connections.
    Author:
    David Graeff - Initial contribution
    • Method Detail

      • addBrokersListener

        void addBrokersListener​(MqttServiceObserver observer)
        Add a listener to get notified of new/removed brokers.
        Parameters:
        observer - The observer
      • removeBrokersListener

        void removeBrokersListener​(MqttServiceObserver observer)
        Remove a listener and don't get notified of new/removed brokers anymore.
        Parameters:
        observer - The observer
      • hasBrokerObservers

        boolean hasBrokerObservers()
        Return true if a broker listener has been added via addBrokersListener().
      • getBrokerConnection

        @Nullable MqttBrokerConnection getBrokerConnection​(String brokerName)
        Lookup an broker connection by name.
        Parameters:
        brokerName - to look for.
        Returns:
        existing connection or null
      • addBrokerConnection

        boolean addBrokerConnection​(String brokerID,
                                    MqttBrokerConnection connection)
        Adds a broker connection to the service. The broker connection state will not be altered (started/stopped). It is your responsibility to remove the broker connection again by calling removeBrokerConnection(brokerID).
        Parameters:
        brokerID - The broker connection will be identified by this ID. The ID must be unique within the service.
        connection - The broker connection object
        Returns:
        Return true if the connection could be added successfully, return false if there is already an existing connection with the same name.
      • removeBrokerConnection

        @Nullable MqttBrokerConnection removeBrokerConnection​(String brokerID)
        Remove a broker connection by name
        Parameters:
        brokerName - The broker ID
        Returns:
        Returns the removed broker connection, or null if there was none with the given name.
      • getAllBrokerConnections

        Map<String,​MqttBrokerConnection> getAllBrokerConnections()
        Returns an unmodifiable map with all configured brokers of this service and the broker ID as keys.