net.sf.xenqtt.message
Class MqttMessage

java.lang.Object
  extended by net.sf.xenqtt.message.MqttMessage
Direct Known Subclasses:
ConnAckMessage, ConnectMessage, DisconnectMessage, IdentifiableMqttMessage, PingReqMessage, PingRespMessage

public class MqttMessage
extends Object

This is a generic MQTT message. Extending classes support more specific message types


Constructor Summary
MqttMessage(MqttMessage copyFrom)
          Creates a copy of the copyFrom message.
 
Method Summary
static String byteBufferToHex(ByteBuffer buffer)
           
static String bytesToHex(byte[] bytes)
           
 boolean equals(Object obj)
           
 MessageType getMessageType()
          The type of message
 QoS getQoS()
          The level of assurance for delivery of an IdentifiableMqttMessage.
 int getQoSLevel()
          The raw integer value for the level of assurance for delivery of a PUBLISH message.
 long getReceivedTimestamp()
           
 int getRemainingLength()
          Represents the number of bytes remaining within the current message, including data in the variable header and the payload.
 boolean isAck()
           
 boolean isAckable()
           
 boolean isDuplicate()
          This flag is set when the client or server attempts to re-deliver a PUBLISH, PUBREL, SUBSCRIBE or UNSUBSCRIBE message.
 boolean isRetain()
          This flag is only used on PUBLISH messages.
 void setDuplicateFlag()
          Sets the duplicate flag on this message.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MqttMessage

public MqttMessage(MqttMessage copyFrom)
Creates a copy of the copyFrom message.

Method Detail

byteBufferToHex

public static String byteBufferToHex(ByteBuffer buffer)
Returns:
Space delimited hexadecimal string representation of the specified byte buffer

bytesToHex

public static String bytesToHex(byte[] bytes)
Returns:
Space delimited hexadecimal string representation of the specified byte array

getReceivedTimestamp

public long getReceivedTimestamp()
Returns:
Timestamp (from System.currentTimeMillis()) when the message was received. 0 if this is not a received message.

isAckable

public final boolean isAckable()
Returns:
True if getQoSLevel() > 0

isAck

public final boolean isAck()
Returns:
True if this is an ack to an ackable message (does not include ConnAckMessage.

getMessageType

public final MessageType getMessageType()
The type of message


isDuplicate

public final boolean isDuplicate()
This flag is set when the client or server attempts to re-deliver a PUBLISH, PUBREL, SUBSCRIBE or UNSUBSCRIBE message. This applies to messages where the value of QoS is greater than zero (0), and an acknowledgment is required. When the DUP bit is set, the variable header includes a Message ID.

The recipient should treat this flag as a hint as to whether the message may have been previously received. It should not be relied on to detect duplicates.


getQoS

public final QoS getQoS()
The level of assurance for delivery of an IdentifiableMqttMessage.


getQoSLevel

public final int getQoSLevel()
The raw integer value for the level of assurance for delivery of a PUBLISH message.


isRetain

public final boolean isRetain()
This flag is only used on PUBLISH messages. When a client sends a PUBLISH to a server, if the Retain flag is set (1), the server should hold on to the message after it has been delivered to the current subscribers.

When a new subscription is established on a topic, the last retained message on that topic should be sent to the subscriber with the Retain flag set. If there is no retained message, nothing is sent

This is useful where publishers send messages on a "report by exception" basis, where it might be some time between messages. This allows new subscribers to instantly receive data with the retained, or Last Known Good, value.

When a server sends a PUBLISH to a client as a result of a subscription that already existed when the original PUBLISH arrived, the Retain flag should not be set, regardless of the Retain flag of the original PUBLISH. This allows a client to distinguish messages that are being received because they were retained and those that are being received "live".

Retained messages should be kept over restarts of the server.

A server may delete a retained message if it receives a message with a zero-length payload and the Retain flag set on the same topic.


getRemainingLength

public final int getRemainingLength()
Represents the number of bytes remaining within the current message, including data in the variable header and the payload. The maximum value is 268,435,455 (256MB).


setDuplicateFlag

public final void setDuplicateFlag()
Sets the duplicate flag on this message. This is called before resending this message.


equals

public boolean equals(Object obj)
Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()


Copyright © 2013. All Rights Reserved.