com.ibm.mqttclient
Interface MqttCallback

All Known Subinterfaces:
MqttAdvancedCallback

public interface MqttCallback

This interface class defines the methods that will be called if the simple callback mechanism is implemented. Using the simple callback interface a class can be notified of publications arriving and the TCP/IP connection unexpectedly terminating.


Method Summary
 void connectionLost(java.lang.Throwable cause)
          Called by the MQTT session if the TCP/IP connection unexpectedly terminates
This method should attempt to reconnect using the connect method.
 boolean publishArrived(java.lang.String topicName, MqttPayload payload, byte qos, boolean retained, int msgId)
          Called by the MQTT session when it receives a publish message from the broker.
 

Method Detail

connectionLost

public void connectionLost(java.lang.Throwable cause)
Called by the MQTT session if the TCP/IP connection unexpectedly terminates
This method should attempt to reconnect using the connect method. If the cleanstart flag was specified then this method should also resubscribe for all topics that the client is interested in receiving.

If the client decides to give up trying to reconnect then this method should just return.

Parameters:
cause - The Throwable which caused the connection to be declared lost.

publishArrived

public boolean publishArrived(java.lang.String topicName,
                              MqttPayload payload,
                              byte qos,
                              boolean retained,
                              int msgId)
Called by the MQTT session when it receives a publish message from the broker.

NOTE:
Any implementation of this method should NOT call any of the other API methods as this will cause a deadlock. Blocking for a significant amount of time is also not advised. If API calls or blocking are required in this method, then the method should start up a new thread to do the work.

Parameters:
topicName - The topic from which data was received
payload - An object containing a byte array and start offset of the data received on the above topic.
qos - The Quality of Service at which the pulication was delivered by the broker
retained - Is this a retained publication?
msgId - The MQTT message id of the received publication. This parameter can be used to minimise the number of times the message is persisted when reliable message receipt is required. For QoS 1 and 2 publications MqttPersistence.addReceivedMessage(MqttPersistentData) persists the publication, so when this method is called the msgId can be used to reference the already persisted message payload and thereby avoid the need for the application to persist the MqttPayload passed into publishArrived.
Returns:
false if the application was unable to receive the publication, true otherwise.
If false is returned then Quality of Service 1 and 2 publications will be periodically redelivered by the broker until publishArrived completes successfully.