org.eclipse.paho.client.mqttv3
Class MqttMessage

java.lang.Object
  extended by org.eclipse.paho.client.mqttv3.MqttMessage
Direct Known Subclasses:
MqttReceivedMessage

public class MqttMessage
extends Object

An MQTT message holds the application payload and options specifying how the message is to be delivered 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
protected  void checkMutable()
           
 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.
protected  void setDuplicate(boolean dup)
           
protected  void setMutable(boolean mutable)
          Sets the mutability of this object (whether or not its values can be changed.
 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.
 String toString()
          Returns a string representation of this message's payload.
static void validateQos(int qos)
          Utility method to validate the supplied QoS value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, 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

validateQos

public static void validateQos(int qos)
Utility method to validate the supplied QoS value.

Throws:
IllegalArgumentException - if value of QoS is not 0, 1 or 2.

getPayload

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

Returns:
the payload as a byte array.

clearPayload

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

Throws:
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:
IllegalStateException - if this message cannot be edited
NullPointerException - if no payload is provided

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:
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 String toString()
Returns a string representation of this message's payload. Makes an attempt to return the payload as a string. As the MQTT client has no control over the content of the payload it may fail.

Overrides:
toString in class Object
Returns:
a string representation of this message.

setMutable

protected void setMutable(boolean mutable)
Sets the mutability of this object (whether or not its values can be changed.

Parameters:
mutable - true if the values can be changed, false to prevent them from being changed.

checkMutable

protected void checkMutable()
                     throws IllegalStateException
Throws:
IllegalStateException

setDuplicate

protected void setDuplicate(boolean dup)

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.


Copyright © 2013. All Rights Reserved.