@Immutable public class MessageGUID extends Object
MessageGUID
provides a value-semantic global unique identifier for BlazingMQ messages.
Each message delivered to BlazingMQ client from BlazingMQ broker contains a unique MessageGUID
.
toHex
method that can be used to externalize a
MessageGUID
instance. Applications can persist the resultant buffer (on filesystem, in
database) to keep track of last processed message ID across task instantiations. fromHex
method can be used to convert a valid externalized buffer back to a message ID.
msg
is a valid instance of AckMessage
obtained from an
instance of AbstractSession
via AckMessageHandler
:
MessageGUID g1 = msg.messageGUID(); String hex1 = g1.toHex(); assert MessageGUID.isValidHexRepresentation(hex1.getBytes()); MessageGUID g2 = MessageGUID.fromHex(hex1); assert g1.equals(g2);
Modifier and Type | Field and Description |
---|---|
static int |
SIZE_BINARY
The size of a buffer needed to represent a GUID.
|
static int |
SIZE_HEX
The size of a hexadecimal string representation of the GUID.
|
Modifier and Type | Method and Description |
---|---|
static MessageGUID |
createEmptyGUID()
Returns a zero filled
MessageGUID object. |
boolean |
equals(Object other)
Returns true if this GUID is equal to the specified
other , false otherwise. |
static MessageGUID |
fromBinary(byte[] buffer)
Returns a new
MessageGUID created from the specified buffer , in binary
format. |
static MessageGUID |
fromHex(String val)
Returns a new
MessageGUID created from the specified String contained
hexadecimal representation of the GUID. |
int |
hashCode()
Returns a hash code value for this
MessageGUID object. |
static boolean |
isValidHexRepresentation(byte[] buffer)
Returns true if the specified
buffer is a valid hex representation of a MessageGUID . |
void |
toBinary(byte[] destination)
Writes a binary representation of this object to the specified
destination which
length should be SIZE_BINARY . |
String |
toHex()
Returns a hex representation of this object as a
String . |
String |
toString()
Returns a hex representation of this object as a
String . |
public static final int SIZE_BINARY
public static final int SIZE_HEX
public static boolean isValidHexRepresentation(byte[] buffer)
buffer
is a valid hex representation of a MessageGUID
. The the buffer
should be equal to SIZE_HEX
.buffer
- Array of bytes that contrains hex representation the MessageGUID
.buffer
is a valid hex representation, false
otherwise.NullPointerException
- if the specified buffer
is nullpublic void toBinary(byte[] destination)
destination
which
length should be SIZE_BINARY
. Note that destination
can later be used to
populate a MessageGUID
object using fromBinary(byte[])
method.destination
- byte array to store a binary representation of this GUIDIllegalArgumentException
- in case of the destination
length is less
than SIZE_BINARY
NullPointerException
- if the specified destination
is nullpublic String toHex()
String
. Note that the returned
string can later be used to create a MessageGUID object using fromHex
method.public static MessageGUID fromBinary(byte[] buffer)
MessageGUID
created from the specified buffer
, in binary
format. The buffer
length should be SIZE_BINARY
.buffer
- binary representation of the GUIDMessageGUID
objectIllegalArgumentException
- in case of the buffer
length is less than
SIZE_BINARY
NullPointerException
- if the specified buffer
is nullpublic static MessageGUID fromHex(String val)
MessageGUID
created from the specified String
contained
hexadecimal representation of the GUID.val
- string with a hexadecimal representation of the GUIDMessageGUID
objectIllegalArgumentException
- in case of the specified string is not a valid
hexadecimal representation of the GUID, or if error happens during string decodingNullPointerException
- if the specified val
is nullpublic static MessageGUID createEmptyGUID()
MessageGUID
object.public String toString()
String
.public boolean equals(Object other)
other
, false otherwise. Two GUIDs
are equal if they have equal binary representations.Copyright © 2023 Bloomberg L.P.. All rights reserved.