public class Message extends Object implements jakarta.jms.Message
jakarta.jms.Message
interface.
A Joram message encapsulates a proprietary message which is used for effective MOM transport facility. It defines the message header and properties, and the acknowledge method used for all messages.
JMS messages are composed of the following parts:
Modifier and Type | Field and Description |
---|---|
private static boolean |
first |
protected jakarta.jms.Destination |
jmsDest
The JMSDestination field.
|
static Logger |
logger |
protected Message |
momMsg |
boolean |
propertiesRO
true if the properties are read-only. |
protected boolean |
RObody
true if the message body is read-only. |
protected Session |
session
If the message is actually consumed, the session that consumes it,
null otherwise. |
private static boolean |
strictVerificationError |
private static boolean |
strictVerificationWarn |
Modifier | Constructor and Description |
---|---|
protected |
Message()
Constructs a bright new
Message . |
protected |
Message(Session session,
Message momMsg)
Instantiates a
Message wrapping a consumed MOM simple message. |
Modifier and Type | Method and Description |
---|---|
void |
acknowledge()
API method.
|
private void |
checkIdentifier(String identifier) |
void |
clearBody()
API method.
|
void |
clearProperties()
API method.
|
static Message |
convertJMSMessage(jakarta.jms.Message jmsMsg)
Converts a non-Joram JMS message into a Joram message.
|
private Object |
doGetProperty(String name)
Method actually getting a property.
|
private void |
doSetProperty(String name,
Object value)
Method actually setting a new property.
|
<T> T |
getBody(Class<T> c)
Returns the message body as an object of the specified type.
|
boolean |
getBooleanProperty(String name)
API method.
|
byte |
getByteProperty(String name)
API method.
|
int |
getCompressedMinSize()
Returns the minimum size beyond which this message's body is compressed.
|
int |
getCompressionLevel()
Returns the compression level (0..9) used when this message body is compressed.
|
double |
getDoubleProperty(String name)
API method.
|
protected <T> T |
getEffectiveBody(Class<T> c)
Get message body
|
float |
getFloatProperty(String name)
API method.
|
int |
getIntProperty(String name)
API method.
|
String |
getJMSCorrelationID()
API method.
|
byte[] |
getJMSCorrelationIDAsBytes()
API method.
|
int |
getJMSDeliveryMode()
API method.
|
long |
getJMSDeliveryTime()
API 2.0
Gets the message delivery time value.
|
jakarta.jms.Destination |
getJMSDestination()
Returns the message destination.
|
long |
getJMSExpiration()
API method.
|
String |
getJMSMessageID()
API method.
|
int |
getJMSPriority()
API method.
|
boolean |
getJMSRedelivered()
API method.
|
jakarta.jms.Destination |
getJMSReplyTo()
API method.
|
long |
getJMSTimestamp()
API method.
|
String |
getJMSType()
API method.
|
long |
getLongProperty(String name)
API method.
|
Message |
getMomMsg() |
Object |
getObjectProperty(String name)
API method.
|
void |
getProperties(Map h)
Copies all of the mappings from the properties of this message to
the specified map.
|
Enumeration |
getPropertyNames()
API method.
|
short |
getShortProperty(String name)
API method.
|
String |
getStringProperty(String name)
API method.
|
private static void |
initStrictVerification() |
boolean |
isBodyAssignableTo(Class c)
API 2.0 method
|
boolean |
isCompressed() |
protected void |
prepare()
Method preparing the message for sending; resets header values, and
serializes the body (done in subclasses).
|
static void |
prepareJMSMessage(Message msg)
Prepare a JMS message for sending.
|
boolean |
propertyExists(String name)
API method.
|
void |
resetPropertiesRO()
Resets the read-only flag, in order to allow the modification
of message properties.
|
void |
setBooleanProperty(String name,
boolean value)
API method.
|
void |
setByteProperty(String name,
byte value)
API method.
|
void |
setCompressedMinSize(int compressedMinSize)
Sets the minimum size beyond which this message's body is compressed.
|
void |
setCompressionLevel(int compressionLevel)
Sets the compression level (0..9) used when this message body is compressed.
|
void |
setDoubleProperty(String name,
double value)
API method.
|
void |
setFloatProperty(String name,
float value)
API method.
|
void |
setIntProperty(String name,
int value)
API method.
|
void |
setJMSCorrelationID(String correlationID)
API method.
|
void |
setJMSCorrelationIDAsBytes(byte[] correlationID)
API method.
|
void |
setJMSDeliveryMode(int deliveryMode)
API method.
|
void |
setJMSDeliveryTime(long deliveryTime)
API 2.0
Sets the message delivery time value.
|
void |
setJMSDestination(jakarta.jms.Destination dest)
API method.
|
void |
setJMSExpiration(long expiration)
API method.
|
void |
setJMSMessageID(String id)
API method.
|
void |
setJMSPriority(int priority)
API method.
|
void |
setJMSRedelivered(boolean redelivered)
API method.
|
void |
setJMSReplyTo(jakarta.jms.Destination replyTo)
API method.
|
void |
setJMSTimestamp(long timestamp)
API method.
|
void |
setJMSType(String type)
API method.
|
void |
setLongProperty(String name,
long value)
API method.
|
void |
setObjectProperty(String name,
Object value)
API method.
|
private void |
setReadOnly()
set message read-only
|
void |
setShortProperty(String name,
short value)
API method.
|
void |
setStringProperty(String name,
String value)
API method.
|
private static boolean |
strictVerificationError() |
private static boolean |
strictVerificationWarn() |
String |
toString() |
void |
toString(StringBuffer strbuf) |
static Message |
wrapMomMessage(Session session,
Message momMsg)
Builds a Joram/JMS message from a Joram shared message.
|
public static Logger logger
protected Message momMsg
protected transient Session session
null
otherwise.protected transient jakarta.jms.Destination jmsDest
protected boolean RObody
true
if the message body is read-only.public boolean propertiesRO
true
if the properties are read-only.private static boolean first
private static boolean strictVerificationError
private static boolean strictVerificationWarn
public void setCompressedMinSize(int compressedMinSize)
compressedMinSize
- the minimum size beyond which this message's body is compressedpublic final int getCompressedMinSize()
public final boolean isCompressed()
public final void setCompressionLevel(int compressionLevel)
compressionLevel
- the compression level (0-9)public final int getCompressionLevel()
public static Message wrapMomMessage(Session session, Message momMsg) throws jakarta.jms.JMSException
session
- momMsg
- jakarta.jms.JMSException
public void acknowledge() throws jakarta.jms.JMSException
All consumed JMS messages support the acknowledge method for use when a client has specified that its JMS session's consumed messages are to be explicitly acknowledged. By invoking acknowledge on a consumed message, a client implicitly acknowledges all messages consumed by the session that the message was delivered to.
Calls to acknowledge are ignored for both transacted sessions and sessions specified to use implicit acknowledgement modes.
Messages that have been received but not acknowledged may be redelivered.
acknowledge
in interface jakarta.jms.Message
jakarta.jms.IllegalStateException
- If the session is closed.jakarta.jms.JMSException
- If the acknowledgement fails for any other reason.public void clearBody() throws jakarta.jms.JMSException
Calling this method leaves the message body in the same state as an empty body in a newly created message.
clearBody
in interface jakarta.jms.Message
jakarta.jms.JMSException
- Actually never thrown.private void setReadOnly()
public final String getJMSMessageID() throws jakarta.jms.JMSException
The JMSMessageID header field contains a value that uniquely identifies each message sent by Joram. When a message is sent, JMSMessageID is ignored, when the send or publish method returns, it contains an unique identifier assigned by Joram.
All JMSMessageID values starts with the prefix 'ID:'.
getJMSMessageID
in interface jakarta.jms.Message
jakarta.jms.JMSException
- Actually never thrown.public final void setJMSMessageID(String id) throws jakarta.jms.JMSException
This field is set when a message is sent, this method can only be used to change the value for a message that has been received.
setJMSMessageID
in interface jakarta.jms.Message
id
- the identifier for this message.jakarta.jms.JMSException
- Actually never thrown.public final int getJMSPriority() throws jakarta.jms.JMSException
The JMS API defines ten levels of priority value, with 0 as the lowest priority and 9 as the highest. In addition, clients should consider priorities 0-4 as gradations of normal priority and priorities 5-9 as gradations of expedited priority.
Default prioprity is defined by Message.DEFAULT_PRIORITY.
getJMSPriority
in interface jakarta.jms.Message
jakarta.jms.JMSException
- Actually never thrown.public final void setJMSPriority(int priority) throws jakarta.jms.JMSException
This field is set when a message is sent, this method can be used to change the value for a message that has been received.
setJMSPriority
in interface jakarta.jms.Message
priority
- the priority of this message.jakarta.jms.JMSException
- If the priority value is incorrect.public final jakarta.jms.Destination getJMSDestination() throws jakarta.jms.JMSException
Session.send()
, it can be overloaded
for received messages.
API method.
Returns the message destination. This field is set by the provider at sending, it
contains the destination to which the message is being sent.
When a message is sent, this field is ignored. After completion of the send or publish method, the field holds the destination specified by the method.
When a message is received, its JMSDestination value must be equivalent to the value assigned when it was sent. This field can be overloaded for received messages.
getJMSDestination
in interface jakarta.jms.Message
jakarta.jms.JMSException
- Actually never thrown.public final void setJMSDestination(jakarta.jms.Destination dest) throws jakarta.jms.JMSException
This field is set when message is sent, this method can only be used to change the value for a message that has been received.
setJMSDestination
in interface jakarta.jms.Message
dest
- the destination for this message.jakarta.jms.JMSException
- If the destination id not a Joram's one.public final long getJMSExpiration() throws jakarta.jms.JMSException
When a message is sent, the JMSExpiration header field is ignored. After completion of the send or publish method, it holds the expiration time of the message. This is the sum of the time-to-live value specified by the client and the GMT at the time of the send or publish.
If the time-to-live is specified as zero, JMSExpiration is set to zero to indicate that the message does not expire.
When a message's expiration time is reached, it is either discarded or forwarded to a DeadMessageQueue.
getJMSExpiration
in interface jakarta.jms.Message
jakarta.jms.JMSException
- Actually never thrown.public final void setJMSExpiration(long expiration) throws jakarta.jms.JMSException
This field is set when a message is sent, this method can only be used to change the value for a message that has been received.
setJMSExpiration
in interface jakarta.jms.Message
expiration
- the message's expiration time.jakarta.jms.JMSException
- Actually never thrown.public final boolean getJMSRedelivered() throws jakarta.jms.JMSException
If a client receives a message with the JMSRedelivered field set, it can access the JMSXDeliveryCount property to determine the number of attempts to deliver this message.
getJMSRedelivered
in interface jakarta.jms.Message
jakarta.jms.JMSException
- Actually never thrown.public final void setJMSRedelivered(boolean redelivered) throws jakarta.jms.JMSException
This field is set at the time the message is delivered, this method can only be used to change the value for a message that has been received.
setJMSRedelivered
in interface jakarta.jms.Message
redelivered
- an indication of whether this message is being redelivered.jakarta.jms.JMSException
- Actually never thrown.public final jakarta.jms.Destination getJMSReplyTo() throws jakarta.jms.JMSException
getJMSReplyTo
in interface jakarta.jms.Message
jakarta.jms.JMSException
- Actually never thrown.public final void setJMSReplyTo(jakarta.jms.Destination replyTo) throws jakarta.jms.JMSException
The JMSReplyTo header field contains the destination where a reply to the current message should be sent. The destination may be either a Queue object or a Topic object.
setJMSReplyTo
in interface jakarta.jms.Message
replyTo
- Destination to which to send a response to this message.jakarta.jms.JMSException
- If the destination id not a Joram's one.public final long getJMSTimestamp() throws jakarta.jms.JMSException
The JMSTimestamp header field contains the time a message was handed off to Joram to be sent. It is not the time the message was actually transmitted, because the actual send may occur later due to transactions or other client-side queueing of messages.
When a message is sent, JMSTimestamp is ignored. When the send or publish method returns, it contains a time value somewhere in the interval between the call and the return.
Since timestamps take some effort to create and increase a message's size, some Joram allows to optimize message overhead if they are given a hint that the timestamp is not used by an application. By calling the MessageProducer.setDisableMessageTimestamp method, a JMS client enables this potential optimization for all messages sent by that message producer.
getJMSTimestamp
in interface jakarta.jms.Message
jakarta.jms.JMSException
- Actually never thrown.public final void setJMSTimestamp(long timestamp) throws jakarta.jms.JMSException
This field is set when a message is sent, this method can only be used to change the value for a message that has been received.
setJMSTimestamp
in interface jakarta.jms.Message
timestamp
- the timestamp for this message.jakarta.jms.JMSException
- Actually never thrown.public final String getJMSCorrelationID() throws jakarta.jms.JMSException
getJMSCorrelationID
in interface jakarta.jms.Message
jakarta.jms.JMSException
- Actually never thrown.public final void setJMSCorrelationID(String correlationID) throws jakarta.jms.JMSException
A client can use the JMSCorrelationID header field to link one message with another. A typical use is to link a response message with its request message.
setJMSCorrelationID
in interface jakarta.jms.Message
correlationID
- the message ID of a message being referred to.jakarta.jms.JMSException
- Actually never thrown.public final byte[] getJMSCorrelationIDAsBytes() throws jakarta.jms.JMSException
getJMSCorrelationIDAsBytes
in interface jakarta.jms.Message
jakarta.jms.JMSException
- Actually never thrown.public final void setJMSCorrelationIDAsBytes(byte[] correlationID) throws jakarta.jms.JMSException
The use of a byte[] value for JMSCorrelationID is non-portable.
setJMSCorrelationIDAsBytes
in interface jakarta.jms.Message
correlationID
- the message ID value as an array of bytes.jakarta.jms.JMSException
- Actually never thrown.public final int getJMSDeliveryMode() throws jakarta.jms.JMSException
The delivery modes supported are DeliveryMode.PERSISTENT and DeliveryMode.NON_PERSISTENT.
getJMSDeliveryMode
in interface jakarta.jms.Message
jakarta.jms.JMSException
- Actually never thrown.DeliveryMode
public final void setJMSDeliveryMode(int deliveryMode) throws jakarta.jms.JMSException
JMS providers set this field when a message is sent. This method can be used to change the value for a message that has been received.
setJMSDeliveryMode
in interface jakarta.jms.Message
deliveryMode
- the delivery mode for this message.jakarta.jms.JMSException
- If the delivery mode is incorrect.public final String getJMSType() throws jakarta.jms.JMSException
getJMSType
in interface jakarta.jms.Message
jakarta.jms.JMSException
- Actually never thrown.public final void setJMSType(String type) throws jakarta.jms.JMSException
Joram does not define a standard message definition repository, this field can be used freely by the JMS applications.
setJMSType
in interface jakarta.jms.Message
type
- the message type.jakarta.jms.JMSException
- Actually never thrown.public final void clearProperties() throws jakarta.jms.JMSException
clearProperties
in interface jakarta.jms.Message
jakarta.jms.JMSException
- Actually never thrown.public final void resetPropertiesRO() throws jakarta.jms.JMSException
jakarta.jms.JMSException
- Actually never thrown.public final boolean propertyExists(String name) throws jakarta.jms.JMSException
propertyExists
in interface jakarta.jms.Message
name
- the name of the property to test.jakarta.jms.JMSException
- Actually never thrown.public void getProperties(Map h)
public final Enumeration getPropertyNames() throws jakarta.jms.JMSException
Note that JMS standard header fields are not considered properties and are not returned in this enumeration.
getPropertyNames
in interface jakarta.jms.Message
jakarta.jms.JMSException
- Actually never thrown.public final void setBooleanProperty(String name, boolean value) throws jakarta.jms.JMSException
setBooleanProperty
in interface jakarta.jms.Message
name
- The property name.value
- The property value.jakarta.jms.MessageNotWriteableException
- If the message is read-only.jakarta.jms.JMSException
- If the property name is invalid.public final void setByteProperty(String name, byte value) throws jakarta.jms.JMSException
setByteProperty
in interface jakarta.jms.Message
name
- The property name.value
- The property value.jakarta.jms.MessageNotWriteableException
- If the message is read-only.jakarta.jms.JMSException
- If the property name is invalid.public final void setShortProperty(String name, short value) throws jakarta.jms.JMSException
setShortProperty
in interface jakarta.jms.Message
name
- The property name.value
- The property value.jakarta.jms.MessageNotWriteableException
- If the message is read-only.jakarta.jms.JMSException
- If the property name is invalid.public final void setIntProperty(String name, int value) throws jakarta.jms.JMSException
setIntProperty
in interface jakarta.jms.Message
name
- The property name.value
- The property value.jakarta.jms.MessageNotWriteableException
- If the message is read-only.jakarta.jms.JMSException
- If the property name is invalid.public final void setLongProperty(String name, long value) throws jakarta.jms.JMSException
setLongProperty
in interface jakarta.jms.Message
name
- The property name.value
- The property value.jakarta.jms.MessageNotWriteableException
- If the message is read-only.jakarta.jms.JMSException
- If the property name is invalid.public final void setFloatProperty(String name, float value) throws jakarta.jms.JMSException
setFloatProperty
in interface jakarta.jms.Message
name
- The property name.value
- The property value.jakarta.jms.MessageNotWriteableException
- If the message is read-only.jakarta.jms.JMSException
- If the property name is invalid.public final void setDoubleProperty(String name, double value) throws jakarta.jms.JMSException
setDoubleProperty
in interface jakarta.jms.Message
name
- The property name.value
- The property value.jakarta.jms.MessageNotWriteableException
- If the message is read-only.jakarta.jms.JMSException
- If the property name is invalid.public final void setStringProperty(String name, String value) throws jakarta.jms.JMSException
setStringProperty
in interface jakarta.jms.Message
name
- The property name.value
- The property value.jakarta.jms.MessageNotWriteableException
- If the message is read-only.jakarta.jms.JMSException
- If the property name is invalid.public final void setObjectProperty(String name, Object value) throws jakarta.jms.JMSException
Note that this method works only for the objectified primitive object types (Integer, Double, Long ...) and String objects.
setObjectProperty
in interface jakarta.jms.Message
name
- The property name.value
- The property value.IllegalArgumentException
- If the key name is illegal (null or empty string).jakarta.jms.MessageFormatException
- If the value is not a Java primitive object.jakarta.jms.MessageNotWriteableException
- If the message is read-only.jakarta.jms.JMSException
- If the property name is invalid, or if the object is invalid.private final void checkIdentifier(String identifier) throws IllegalArgumentException
IllegalArgumentException
private static final void initStrictVerification()
private static final boolean strictVerificationError()
private static final boolean strictVerificationWarn()
private final void doSetProperty(String name, Object value) throws jakarta.jms.JMSException
name
- The property name.value
- The property value.jakarta.jms.MessageFormatException
- If the property type is invalid.jakarta.jms.MessageNotWriteableException
- If the message is read-only.jakarta.jms.JMSException
- If the name is invalid.IllegalArgumentException
- If the name string is null or empty.public final boolean getBooleanProperty(String name) throws jakarta.jms.JMSException
getBooleanProperty
in interface jakarta.jms.Message
name
- The property name.jakarta.jms.MessageFormatException
- If the property type is invalid.jakarta.jms.JMSException
- If the name is invalid.public final byte getByteProperty(String name) throws jakarta.jms.JMSException
getByteProperty
in interface jakarta.jms.Message
name
- The property name.jakarta.jms.MessageFormatException
- If the property type is invalid.jakarta.jms.JMSException
- If the name is invalid.public final short getShortProperty(String name) throws jakarta.jms.JMSException
getShortProperty
in interface jakarta.jms.Message
name
- The property name.jakarta.jms.MessageFormatException
- If the property type is invalid.jakarta.jms.JMSException
- If the name is invalid.public final int getIntProperty(String name) throws jakarta.jms.JMSException
getIntProperty
in interface jakarta.jms.Message
name
- The property name.jakarta.jms.MessageFormatException
- If the property type is invalid.jakarta.jms.JMSException
- If the name is invalid.public final long getLongProperty(String name) throws jakarta.jms.JMSException
getLongProperty
in interface jakarta.jms.Message
name
- The property name.jakarta.jms.MessageFormatException
- If the property type is invalid.jakarta.jms.JMSException
- If the name is invalid.public final float getFloatProperty(String name) throws jakarta.jms.JMSException
getFloatProperty
in interface jakarta.jms.Message
name
- The property name.jakarta.jms.MessageFormatException
- If the property type is invalid.jakarta.jms.JMSException
- If the name is invalid.public final double getDoubleProperty(String name) throws jakarta.jms.JMSException
getDoubleProperty
in interface jakarta.jms.Message
name
- The property name.jakarta.jms.MessageFormatException
- If the property type is invalid.jakarta.jms.JMSException
- If the name is invalid.public final String getStringProperty(String name) throws jakarta.jms.JMSException
getStringProperty
in interface jakarta.jms.Message
name
- The property name.jakarta.jms.MessageFormatException
- If the property type is invalid.jakarta.jms.JMSException
- If the name is invalid.public final Object getObjectProperty(String name) throws jakarta.jms.JMSException
This method can be used to return, in objectified format, an object that has been stored as a property in the message with the equivalent setObjectProperty method call, or its equivalent primitive settypeProperty method.
getObjectProperty
in interface jakarta.jms.Message
name
- The property name.jakarta.jms.JMSException
- If the name is invalid.private final Object doGetProperty(String name)
name
- The property name.public static Message convertJMSMessage(jakarta.jms.Message jmsMsg) throws jakarta.jms.JMSException
jmsMsg
- a JMS message.jakarta.jms.JMSException
- If an error occurs while building the message.public static void prepareJMSMessage(Message msg) throws jakarta.jms.JMSException
jakarta.jms.JMSException
protected void prepare() throws jakarta.jms.JMSException
jakarta.jms.JMSException
public Message getMomMsg()
public void toString(StringBuffer strbuf)
public boolean isBodyAssignableTo(Class c) throws jakarta.jms.JMSException
isBodyAssignableTo
in interface jakarta.jms.Message
c
- the specified type
Check if the message body is capable of being assigned to specified typejakarta.jms.JMSException
- if fail to return a value due to some internal errorpublic <T> T getBody(Class<T> c) throws jakarta.jms.JMSException
getBody
in interface jakarta.jms.Message
c
- The type to which the message body will be assigned.
If the message has no body then any type may be specified and null is returned.
TextMessage
then this parameter must
be set to String.class
or another type to which
a String
is assignable.
ObjectMessage
then parameter must
be set to java.io.Serializable.class
or
another type to which the body is assignable.
MapMessage
then this parameter must
be set to java.util.Map.class
(or java.lang.Object.class
).
BytesMessage
then this parameter must
be set to byte[].class
(or java.lang.Object.class
). This method
will reset the BytesMessage
before and after use.
TextMessage
, ObjectMessage
, MapMessage
or BytesMessage
and the message has no body,
then the above does not apply and this parameter may be set to any type;
the returned value will always be null.
Message
(but not one of its subtypes)
then this parameter may be set to any type;
the returned value will always be null.jakarta.jms.MessageFormatException
- if the message is a StreamMessage, if the message body cannot be
assigned to the specified type, or if the message is an ObjectMessage and object deserialization fails.jakarta.jms.JMSException
- if the JMS provider fails to get the message body due to some internal error.protected <T> T getEffectiveBody(Class<T> c) throws jakarta.jms.JMSException
c
- The type to which the message body will be assigned.jakarta.jms.JMSException
- if the JMS provider fails to return a value due to some internal error.public long getJMSDeliveryTime() throws jakarta.jms.JMSException
getJMSDeliveryTime
in interface jakarta.jms.Message
jakarta.jms.JMSException
- if fail to get the delivery time due to some internal error.public void setJMSDeliveryTime(long deliveryTime) throws jakarta.jms.JMSException
setJMSDeliveryTime
in interface jakarta.jms.Message
deliveryTime
- the message delivery time valuejakarta.jms.JMSException
- if fail to set the delivery time due to some internal error.Copyright © 2022 ScalAgent D.T.. All rights reserved.