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.String
baseTopic
Otherwise known as "Channel", this is prepended to the topic for all JMRI inward and outward communications.(package private) org.eclipse.paho.client.mqttv3.MqttClient
mqttClient
(package private) java.util.HashMap<java.lang.String,java.util.ArrayList<MqttEventListener>>
mqttEventListeners
int
qosflag
boolean
retained
-
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 void
closeConnection()
Abstract class for controllers to close the connection.void
configure()
Configure all of the other jmrix widgets needed to work with this adaptervoid
connect()
Open the connection.void
connectionLost(java.lang.Throwable thrwbl)
void
deliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken imdt)
void
dispose()
Clean up before removal.org.eclipse.paho.client.mqttv3.MqttClient
getMQttClient()
org.eclipse.paho.client.mqttv3.MqttConnectOptions
getMqttConnectionOptions()
(package private) org.eclipse.paho.client.mqttv3.MqttClient
getNewMqttClient(java.lang.String clientID, java.lang.String tempdirName)
MqttSystemConnectionMemo
getSystemConnectionMemo()
Get theSystemConnectionMemo
associated with this object.void
messageArrived(java.lang.String topic, org.eclipse.paho.client.mqttv3.MqttMessage mm)
void
publish(java.lang.String topic, byte[] payload)
Send a message over the existing link to a broker.void
publish(java.lang.String topic, byte[] payload, boolean retain)
Send a message over the existing link to a broker.void
publish(java.lang.String topic, java.lang.String payload)
Send a message over the existing link to a broker.void
publish(java.lang.String topic, java.lang.String payload, boolean retain)
Send a message over the existing link to a broker.void
subscribe(java.lang.String topic, MqttEventListener mel)
void
unsubscribe(java.lang.String topic, MqttEventListener mel)
void
unsubscribeall(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:NetworkPortAdapter
Configure all of the other jmrix widgets needed to work with this adapter- Specified by:
configure
in interfaceNetworkPortAdapter
- Specified by:
configure
in interfacePortAdapter
-
connect
@API(status=INTERNAL) public void connect() throws java.io.IOException
Description copied from interface:PortAdapter
Open the connection.- Specified by:
connect
in interfacePortAdapter
- Overrides:
connect
in 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:AbstractPortController
Get theSystemConnectionMemo
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 interfacePortAdapter
- Overrides:
getSystemConnectionMemo
in 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:
connectionLost
in 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:
messageArrived
in 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:
deliveryComplete
in interfaceorg.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 classAbstractNetworkPortController
-
dispose
public void dispose()
Description copied from class:AbstractPortController
Clean 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:
dispose
in interfacePortAdapter
- Overrides:
dispose
in classAbstractPortController
-
-