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
Fields Modifier and Type Field Description java.lang.StringbaseTopicOtherwise known as "Channel", this is prepended to the topic for all JMRI inward and outward communications.(package private) org.eclipse.paho.client.mqttv3.MqttClientmqttClient(package private) java.util.HashMap<java.lang.String,java.util.ArrayList<MqttEventListener>>mqttEventListenersintqosflagbooleanretained-
Fields inherited from class jmri.jmrix.AbstractNetworkPortController
connTimeout, m_HostName, m_port, socketConn
-
Fields inherited from class jmri.jmrix.AbstractPortController
allowConnectionRecovery, manufacturerName, opened, option1Name, option2Name, option3Name, option4Name, options, reconnectinterval, reconnectMaxAttempts, reconnectMaxInterval
-
-
Constructor Summary
Constructors Constructor Description MqttAdapter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcloseConnection()Abstract class for controllers to close the connection.voidconfigure()Configure all of the other jmrix widgets needed to work with this adaptervoidconnect()Open the connection.voidconnectionLost(java.lang.Throwable thrwbl)voiddeliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken imdt)voiddispose()Clean up before removal.org.eclipse.paho.client.mqttv3.MqttClientgetMQttClient()org.eclipse.paho.client.mqttv3.MqttConnectOptionsgetMqttConnectionOptions()(package private) org.eclipse.paho.client.mqttv3.MqttClientgetNewMqttClient(java.lang.String clientID, java.lang.String tempdirName)MqttSystemConnectionMemogetSystemConnectionMemo()Get theSystemConnectionMemoassociated with this object.voidmessageArrived(java.lang.String topic, org.eclipse.paho.client.mqttv3.MqttMessage mm)voidpublish(java.lang.String topic, byte[] payload)Send a message over the existing link to a broker.voidpublish(java.lang.String topic, byte[] payload, boolean retain)Send a message over the existing link to a broker.voidpublish(java.lang.String topic, java.lang.String payload)Send a message over the existing link to a broker.voidpublish(java.lang.String topic, java.lang.String payload, boolean retain)Send a message over the existing link to a broker.voidsubscribe(java.lang.String topic, MqttEventListener mel)voidunsubscribe(java.lang.String topic, MqttEventListener mel)voidunsubscribeall(MqttEventListener mel)-
Methods 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, setServiceType
-
Methods 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, status
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jmri.jmrix.NetworkPortAdapter
status
-
Methods 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 Detail
-
retained
public boolean retained
-
qosflag
public int qosflag
-
baseTopic
@API(status=MAINTAINED) public java.lang.String 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
java.util.HashMap<java.lang.String,java.util.ArrayList<MqttEventListener>> mqttEventListeners
-
mqttClient
org.eclipse.paho.client.mqttv3.MqttClient mqttClient
-
-
Constructor Detail
-
MqttAdapter
@API(status=INTERNAL) public MqttAdapter()
-
-
Method Detail
-
getMqttConnectionOptions
public org.eclipse.paho.client.mqttv3.MqttConnectOptions getMqttConnectionOptions()
-
configure
@API(status=INTERNAL) public void 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
@API(status=INTERNAL) public void connect() throws java.io.IOException
Description copied from interface:PortAdapterOpen the connection.- Specified by:
connectin interfacePortAdapter- Overrides:
connectin classAbstractNetworkPortController- Throws:
java.io.IOException- if unable to connect
-
getNewMqttClient
org.eclipse.paho.client.mqttv3.MqttClient getNewMqttClient(java.lang.String clientID, java.lang.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: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
@API(status=MAINTAINED) public void subscribe(java.lang.String topic, MqttEventListener mel)
-
unsubscribe
@API(status=MAINTAINED) public void unsubscribe(java.lang.String topic, MqttEventListener mel)
-
unsubscribeall
@API(status=MAINTAINED) public void unsubscribeall(MqttEventListener mel)
-
publish
@API(status=MAINTAINED) public void publish(@Nonnull java.lang.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 messagepayload- The payload makes up the final part of the message
-
publish
@API(status=MAINTAINED) public void publish(@Nonnull java.lang.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
@API(status=MAINTAINED) public void publish(@Nonnull java.lang.String topic, @Nonnull java.lang.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 messagepayload- The payload makes up the final part of the message
-
publish
@API(status=MAINTAINED) public void publish(@Nonnull java.lang.String topic, @Nonnull java.lang.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
public org.eclipse.paho.client.mqttv3.MqttClient getMQttClient()
-
connectionLost
@API(status=INTERNAL) public void connectionLost(java.lang.Throwable thrwbl)
- Specified by:
connectionLostin interfaceorg.eclipse.paho.client.mqttv3.MqttCallback
-
messageArrived
@API(status=INTERNAL) public void messageArrived(java.lang.String topic, org.eclipse.paho.client.mqttv3.MqttMessage mm) throws java.lang.Exception
- Specified by:
messageArrivedin interfaceorg.eclipse.paho.client.mqttv3.MqttCallback- Throws:
java.lang.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
protected void closeConnection()
Description copied from class:AbstractNetworkPortControllerAbstract class for controllers to close the connection. Called prior to any re-connection attempts.- Overrides:
closeConnectionin classAbstractNetworkPortController
-
dispose
public void 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
-
-