Class 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
      • 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 in body to 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 is 0.
      • bodyLength

        private transient int bodyLength
        The length of the subarray in body to be used for message body. /!\ Be careful, this attribute should not be used except in very specific cases. Use getBodyLength instead. Value -1 means that the body completely fills the array and bodyOffset can 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
        true if 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
      • 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
        true if 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
        true if compressed body.
      • compressedMinSize

        public transient int compressedMinSize
        If the message body size is greater than the compressedMinSize, 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
        true if 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.
    • Constructor Detail

      • Message

        public Message()
        Constructs a bright new Message.
    • 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.
      • 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 IOException
        the 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 IOException
        Compress 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 IOException
        Uncompress byte array.
        Parameters:
        toUncompress - a compressed byte array
        Returns:
        the uncompressed byte array
        Throws:
        IOException - if an I/O error has occurred
      • clone

        public Object clone()
        Clones the message. /!\ Be careful, if this method is used broker side, we must ensure that the body is loaded.
        Overrides:
        clone in class Object
      • writeTo

        public void writeTo​(OutputStream os)
                     throws IOException
        The object implements the writeTo method to write its contents to the output stream.
        Specified by:
        writeTo in interface Streamable
        Parameters:
        os - the stream to write the object to
        Throws:
        IOException - an error occurs during IO operation.
      • 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:
        readFrom in interface Streamable
        Parameters:
        is - the stream to read data from in order to restore the object
        Throws:
        IOException - an error occurs during IO operation.
      • 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 messages
        os - 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
      • getEncodableClassId

        public int getEncodableClassId()
        ***** ***** ***** ***** ***** ***** ***** Encodable interface. ***** ***** ***** ***** ***** ***** ***** *****
        Specified by:
        getEncodableClassId in interface Encodable
        Returns:
        a unique class identifier
      • getEncodedSize

        public int getEncodedSize()
                           throws Exception
        Returns the size of byte array needed to encode the message including its body (even if soft is true).
        Specified by:
        getEncodedSize in interface Encodable
        Returns:
        the size of the encoded byte array
        Throws:
        Exception - if an error occurs
      • getEncodedBodySize

        public int getEncodedBodySize()
                               throws Exception
        Returns 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)
                    throws Exception
        Encode this shared message
        Specified by:
        encode in interface Encodable
        Parameters:
        encoder - the encoder to be used for the encoding
        Throws:
        Exception - if an error occurs
      • 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: Encodable
        Decodes the content of this object
        Specified by:
        decode in interface Encodable
        Parameters:
        decoder - the decoder to be used for the decoding
        Throws:
        Exception - if an error occurs
      • 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
      • 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