org.eclipse.paho.client.mqttv3
Interface MqttPersistable


public interface MqttPersistable

Represents an object used to pass data to be persisted across the MqttClientPersistence interface.

When data is passed across the interface the header and payload are separated, so that unnecessary message copies may be avoided. For example, if a 10 MB payload was published it would be inefficient to create a byte array a few bytes larger than 10 MB and copy the MQTT message header and payload into a contiguous byte array.

When the request to persist data is made a separate byte array and offset is passed for the header and payload. Only the data between offset and length need be persisted. So for example, a message to be persisted consists of a header byte array starting at offset 1 and length 4, plus a payload byte array starting at offset 30 and length 40000. There are three ways in which the persistence implementation may return data to the client on recovery:


Method Summary
 byte[] getHeaderBytes()
          Returns the header bytes in an array.
 int getHeaderLength()
          Returns the length of the header.
 int getHeaderOffset()
          Returns the offset of the header within the byte array returned by getHeaderBytes().
 byte[] getPayloadBytes()
          Returns the payload bytes in an array.
 int getPayloadLength()
          Returns the length of the payload.
 int getPayloadOffset()
          Returns the offset of the payload within the byte array returned by getPayloadBytes().
 

Method Detail

getHeaderBytes

public byte[] getHeaderBytes()
                      throws MqttPersistenceException
Returns the header bytes in an array. The bytes start at getHeaderOffset() and continue for getHeaderLength().

Returns:
the header bytes.
Throws:
MqttPersistenceException

getHeaderLength

public int getHeaderLength()
                    throws MqttPersistenceException
Returns the length of the header.

Returns:
the header length
Throws:
MqttPersistenceException

getHeaderOffset

public int getHeaderOffset()
                    throws MqttPersistenceException
Returns the offset of the header within the byte array returned by getHeaderBytes().

Returns:
the header offset.
Throws:
MqttPersistenceException

getPayloadBytes

public byte[] getPayloadBytes()
                       throws MqttPersistenceException
Returns the payload bytes in an array. The bytes start at getPayloadOffset() and continue for getPayloadLength().

Returns:
the payload bytes.
Throws:
MqttPersistenceException

getPayloadLength

public int getPayloadLength()
                     throws MqttPersistenceException
Returns the length of the payload.

Returns:
the payload length.
Throws:
MqttPersistenceException

getPayloadOffset

public int getPayloadOffset()
                     throws MqttPersistenceException
Returns the offset of the payload within the byte array returned by getPayloadBytes().

Returns:
the payload offset.
Throws:
MqttPersistenceException