Class Message
- java.lang.Object
-
- org.objectweb.joram.shared.messages.Message
-
- All Implemented Interfaces:
Encodable,Streamable,Serializable,Cloneable
public final class Message extends Object implements Cloneable, Serializable, Streamable, Encodable
Implements theMessagedata structure.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intADMINA admin message carries a streamable object.private byte[]bodyByte array containing the body of the message.private intbodyLengthThe length of the subarray inbodyto be used for message bodyprivate intbodyOffsetThe offset of the subarray inbodyto be used for message bodystatic StringBROKER_SWAPALLOWEDstatic StringBROKER_USELOADALLstatic intBYTESA bytes message carries an array of bytes.StringclientIDThe client connection identificationbooleancompressedtrueif compressed body.intcompressedMinSizeIf the message body size is greater than thecompressedMinSize, this message body is compressed.intcompressionLevelstatic StringCORRELATION_IDStringcorrelationIdThe correlation identifier field.private static shortcorrrelationIdFlagprivate static booleanDEBUGstatic intDEFAULT_DELIVERY_MODEstatic intDEFAULT_PRIORITYstatic longDEFAULT_TIME_TO_LIVEintdeliveryCountThe number of delivery attempts for this message.private static shortdeliveryCountFlaglongdeliveryTimethe message delivery time value.static StringERRORCAUSE_PREFIXstatic StringERRORCODE_PREFIXstatic StringERRORCOUNTlongexpirationThe message expiration time, by default 0 for infinite time-to-live.private static shortexpirationFlagStringidThe message identifier.StringjmsTypeThe JMSType header field contains a message type identifier supplied by a client when a message is sent.private static shortjmsTypeFlagstatic Loggerloggerloggerstatic intMAPA map message carries an hashtable.static StringMQTT_QOSstatic StringMQTT_RETAINstatic StringMQTT_TOPICstatic intNON_PERSISTENTstatic intOBJECTAn object message carries a serializable object.booleanpersistenttrueif the message must be persisted.static intPERSISTENTprivate static shortpersistentFlagintpriorityThe message priority from 0 to 9, 9 being the highest.private static shortpriorityFlagPropertiespropertiesThe message properties table.private static shortpropertiesFlagbooleanredeliveredtrueif the message has been denied at least once by a consumer.private static shortredeliveredFlagStringreplyToIdThe reply to destination identifier.private static shortreplyToIdFlagStringreplyToNameThe reply to destination name.bytereplyToTypetrueif the "reply to" destination is a queue.private static longserialVersionUIDdefine serialVersionUID for interoperabilitystatic intSIMPLEA simple message carries an empty body.static intSTREAMA stream message carries a bytes stream.static StringSWAPALLOWEDstatic intTEXTA text message carries a String body.longtimestampThe message time stamp.StringtoIdThe message destination identifier.StringtoNameThe message destination name.bytetoTypeThe message destination type.inttypeThe client message type: SIMPLE, TEXT, OBJECT, MAP, STREAM, BYTES, ADMIN.private static shorttypeFlag(package private) static String[]typeToString-
Fields inherited from interface fr.dyade.aaa.common.encoding.Encodable
BOOLEAN_ENCODED_SIZE, BYTE_ENCODED_SIZE, DOUBLE_ENCODED_SIZE, FLOAT_ENCODED_SIZE, INT_ENCODED_SIZE, LONG_ENCODED_SIZE, SHORT_ENCODED_SIZE
-
-
Constructor Summary
Constructors Constructor Description Message()Constructs a bright newMessage.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidbodyToJSon(Appendable appendable, String msgId, int type, byte[] body, int offset, int length, boolean compressed, boolean binary)Exports the specified body to JSon.voidclearBody()Set body to nullObjectclone()Clones the messagestatic byte[]compress(byte[] toCompress, int compressionLevel)Compress byte array.voiddecode(Decoder decoder)Decodes the content of this objectstatic Vector<Message>decodeMessageVector(Decoder decoder)private static voiddumpBodyToJSon(Appendable appendable, byte[] body, int offset, int length)/!voidencode(Encoder encoder)Encode this shared messagevoidencode(Encoder encoder, boolean replace, byte[] body2)This method is necessary to distinguish the purpose of encoding, persistence or otherwise.static voidencodeMessageVector(Vector<Message> messages, Encoder encoder)private static SerializablefromBytes(byte[] body, int offset, int length)Convert byte[] to serializable objectAbstractAdminMessagegetAdminMessage()Returns the AbstractAdminMessage body of the message.byte[]getBody()the body of the message, trims it and uncompress it if needed (the Message body remains unmodified)intgetBodyLength()Gets the number of bytes of the message bodyintgetBodyOffset()Returns the body offset.intgetEncodableClassId()***** ***** ***** ***** ***** ***** ***** Encodable interface. ***** ***** ***** ***** ***** ***** ***** *****intgetEncodedBodySize()Returns the size needed to encode the bodyintgetEncodedSize()Returns the size of byte array needed to encode the message including its body (even if soft is true).byte[]getJMSCorrelationIDAsBytes()Gets the correlation ID as an array of bytes for the message.HashMapgetMap()Returns the map body of the message.static intgetMessageVectorEncodedSize(Vector<Message> messages)SerializablegetObject()Returns the object body of the message.static SerializablegetObject(byte[] body, int offset, int length, boolean compressed)ObjectgetProperty(String name)Returns a property as an object.byte[]getRawBody()Should only be used by MOM message.StringgetText()Returns the text body of the message.voidheaderToJSon(Appendable appendable)booleanisFullBody()Return true if the body fills the entire byte array returned by getRawBody.booleanisNullBody()Return true if body is nullprivate voidnullableStringToJSon(Appendable appendable, String str)voidreadFrom(InputStream is)The object implements the readFrom method to restore its contents from the input stream.voidreadHeaderFrom(InputStream is)private voidreadObject(ObjectInputStream in)static Vector<Message>readVectorFrom(InputStream is)this method allows to read from the input stream a vector of messages.voidsetAdminMessage(AbstractAdminMessage adminMsg)Sets an AbstractAdminMessage as the body of the message.voidsetBody(byte[] bytes)Set the body.voidsetBody(byte[] body, int bodyOffset, int bodyLength)Sets body, bodyOffset, and bodyLength without any modification.voidsetDestination(String id, String name, byte type)Sets the message destination.voidsetJMSCorrelationIDAsBytes(byte[] correlationID)Sets the correlation ID as an array of bytes for the message.voidsetMap(HashMap map)Sets a Map as the body of the message.voidsetObject(Serializable object)Sets an object as the body of the message.voidsetProperty(String name, Object value)Sets a property value.voidsetRawBody(byte[] body)Should only be used by MOM message, sets body attribute without any modification of bodyOffset and/or bodyLength.voidsetReplyTo(String id, String name, byte type)Sets the destination to which a reply should be sent.voidsetText(String text)Sets a String as the body of the message.private byte[]toBytes(Serializable object)convert serializable object to byte[]voidtoJSon(Appendable appendable)/!voidtoJSon(Appendable appendable, boolean binary)/!StringtoString()voidtoString(StringBuffer strbuf)private static byte[]trimBody(byte[] bytes, int offset, int length)Trim the given byte array.private static byte[]uncompress(byte[] toUncompress)Uncompress byte array.voidwriteHeaderTo(OutputStream os)private voidwriteObject(ObjectOutputStream out)***** ***** ***** ***** ***** ***** ***** Serializable interface ***** ***** ***** ***** ***** ***** ***** *****voidwriteTo(OutputStream os)The object implements the writeTo method to write its contents to the output stream.static voidwriteVectorTo(Vector<Message> messages, OutputStream os)this method allows to write to the output stream a vector of message.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
define serialVersionUID for interoperability- See Also:
- Constant Field Values
-
logger
public static final Logger logger
logger
-
DEBUG
private static final boolean DEBUG
-
NON_PERSISTENT
public static final int NON_PERSISTENT
- See Also:
- Constant Field Values
-
PERSISTENT
public static final int PERSISTENT
- See Also:
- Constant Field Values
-
DEFAULT_DELIVERY_MODE
public static final int DEFAULT_DELIVERY_MODE
- See Also:
- Constant Field Values
-
DEFAULT_PRIORITY
public static final int DEFAULT_PRIORITY
- See Also:
- Constant Field Values
-
DEFAULT_TIME_TO_LIVE
public static final long DEFAULT_TIME_TO_LIVE
- See Also:
- Constant Field Values
-
SWAPALLOWED
public static final String SWAPALLOWED
- See Also:
- Constant Field Values
-
ERRORCOUNT
public static final String ERRORCOUNT
- See Also:
- Constant Field Values
-
ERRORCAUSE_PREFIX
public static final String ERRORCAUSE_PREFIX
- See Also:
- Constant Field Values
-
ERRORCODE_PREFIX
public static final String ERRORCODE_PREFIX
- See Also:
- Constant Field Values
-
CORRELATION_ID
public static final String CORRELATION_ID
- See Also:
- Constant Field Values
-
MQTT_TOPIC
public static final String MQTT_TOPIC
- See Also:
- Constant Field Values
-
MQTT_QOS
public static final String MQTT_QOS
- See Also:
- Constant Field Values
-
MQTT_RETAIN
public static final String MQTT_RETAIN
- See Also:
- Constant Field Values
-
BROKER_USELOADALL
public static final String BROKER_USELOADALL
- See Also:
- Constant Field Values
-
BROKER_SWAPALLOWED
public static final String BROKER_SWAPALLOWED
- See Also:
- Constant Field Values
-
body
private transient byte[] body
Byte array containing the body of the message. The body can be a subarray of this byte array, in this case bodyOffset and bodyLength specify the useful part of the array. If the body completely fills the array then bodyLength value is -1 (and bodyOffset is 0). If the If body is null, bodyOffset and bodyLength are not significant. On client side, use getBody and setBody instead of direct access to the body.
-
bodyOffset
private transient int bodyOffset
The offset of the subarray inbodyto be used for message body. /!\ Be careful, this attribute should not be used except in very specific cases. Use getBodyOffset instead. If body is null, this value is not significant (see getBodyOffset method). Default value is0.
-
bodyLength
private transient int bodyLength
The length of the subarray inbodyto be used for message body. /!\ Be careful, this attribute should not be used except in very specific cases. Use getBodyLength instead. Value-1means that the body completely fills the array andbodyOffsetcan be ignored. If body is null, this value is not significant (see getBodyLength method). Default value is-1.
-
properties
public transient Properties properties
The message properties table.
-
id
public transient String id
The message identifier.
-
persistent
public transient boolean persistent
trueif the message must be persisted.
-
SIMPLE
public static final int SIMPLE
A simple message carries an empty body.- See Also:
- Constant Field Values
-
TEXT
public static final int TEXT
A text message carries a String body.- See Also:
- Constant Field Values
-
OBJECT
public static final int OBJECT
An object message carries a serializable object.- See Also:
- Constant Field Values
-
MAP
public static final int MAP
A map message carries an hashtable.- See Also:
- Constant Field Values
-
STREAM
public static final int STREAM
A stream message carries a bytes stream.- See Also:
- Constant Field Values
-
BYTES
public static final int BYTES
A bytes message carries an array of bytes.- See Also:
- Constant Field Values
-
ADMIN
public static final int ADMIN
A admin message carries a streamable object.- See Also:
- Constant Field Values
-
typeToString
static String[] typeToString
-
type
public transient int type
The client message type: SIMPLE, TEXT, OBJECT, MAP, STREAM, BYTES, ADMIN. By default, the message type is SIMPLE. Be careful, this type is coded on 4 bits (see writeTo and readFrom methods).
-
jmsType
public transient String jmsType
The JMSType header field contains a message type identifier supplied by a client when a message is sent.
-
priority
public transient int priority
The message priority from 0 to 9, 9 being the highest. By default, the priority is 4. Be careful, this type is coded on 4 bits (see writeTo and readFrom methods).
-
expiration
public transient long expiration
The message expiration time, by default 0 for infinite time-to-live.
-
timestamp
public transient long timestamp
The message time stamp.
-
redelivered
public transient boolean redelivered
trueif the message has been denied at least once by a consumer.
-
toId
public transient String toId
The message destination identifier.
-
toName
public transient String toName
The message destination name.
-
toType
public transient byte toType
The message destination type.
-
compressed
public transient boolean compressed
trueif compressed body.
-
compressedMinSize
public transient int compressedMinSize
If the message body size is greater than thecompressedMinSize, this message body is compressed. By default 0, no compression.
-
compressionLevel
public transient int compressionLevel
-
deliveryTime
public transient long deliveryTime
the message delivery time value.
-
clientID
public transient String clientID
The client connection identification
-
replyToId
public transient String replyToId
The reply to destination identifier.
-
replyToName
public transient String replyToName
The reply to destination name.
-
replyToType
public transient byte replyToType
trueif the "reply to" destination is a queue.
-
correlationId
public transient String correlationId
The correlation identifier field.
-
deliveryCount
public transient int deliveryCount
The number of delivery attempts for this message.
-
typeFlag
private static final short typeFlag
- See Also:
- Constant Field Values
-
replyToIdFlag
private static final short replyToIdFlag
- See Also:
- Constant Field Values
-
propertiesFlag
private static final short propertiesFlag
- See Also:
- Constant Field Values
-
priorityFlag
private static final short priorityFlag
- See Also:
- Constant Field Values
-
expirationFlag
private static final short expirationFlag
- See Also:
- Constant Field Values
-
corrrelationIdFlag
private static final short corrrelationIdFlag
- See Also:
- Constant Field Values
-
deliveryCountFlag
private static final short deliveryCountFlag
- See Also:
- Constant Field Values
-
jmsTypeFlag
private static final short jmsTypeFlag
- See Also:
- Constant Field Values
-
redeliveredFlag
private static final short redeliveredFlag
- See Also:
- Constant Field Values
-
persistentFlag
private static final short persistentFlag
- See Also:
- Constant Field Values
-
-
Method Detail
-
getBodyOffset
public final int getBodyOffset()
Returns the body offset.- Returns:
- the body offset.
-
isFullBody
public final boolean isFullBody()
Return true if the body fills the entire byte array returned by getRawBody. In this case we don't have to use getBodyOffset and getBodyLength.- Returns:
-
getBodyLength
public final int getBodyLength()
Gets the number of bytes of the message body. /!\ Do not use broker side, the body could be null (or ensure that the body is loaded).- Returns:
- the body length, 0 if body == null.
-
getProperty
public Object getProperty(String name)
Returns a property as an object.- Parameters:
name- The property name.
-
setProperty
public void setProperty(String name, Object value)
Sets a property value. If the value is not a Java primitive object (Boolean, Number, String or byte[]) its string representation is used.- Parameters:
name- The property name.value- The property value.- Throws:
IllegalArgumentException- If the key name is illegal (null or empty string).
-
setDestination
public final void setDestination(String id, String name, byte type)
Sets the message destination.- Parameters:
id- The destination identifier.name- The destination name.type- The type of the destination.
-
setReplyTo
public final void setReplyTo(String id, String name, byte type)
Sets the destination to which a reply should be sent.- Parameters:
id- The destination identifier.type- The destination type.
-
getJMSCorrelationIDAsBytes
public final byte[] getJMSCorrelationIDAsBytes()
Gets the correlation ID as an array of bytes for the message.- Returns:
- the correlation ID for the message as an array of bytes.
-
setJMSCorrelationIDAsBytes
public final void setJMSCorrelationIDAsBytes(byte[] correlationID)
Sets the correlation ID as an array of bytes for the message.- Parameters:
correlationID- the message ID value as an array of bytes.
-
toBytes
private byte[] toBytes(Serializable object) throws IOException
convert serializable object to byte[]- Parameters:
object- the serializable object- Returns:
- the byte array
- Throws:
IOException- In case of error
-
fromBytes
private static Serializable fromBytes(byte[] body, int offset, int length) throws Exception
Convert byte[] to serializable object- Parameters:
body- the byte array containing the body.offset-length-- Returns:
- the serializable object
- Throws:
Exception- In case of error
-
setText
public void setText(String text) throws IOException
Sets a String as the body of the message.- Throws:
IOException- In case of an error while setting the text
-
getText
public String getText() throws Exception
Returns the text body of the message. Should be used only client side.- Throws:
Exception- In case of an error while getting the text
-
setMap
public void setMap(HashMap map) throws IOException
Sets a Map as the body of the message.- Throws:
IOException- In case of an error while setting the map
-
getMap
public HashMap getMap() throws Exception
Returns the map body of the message.- Throws:
Exception- In case of an error while getting the map
-
setObject
public void setObject(Serializable object) throws IOException
Sets an object as the body of the message. Should be used only client side, or ensures that the message is completely loaded.- Throws:
IOException- In case of an error while setting the object.
-
getObject
public Serializable getObject() throws Exception
Returns the object body of the message.- Throws:
Exception- In case of an error while getting the object.
-
getObject
public static Serializable getObject(byte[] body, int offset, int length, boolean compressed) throws Exception
- Throws:
Exception
-
setAdminMessage
public void setAdminMessage(AbstractAdminMessage adminMsg) throws IOException
Sets an AbstractAdminMessage as the body of the message.- Throws:
IOException- In case of an error while setting the object.
-
getAdminMessage
public AbstractAdminMessage getAdminMessage()
Returns the AbstractAdminMessage body of the message. TODO (AF): AdminMessage are normally never stored by Queue or Proxy, so body should never be swapped out. We should ensure that these messages are not persistent!- Returns:
- the AbstractAdminMessage body of the message.
-
getRawBody
public final byte[] getRawBody()
Should only be used by MOM message.- Returns:
-
setRawBody
public final void setRawBody(byte[] body)
Should only be used by MOM message, sets body attribute without any modification of bodyOffset and/or bodyLength.- Parameters:
body-
-
setBody
public final void setBody(byte[] body, int bodyOffset, int bodyLength)Sets body, bodyOffset, and bodyLength without any modification.- Parameters:
bytes-bodyOffset-bodyLength-
-
setBody
public final void setBody(byte[] bytes)
Set the body. The body is compressed if the body length is greater than compressedMinSize. /!\ Be careful, should be use only client side.- Parameters:
bytes- a byte array- Throws:
IOException- if an I/O error has occurred
-
trimBody
private static byte[] trimBody(byte[] bytes, int offset, int length)Trim the given byte array.- Parameters:
bytes- the byte array to trim, should not be null.offset-length-- Returns:
-
getBody
public final byte[] getBody() throws IOExceptionthe body of the message, trims it and uncompress it if needed (the Message body remains unmodified). /!\ Do not use broker side, the body could be null (or ensure that the body is loaded).- Returns:
- the body
- Throws:
IOException- if an I/O error has occurred
-
clearBody
public void clearBody()
Set body to null. /!\ Be careful, only use client side. Broker side, the body can be kept via bodySoftRef mom message attribute.
-
isNullBody
public final boolean isNullBody()
Return true if body is null. /!\ Be careful, only use client side. Broker side, the body can be kept via bodySoftRef mom message attribute.- Returns:
- true if body is null
-
compress
public static byte[] compress(byte[] toCompress, int compressionLevel) throws IOExceptionCompress byte array.- Parameters:
toCompress- a byte array to compress- Returns:
- the compressed byte array
- Throws:
IOException- if an I/O error has occurred
-
uncompress
private static byte[] uncompress(byte[] toUncompress) throws IOExceptionUncompress byte array.- Parameters:
toUncompress- a compressed byte array- Returns:
- the uncompressed byte array
- Throws:
IOException- if an I/O error has occurred
-
toString
public void toString(StringBuffer strbuf)
-
clone
public Object clone()
Clones the message. /!\ Be careful, if this method is used broker side, we must ensure that the body is loaded.
-
writeTo
public void writeTo(OutputStream os) throws IOException
The object implements the writeTo method to write its contents to the output stream.- Specified by:
writeToin interfaceStreamable- Parameters:
os- the stream to write the object to- Throws:
IOException- an error occurs during IO operation.
-
writeHeaderTo
public void writeHeaderTo(OutputStream os) throws IOException
- Throws:
IOException
-
readFrom
public void readFrom(InputStream is) throws IOException
The object implements the readFrom method to restore its contents from the input stream. Only used from a new Message (bodyOffset=0, bodyLength=-1).- Specified by:
readFromin interfaceStreamable- Parameters:
is- the stream to read data from in order to restore the object- Throws:
IOException- an error occurs during IO operation.
-
readHeaderFrom
public void readHeaderFrom(InputStream is) throws IOException
- Throws:
IOException
-
writeVectorTo
public static void writeVectorTo(Vector<Message> messages, OutputStream os) throws IOException
this method allows to write to the output stream a vector of message.- Parameters:
messages- the vector of messagesos- the stream to write the vector to- Throws:
IOException
-
readVectorFrom
public static Vector<Message> readVectorFrom(InputStream is) throws IOException
this method allows to read from the input stream a vector of messages.- Parameters:
is- the stream to read data from in order to restore the vector- Returns:
- the vector of messages
- Throws:
IOException
-
writeObject
private void writeObject(ObjectOutputStream out) throws IOException
***** ***** ***** ***** ***** ***** ***** Serializable interface ***** ***** ***** ***** ***** ***** ***** *****- Throws:
IOException
-
readObject
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
- Throws:
ClassNotFoundExceptionIOException
-
getEncodableClassId
public int getEncodableClassId()
***** ***** ***** ***** ***** ***** ***** Encodable interface. ***** ***** ***** ***** ***** ***** ***** *****- Specified by:
getEncodableClassIdin interfaceEncodable- Returns:
- a unique class identifier
-
getEncodedSize
public int getEncodedSize() throws ExceptionReturns the size of byte array needed to encode the message including its body (even if soft is true).- Specified by:
getEncodedSizein interfaceEncodable- Returns:
- the size of the encoded byte array
- Throws:
Exception- if an error occurs
-
getEncodedBodySize
public int getEncodedBodySize() throws ExceptionReturns the size needed to encode the body. /!\ Be careful, this size does not take into account encryption. If encryption is activated, the size is corrected in the corresponding methods.- Throws:
Exception
-
encode
public void encode(Encoder encoder, boolean replace, byte[] body2) throws Exception
This method is necessary to distinguish the purpose of encoding, persistence or otherwise.- Parameters:
encoder-replace- If true replaces the message body by the next parameter.body2- Body replacement.- Throws:
Exception
-
decode
public void decode(Decoder decoder) throws Exception
Description copied from interface:EncodableDecodes the content of this object
-
getMessageVectorEncodedSize
public static int getMessageVectorEncodedSize(Vector<Message> messages) throws Exception
- Throws:
Exception
-
encodeMessageVector
public static void encodeMessageVector(Vector<Message> messages, Encoder encoder) throws Exception
- Throws:
Exception
-
decodeMessageVector
public static Vector<Message> decodeMessageVector(Decoder decoder) throws Exception
- Throws:
Exception
-
toJSon
public void toJSon(Appendable appendable) throws IOException
/!\ Be careful, should be used in a client environment (body already loaded).- Parameters:
appendable-- Throws:
IOException
-
toJSon
public void toJSon(Appendable appendable, boolean binary) throws IOException
/!\ Be careful, should be used only with body already loaded).- Parameters:
appendable-binary-- Throws:
IOException
-
nullableStringToJSon
private void nullableStringToJSon(Appendable appendable, String str) throws IOException
- Throws:
IOException
-
headerToJSon
public void headerToJSon(Appendable appendable) throws IOException
- Throws:
IOException
-
dumpBodyToJSon
private static void dumpBodyToJSon(Appendable appendable, byte[] body, int offset, int length) throws IOException
/!\ Be careful, should only be used if body is not null!!- Parameters:
appendable-- Throws:
IOException
-
bodyToJSon
public static void bodyToJSon(Appendable appendable, String msgId, int type, byte[] body, int offset, int length, boolean compressed, boolean binary) throws IOException
Exports the specified body to JSon. Be careful, body must be loaded!!- Parameters:
appendable-msgId- The message identifier (used for logging).type- the type of JMS body.body- the byte array containing the body.offset-length-binary-- Throws:
IOException
-
-