Package jmri.jmrix.mqtt
Class MqttAdapter
java.lang.Object
jmri.jmrix.AbstractPortController
jmri.jmrix.AbstractNetworkPortController
jmri.jmrix.mqtt.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.
-
Nested Class Summary
Nested classes/interfaces inherited from class jmri.jmrix.AbstractPortController
AbstractPortController.Option -
Field Summary
FieldsModifier and TypeFieldDescriptionOtherwise known as "Channel", this is prepended to the topic for all JMRI inward and outward communications.(package private) org.eclipse.paho.client.mqttv3.MqttClient(package private) HashMap<String,ArrayList<MqttEventListener>> intbooleanFields inherited from class jmri.jmrix.AbstractNetworkPortController
connTimeout, m_HostName, m_port, socketConnFields inherited from class jmri.jmrix.AbstractPortController
allowConnectionRecovery, manufacturerName, opened, option1Name, option2Name, option3Name, option4Name, options, reconnectinterval, reconnectMaxAttempts, reconnectMaxInterval -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAbstract class for controllers to close the connection.voidConfigure all of the other jmrix widgets needed to work with this adaptervoidconnect()Open the connection.voidconnectionLost(Throwable thrwbl) voiddeliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken imdt) voiddispose()Clean up before removal.org.eclipse.paho.client.mqttv3.MqttClientorg.eclipse.paho.client.mqttv3.MqttConnectOptions(package private) org.eclipse.paho.client.mqttv3.MqttClientgetNewMqttClient(String clientID, String tempdirName) Get theSystemConnectionMemoassociated with this object.voidmessageArrived(String topic, org.eclipse.paho.client.mqttv3.MqttMessage mm) voidSend a message over the existing link to a broker.voidSend a message over the existing link to a broker.voidSend a message over the existing link to a broker.voidSend a message over the existing link to a broker.voidsubscribe(String topic, MqttEventListener mel) voidunsubscribe(String topic, MqttEventListener mel) voidMethods inherited from class jmri.jmrix.AbstractNetworkPortController
autoConfigure, connect, getAdvertisementName, getConnectionTimeout, getCurrentPortName, getHostAddress, getHostName, getInputStream, getMdnsConfigure, getOutputStream, getPort, getServiceType, reconnectFromLoop, resetupConnection, setAdvertisementName, setConnectionTimeout, setHostAddress, setHostName, setMdnsConfigure, setPort, setPort, setServiceTypeMethods inherited from class jmri.jmrix.AbstractPortController
configureOption1, configureOption2, configureOption3, configureOption4, getDisabled, getManufacturer, getOption1Name, getOption2Name, getOption3Name, getOption4Name, getOptionChoices, getOptionDisplayName, getOptions, getOptionState, getReconnectMaxAttempts, getReconnectMaxInterval, getSystemPrefix, getUserName, isDirty, isOptionAdvanced, isOptionTypePassword, isOptionTypeText, isRestartRequired, purgeStream, reconnect, recover, safeSleep, setClosed, setDisabled, setManufacturer, setOpened, setOptionState, setReconnectMaxAttempts, setReconnectMaxInterval, setSystemConnectionMemo, setSystemPrefix, setUserName, statusMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jmri.jmrix.NetworkPortAdapter
statusMethods inherited from interface jmri.jmrix.PortAdapter
configureOption1, configureOption2, configureOption3, configureOption4, getDisabled, getManufacturer, getOption1Name, getOption2Name, getOption3Name, getOption4Name, getOptionChoices, getOptionDisplayName, getOptions, getOptionState, getReconnectMaxAttempts, getReconnectMaxInterval, getSystemPrefix, getUserName, isDirty, isOptionAdvanced, isOptionTypePassword, isOptionTypeText, isRestartRequired, recover, setDisabled, setManufacturer, setOptionState, setReconnectMaxAttempts, setReconnectMaxInterval, setSystemConnectionMemo, setSystemPrefix, setUserName
-
Field Details
-
retained
-
qosflag
-
baseTopic
Otherwise known as "Channel", this is prepended to the topic for all JMRI inward and outward communications. Typically set by preferences at startup. Changing it after startup might have no or bad effect. -
mqttEventListeners
-
mqttClient
org.eclipse.paho.client.mqttv3.MqttClient mqttClient
-
-
Constructor Details
-
MqttAdapter
-
-
Method Details
-
getMqttConnectionOptions
-
configure
Description copied from interface:NetworkPortAdapterConfigure all of the other jmrix widgets needed to work with this adapter- Specified by:
configurein interfaceNetworkPortAdapter- Specified by:
configurein interfacePortAdapter
-
connect
Description copied from interface:PortAdapterOpen the connection.- Specified by:
connectin interfacePortAdapter- Overrides:
connectin classAbstractNetworkPortController- 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
Description copied from class:AbstractPortControllerGet theSystemConnectionMemoassociated 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:
getSystemConnectionMemoin interfacePortAdapter- Overrides:
getSystemConnectionMemoin classAbstractPortController- Returns:
- the currently associated SystemConnectionMemo
-
subscribe
-
unsubscribe
-
unsubscribeall
-
publish
Send a message over the existing link to a broker.- Parameters:
topic- The topic, which follows the channel and precedes the payload in the messagepayload- 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 messagepayload- The payload makes up the final part of the messageretain- Should the message be retained?
-
publish
Send a message over the existing link to a broker.- Parameters:
topic- The topic, which follows the channel and precedes the payload in the messagepayload- 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 messageretain- Should the message be retained?payload- The payload makes up the final part of the message
-
getMQttClient
-
connectionLost
- Specified by:
connectionLostin interfaceorg.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:
messageArrivedin interfaceorg.eclipse.paho.client.mqttv3.MqttCallback- Throws:
Exception
-
deliveryComplete
@API(status=INTERNAL) public void deliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken imdt) - Specified by:
deliveryCompletein interfaceorg.eclipse.paho.client.mqttv3.MqttCallback
-
closeConnection
Description copied from class:AbstractNetworkPortControllerAbstract class for controllers to close the connection. Called prior to any re-connection attempts.- Overrides:
closeConnectionin classAbstractNetworkPortController
-
dispose
Description copied from class:AbstractPortControllerClean up before removal. Overriding methods must callsuper.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:
disposein interfacePortAdapter- Overrides:
disposein classAbstractPortController
-