org.eclipse.paho.client.mqttv3
Interface MqttCallback


public interface MqttCallback

Asynchronous message listener. Classes implementing this interface can be passed to MqttClient.setCallback(MqttCallback), which will create a call back on this interface.


Method Summary
 void connectionLost(java.lang.Throwable cause)
          This method is called when the connection to the server is lost.
 void deliveryComplete(MqttDeliveryToken token)
          Called when delivery for a message has been completed, and all acknowledgements have been received.
 void messageArrived(MqttTopic topic, MqttMessage message)
          This method is called when a message arrives from the server.
 

Method Detail

connectionLost

public void connectionLost(java.lang.Throwable cause)
This method is called when the connection to the server is lost.

Parameters:
cause - the reason behind the loss of connection.

messageArrived

public void messageArrived(MqttTopic topic,
                           MqttMessage message)
                    throws java.lang.Exception
This method is called when a message arrives from the server.

This method is invoked synchronously by the MQTT client. An acknowledgment on the network is not sent back to the server until this method returns cleanly.

If an implementation of this method throws an Exception, then the client will be shut down. When the client is next re-connected, any QoS 1 or 2 messages will be redelivered.

Any additional messages which arrive while an implementation of this method is running, will build up in memory, and will then back up on the network.

If an application needs to persist data, then it should ensure the data is persisted prior to returning from this method, as after returning from this method, the message is considered to have been delivered, and will not be reproducable.

It is possible to send a new message within an implementation of this callback (for example, a response to this message), but the implementation must not disconnect the client, as it will be impossible to send an acknowledgement for the message being processed, and a deadlock will occur.

Parameters:
topic - the topic on which the message arrived.
message - the actual message.
Throws:
java.lang.Exception - if a terminal error has occurred, and the client should be shut down.

deliveryComplete

public void deliveryComplete(MqttDeliveryToken token)
Called when delivery for a message has been completed, and all acknowledgements have been received. The supplied token will be same token which was returned when the message was first sent, if it was sent using MqttTopic.publish(MqttMessage).

Parameters:
token - the delivery token associated with the message.