Class ObjectMessage

  • All Implemented Interfaces:
    jakarta.jms.Message, jakarta.jms.ObjectMessage

    public final class ObjectMessage
    extends Message
    implements jakarta.jms.ObjectMessage
    Implements the jakarta.jms.ObjectMessage interface.

    An ObjectMessage object is used to send a message that contains a unique serializable Java object. It inherits from the Message interface and adds a body containing a single reference to an object.

    When a client receives an ObjectMessage, it is in read-only mode. If a client attempts to write to the message at this point, a MessageNotWriteableException is thrown. If clearBody is called, the message can now be both read from and written to.

    • Constructor Detail

      • ObjectMessage

        ObjectMessage()
        Instantiates a bright new ObjectMessage.
      • ObjectMessage

        ObjectMessage​(Session session,
                      Message momMsg)
        Instantiates an ObjectMessage wrapping a consumed MOM message containing an object.
        Parameters:
        session - The consuming session.
        momMsg - The MOM message to wrap.
    • Method Detail

      • setObject

        public void setObject​(Serializable object)
                       throws jakarta.jms.JMSException
        API method. Sets the serializable object containing this message's data. It is important to note that an ObjectMessage contains a snapshot of the object at the time setObject() is called; subsequent modifications of the object will have no effect on the ObjectMessage body.
        Specified by:
        setObject in interface jakarta.jms.ObjectMessage
        Parameters:
        object - the message's data.
        Throws:
        jakarta.jms.MessageNotWriteableException - When trying to set an object if the message body is read-only.
        jakarta.jms.MessageFormatException - If object serialization fails.
        jakarta.jms.JMSException
      • getObject

        public Serializable getObject()
                               throws jakarta.jms.MessageFormatException
        API method.
        Specified by:
        getObject in interface jakarta.jms.ObjectMessage
        Throws:
        jakarta.jms.MessageFormatException - In case of a problem when getting the body.
      • getEffectiveBody

        protected <T> T getEffectiveBody​(Class<T> c)
                                  throws jakarta.jms.JMSException
        Description copied from class: Message
        Get message body
        Overrides:
        getEffectiveBody in class Message
        Parameters:
        c - The type to which the message body will be assigned.
        Returns:
        message body
        Throws:
        jakarta.jms.JMSException - if the JMS provider fails to return a value due to some internal error.