Class MqttAdapter

All Implemented Interfaces:
NetworkPortAdapter, PortAdapter, org.eclipse.paho.client.mqttv3.MqttCallback

@API(status=MAINTAINED) public class MqttAdapter extends AbstractNetworkPortController implements org.eclipse.paho.client.mqttv3.MqttCallback
Communications adapter for Mqtt communications links.
  • Field Details

  • Constructor Details

    • MqttAdapter

      @API(status=INTERNAL) public MqttAdapter()
  • Method Details

    • getMqttConnectionOptions

      public org.eclipse.paho.client.mqttv3.MqttConnectOptions getMqttConnectionOptions()
    • configure

      @API(status=INTERNAL) public void configure()
      Description copied from interface: NetworkPortAdapter
      Configure all of the other jmrix widgets needed to work with this adapter
      Specified by:
      configure in interface NetworkPortAdapter
      Specified by:
      configure in interface PortAdapter
    • connect

      @API(status=INTERNAL) public void connect() throws IOException
      Description copied from interface: PortAdapter
      Open the connection.
      Specified by:
      connect in interface PortAdapter
      Overrides:
      connect in class AbstractNetworkPortController
      Throws:
      IOException - if unable to connect
    • getNewMqttClient

      org.eclipse.paho.client.mqttv3.MqttClient getNewMqttClient(String clientID, String tempdirName) throws org.eclipse.paho.client.mqttv3.MqttException
      Throws:
      org.eclipse.paho.client.mqttv3.MqttException
    • getSystemConnectionMemo

      @API(status=MAINTAINED) public MqttSystemConnectionMemo getSystemConnectionMemo()
      Description copied from class: AbstractPortController
      Get the SystemConnectionMemo associated with this object.

      This method should only be overridden to ensure that a specific subclass of SystemConnectionMemo is returned. The recommended pattern is: public MySystemConnectionMemo getSystemConnectionMemo() { return (MySystemConnectionMemo) super.getSystemConnectionMemo(); }

      Specified by:
      getSystemConnectionMemo in interface PortAdapter
      Overrides:
      getSystemConnectionMemo in class AbstractPortController
      Returns:
      the currently associated SystemConnectionMemo
    • subscribe

      @API(status=MAINTAINED) public void subscribe(String topic, MqttEventListener mel)
    • unsubscribe

      @API(status=MAINTAINED) public void unsubscribe(String topic, MqttEventListener mel)
    • unsubscribeall

      @API(status=MAINTAINED) public void unsubscribeall(MqttEventListener mel)
    • publish

      @API(status=MAINTAINED) public void publish(@Nonnull String topic, @Nonnull byte[] payload)
      Send a message over the existing link to a broker.
      Parameters:
      topic - The topic, which follows the channel and precedes the payload in the message
      payload - The payload makes up the final part of the message
    • publish

      @API(status=MAINTAINED) public void publish(@Nonnull String topic, @Nonnull byte[] payload, boolean retain)
      Send a message over the existing link to a broker.
      Parameters:
      topic - The topic, which follows the channel and precedes the payload in the message
      payload - The payload makes up the final part of the message
      retain - Should the message be retained?
    • publish

      @API(status=MAINTAINED) public void publish(@Nonnull String topic, @Nonnull String payload)
      Send a message over the existing link to a broker.
      Parameters:
      topic - The topic, which follows the channel and precedes the payload in the message
      payload - The payload makes up the final part of the message
    • publish

      @API(status=MAINTAINED) public void publish(@Nonnull String topic, @Nonnull String payload, boolean retain)
      Send a message over the existing link to a broker.
      Parameters:
      topic - The topic, which follows the channel and precedes the payload in the message
      retain - Should the message be retained?
      payload - The payload makes up the final part of the message
    • getMQttClient

      public org.eclipse.paho.client.mqttv3.MqttClient getMQttClient()
    • connectionLost

      @API(status=INTERNAL) public void connectionLost(Throwable thrwbl)
      Specified by:
      connectionLost in interface org.eclipse.paho.client.mqttv3.MqttCallback
    • messageArrived

      @API(status=INTERNAL) public void messageArrived(String topic, org.eclipse.paho.client.mqttv3.MqttMessage mm) throws Exception
      Specified by:
      messageArrived in interface org.eclipse.paho.client.mqttv3.MqttCallback
      Throws:
      Exception
    • deliveryComplete

      @API(status=INTERNAL) public void deliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken imdt)
      Specified by:
      deliveryComplete in interface org.eclipse.paho.client.mqttv3.MqttCallback
    • closeConnection

      protected void closeConnection()
      Description copied from class: AbstractNetworkPortController
      Abstract class for controllers to close the connection. Called prior to any re-connection attempts.
      Overrides:
      closeConnection in class AbstractNetworkPortController
    • dispose

      public void dispose()
      Description copied from class: AbstractPortController
      Clean up before removal. Overriding methods must call super.dispose() or document why they are not calling the overridden implementation. In most cases, failure to call the overridden implementation will cause user-visible error.
      Specified by:
      dispose in interface PortAdapter
      Overrides:
      dispose in class AbstractPortController