public abstract class MQTTTransportHandler extends Object implements org.eclipse.paho.client.mqttv3.MqttCallback, TransportHandler<org.eclipse.paho.client.mqttv3.MqttMessage>
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MQTT_QUALITY_OF_SERVICE |
protected String |
mqttBrokerEndPoint |
protected String |
subscribeTopic |
protected int |
timeoutInterval |
DEFAULT_TIMEOUT_INTERVAL
Modifier | Constructor and Description |
---|---|
protected |
MQTTTransportHandler(String deviceOwner,
String deviceType,
String mqttBrokerEndPoint,
String subscribeTopic)
Constructor for the MQTTTransportHandler which takes in the owner, type of the device
and the MQTT Broker URL and the topic to subscribe.
|
protected |
MQTTTransportHandler(String deviceOwner,
String deviceType,
String mqttBrokerEndPoint,
String subscribeTopic,
int intervalInMillis)
Constructor for the MQTTTransportHandler which takes in the owner, type of the device
and the MQTT Broker URL and the topic to subscribe.
|
Modifier and Type | Method and Description |
---|---|
void |
closeConnection()
Closes the connection to the MQTT Broker.
|
void |
connectionLost(Throwable throwable)
Callback method which is triggered once the MQTT client losers its connection to the broker.
|
protected void |
connectToQueue()
Connects to the MQTT-Broker and if successfully established connection.
|
protected void |
connectToQueue(String username,
String password) |
void |
deliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken iMqttDeliveryToken)
Callback method which gets triggered upon successful completion of a message delivery to
the broker.
|
boolean |
isConnected()
Checks whether the connection to the MQTT-Broker persists.
|
void |
messageArrived(String topic,
org.eclipse.paho.client.mqttv3.MqttMessage mqttMessage)
Callback method which is triggered upon receiving a MQTT Message from the broker.
|
protected void |
publishToQueue(String topic,
org.eclipse.paho.client.mqttv3.MqttMessage message) |
protected void |
publishToQueue(String topic,
String payLoad)
This method is used to publish reply-messages for the control signals received.
|
protected void |
publishToQueue(String topic,
String payLoad,
int qos,
boolean retained)
This is an overloaded method that publishes MQTT reply-messages for control signals
received form the IoT-Server.
|
void |
setTimeoutInterval(int timeoutInterval) |
protected void |
subscribeToQueue()
Subscribes to the MQTT-Topic specific to this MQTT Client.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
connect, disconnect, processIncomingMessage, processIncomingMessage, publishDeviceData, publishDeviceData
public static final int DEFAULT_MQTT_QUALITY_OF_SERVICE
protected String mqttBrokerEndPoint
protected int timeoutInterval
protected String subscribeTopic
protected MQTTTransportHandler(String deviceOwner, String deviceType, String mqttBrokerEndPoint, String subscribeTopic)
deviceOwner
- the owner of the device.deviceType
- the CDMF Device-Type of the device.mqttBrokerEndPoint
- the IP/URL of the MQTT broker endpoint.subscribeTopic
- the MQTT topic to which the client is to be subscribedprotected MQTTTransportHandler(String deviceOwner, String deviceType, String mqttBrokerEndPoint, String subscribeTopic, int intervalInMillis)
deviceOwner
- the owner of the device.deviceType
- the CDMF Device-Type of the device.mqttBrokerEndPoint
- the IP/URL of the MQTT broker endpoint.subscribeTopic
- the MQTT topic to which the client is to be subscribedintervalInMillis
- the time interval in MILLI-SECONDS between successive
attempts to connect to the broker.public void setTimeoutInterval(int timeoutInterval)
public boolean isConnected()
isConnected
in interface TransportHandler<org.eclipse.paho.client.mqttv3.MqttMessage>
protected void connectToQueue(String username, String password) throws TransportHandlerException
TransportHandlerException
protected void connectToQueue() throws TransportHandlerException
TransportHandlerException
- in the event of 'Connecting to' the MQTT broker fails.protected void subscribeToQueue() throws TransportHandlerException
TransportHandlerException
- in the event of 'Subscribing to' the MQTT broker
fails.protected void publishToQueue(String topic, String payLoad) throws TransportHandlerException
topic
- the topic to which the reply message is to be published.payLoad
- the reply-message (payload) of the MQTT publish action.TransportHandlerException
protected void publishToQueue(String topic, String payLoad, int qos, boolean retained) throws TransportHandlerException
topic
- the topic to which the reply message is to be publishedpayLoad
- the reply-message (payload) of the MQTT publish action.qos
- the Quality-of-Service of the current publish action.
Could be 0(At-most once), 1(At-least once) or 2(Exactly once)TransportHandlerException
protected void publishToQueue(String topic, org.eclipse.paho.client.mqttv3.MqttMessage message) throws TransportHandlerException
TransportHandlerException
public void connectionLost(Throwable throwable)
connectionLost
in interface org.eclipse.paho.client.mqttv3.MqttCallback
throwable
- a Throwable Object containing the details as to why the failure occurred.public void messageArrived(String topic, org.eclipse.paho.client.mqttv3.MqttMessage mqttMessage)
messageArrived
in interface org.eclipse.paho.client.mqttv3.MqttCallback
topic
- the MQTT-Topic to which the received message was published to and the
client was subscribed to.mqttMessage
- the actual MQTT-Message that was received from the broker.public void deliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken iMqttDeliveryToken)
deliveryComplete
in interface org.eclipse.paho.client.mqttv3.MqttCallback
iMqttDeliveryToken
- the MQTT-DeliveryToken which includes the details about the
specific message delivery.public void closeConnection() throws org.eclipse.paho.client.mqttv3.MqttException
org.eclipse.paho.client.mqttv3.MqttException
Copyright © 2017 WSO2. All rights reserved.