org.eclipse.paho.client.mqttv3
Class MqttMessage

java.lang.Object
  extended byorg.eclipse.paho.client.mqttv3.MqttMessage

public class MqttMessage
extends java.lang.Object

An MQTT message. The message includes a "payload" (the body of the message) represented as a byte[].


Constructor Summary
MqttMessage()
          Constructs a message with an empty payload, and all other values set to defaults.
MqttMessage(byte[] payload)
          Constructs a message with the specified byte array as a payload, and all other values set to defaults.
 
Method Summary
 void clearPayload()
          Clears the payload, resetting it to be empty.
 byte[] getPayload()
          Returns the payload as a byte array.
 int getQos()
          Returns the quality of service for this message.
 boolean isDuplicate()
          Returns whether or not this message might be a duplicate of one which has already been received.
 boolean isRetained()
          Returns whether or not this message should be/was retained by the server.
 void setPayload(byte[] payload)
          Sets the payload of this message to be the specified byte array.
 void setQos(int qos)
          Sets the quality of service for this message.
 void setRetained(boolean retained)
          Whether or not the publish message should be retained by the messaging engine.
 java.lang.String toString()
          Returns a string representation of this message.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MqttMessage

public MqttMessage()
Constructs a message with an empty payload, and all other values set to defaults. The defaults are:


MqttMessage

public MqttMessage(byte[] payload)
Constructs a message with the specified byte array as a payload, and all other values set to defaults.

Method Detail

getPayload

public byte[] getPayload()
                  throws MqttException
Returns the payload as a byte array.

Returns:
the payload as a byte array.
Throws:
MqttException

clearPayload

public void clearPayload()
Clears the payload, resetting it to be empty.

Throws:
java.lang.IllegalStateException - if this message cannot be edited

setPayload

public void setPayload(byte[] payload)
Sets the payload of this message to be the specified byte array.

Parameters:
payload - the payload for this message.
Throws:
java.lang.IllegalStateException - if this message cannot be edited

isRetained

public boolean isRetained()
Returns whether or not this message should be/was retained by the server. For messages received from the server, this method returns whether or not the message was from a current publisher, or was "retained" by the server as the last message published on the topic.

Returns:
true if the message should be, or was, retained by the server.
See Also:
setRetained(boolean)

setRetained

public void setRetained(boolean retained)
Whether or not the publish message should be retained by the messaging engine. Sending a message with the retained set to false will clear the retained message from the server. The default value is false

Parameters:
retained - whether or not the messaging engine should retain the message.
Throws:
java.lang.IllegalStateException - if this message cannot be edited

getQos

public int getQos()
Returns the quality of service for this message.

Returns:
the quality of service to use, either 0, 1, or 2.
See Also:
setQos(int)

setQos

public void setQos(int qos)
Sets the quality of service for this message.

toString

public java.lang.String toString()
Returns a string representation of this message.

Returns:
a string representation of this message.

isDuplicate

public boolean isDuplicate()
Returns whether or not this message might be a duplicate of one which has already been received. This will only be set on messages received from the server.

Returns:
true if the message might be a duplicate.