public class Message extends Object implements Message
javax.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 Destination |
jmsDest
The JMSDestination field.
|
static org.objectweb.util.monolog.api.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 |
DEFAULT_DELIVERY_MODE, DEFAULT_PRIORITY, DEFAULT_TIME_TO_LIVE
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(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) |
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.
|
Destination |
getJMSDestination()
Returns the message destination.
|
long |
getJMSExpiration()
API method.
|
String |
getJMSMessageID()
API method.
|
int |
getJMSPriority()
API method.
|
boolean |
getJMSRedelivered()
API method.
|
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(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(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 org.objectweb.util.monolog.api.Logger logger
protected Message momMsg
protected transient Session session
null
otherwise.protected transient 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 JMSException
session
- momMsg
- JMSException
public void acknowledge() throws 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 Message
IllegalStateException
- If the session is closed.JMSException
- If the acknowledgement fails for any other reason.public void clearBody() throws JMSException
Calling this method leaves the message body in the same state as an empty body in a newly created message.
clearBody
in interface Message
JMSException
- Actually never thrown.private void setReadOnly()
public final String getJMSMessageID() throws 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 Message
JMSException
- Actually never thrown.public final void setJMSMessageID(String id) throws 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 Message
id
- the identifier for this message.JMSException
- Actually never thrown.public final int getJMSPriority() throws 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 Message
JMSException
- Actually never thrown.public final void setJMSPriority(int priority) throws 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 Message
priority
- the priority of this message.JMSException
- If the priority value is incorrect.public final Destination getJMSDestination() throws 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 Message
JMSException
- Actually never thrown.public final void setJMSDestination(Destination dest) throws 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 Message
dest
- the destination for this message.JMSException
- If the destination id not a Joram's one.public final long getJMSExpiration() throws 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 Message
JMSException
- Actually never thrown.public final void setJMSExpiration(long expiration) throws 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 Message
expiration
- the message's expiration time.JMSException
- Actually never thrown.public final boolean getJMSRedelivered() throws 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 Message
JMSException
- Actually never thrown.public final void setJMSRedelivered(boolean redelivered) throws 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 Message
redelivered
- an indication of whether this message is being redelivered.JMSException
- Actually never thrown.public final Destination getJMSReplyTo() throws JMSException
getJMSReplyTo
in interface Message
JMSException
- Actually never thrown.public final void setJMSReplyTo(Destination replyTo) throws 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 Message
replyTo
- Destination to which to send a response to this message.JMSException
- If the destination id not a Joram's one.public final long getJMSTimestamp() throws 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 Message
JMSException
- Actually never thrown.public final void setJMSTimestamp(long timestamp) throws 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 Message
timestamp
- the timestamp for this message.JMSException
- Actually never thrown.public final String getJMSCorrelationID() throws JMSException
getJMSCorrelationID
in interface Message
JMSException
- Actually never thrown.public final void setJMSCorrelationID(String correlationID) throws 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 Message
correlationID
- the message ID of a message being referred to.JMSException
- Actually never thrown.public final byte[] getJMSCorrelationIDAsBytes() throws JMSException
getJMSCorrelationIDAsBytes
in interface Message
JMSException
- Actually never thrown.public final void setJMSCorrelationIDAsBytes(byte[] correlationID) throws JMSException
The use of a byte[] value for JMSCorrelationID is non-portable.
setJMSCorrelationIDAsBytes
in interface Message
correlationID
- the message ID value as an array of bytes.JMSException
- Actually never thrown.public final int getJMSDeliveryMode() throws JMSException
The delivery modes supported are DeliveryMode.PERSISTENT and DeliveryMode.NON_PERSISTENT.
getJMSDeliveryMode
in interface Message
JMSException
- Actually never thrown.DeliveryMode
public final void setJMSDeliveryMode(int deliveryMode) throws 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 Message
deliveryMode
- the delivery mode for this message.JMSException
- If the delivery mode is incorrect.public final String getJMSType() throws JMSException
getJMSType
in interface Message
JMSException
- Actually never thrown.public final void setJMSType(String type) throws JMSException
Joram does not define a standard message definition repository, this field can be used freely by the JMS applications.
setJMSType
in interface Message
type
- the message type.JMSException
- Actually never thrown.public final void clearProperties() throws JMSException
clearProperties
in interface Message
JMSException
- Actually never thrown.public final void resetPropertiesRO() throws JMSException
JMSException
- Actually never thrown.public final boolean propertyExists(String name) throws JMSException
propertyExists
in interface Message
name
- the name of the property to test.JMSException
- Actually never thrown.public void getProperties(Map h)
public final Enumeration getPropertyNames() throws JMSException
Note that JMS standard header fields are not considered properties and are not returned in this enumeration.
getPropertyNames
in interface Message
JMSException
- Actually never thrown.public final void setBooleanProperty(String name, boolean value) throws JMSException
setBooleanProperty
in interface Message
name
- The property name.value
- The property value.MessageNotWriteableException
- If the message is read-only.JMSException
- If the property name is invalid.public final void setByteProperty(String name, byte value) throws JMSException
setByteProperty
in interface Message
name
- The property name.value
- The property value.MessageNotWriteableException
- If the message is read-only.JMSException
- If the property name is invalid.public final void setShortProperty(String name, short value) throws JMSException
setShortProperty
in interface Message
name
- The property name.value
- The property value.MessageNotWriteableException
- If the message is read-only.JMSException
- If the property name is invalid.public final void setIntProperty(String name, int value) throws JMSException
setIntProperty
in interface Message
name
- The property name.value
- The property value.MessageNotWriteableException
- If the message is read-only.JMSException
- If the property name is invalid.public final void setLongProperty(String name, long value) throws JMSException
setLongProperty
in interface Message
name
- The property name.value
- The property value.MessageNotWriteableException
- If the message is read-only.JMSException
- If the property name is invalid.public final void setFloatProperty(String name, float value) throws JMSException
setFloatProperty
in interface Message
name
- The property name.value
- The property value.MessageNotWriteableException
- If the message is read-only.JMSException
- If the property name is invalid.public final void setDoubleProperty(String name, double value) throws JMSException
setDoubleProperty
in interface Message
name
- The property name.value
- The property value.MessageNotWriteableException
- If the message is read-only.JMSException
- If the property name is invalid.public final void setStringProperty(String name, String value) throws JMSException
setStringProperty
in interface Message
name
- The property name.value
- The property value.MessageNotWriteableException
- If the message is read-only.JMSException
- If the property name is invalid.public final void setObjectProperty(String name, Object value) throws JMSException
Note that this method works only for the objectified primitive object types (Integer, Double, Long ...) and String objects.
setObjectProperty
in interface Message
name
- The property name.value
- The property value.MessageROException
- If the message properties are read-only.MessageFormatException
- If the value is not a Java primitive object.IllegalArgumentException
- If the key name is illegal (null or empty string).MessageFormatException
- If the property type is invalid.MessageNotWriteableException
- If the message is read-only.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 JMSException
name
- The property name.value
- The property value.MessageFormatException
- If the property type is invalid.MessageNotWriteableException
- If the message is read-only.JMSException
- If the name is invalid.IllegalArgumentException
- If the name string is null or empty.public final boolean getBooleanProperty(String name) throws JMSException
getBooleanProperty
in interface Message
name
- The property name.MessageFormatException
- If the property type is invalid.JMSException
- If the name is invalid.public final byte getByteProperty(String name) throws JMSException
getByteProperty
in interface Message
name
- The property name.MessageFormatException
- If the property type is invalid.JMSException
- If the name is invalid.public final short getShortProperty(String name) throws JMSException
getShortProperty
in interface Message
name
- The property name.MessageFormatException
- If the property type is invalid.JMSException
- If the name is invalid.public final int getIntProperty(String name) throws JMSException
getIntProperty
in interface Message
name
- The property name.MessageFormatException
- If the property type is invalid.JMSException
- If the name is invalid.public final long getLongProperty(String name) throws JMSException
getLongProperty
in interface Message
name
- The property name.MessageFormatException
- If the property type is invalid.JMSException
- If the name is invalid.public final float getFloatProperty(String name) throws JMSException
getFloatProperty
in interface Message
name
- The property name.MessageFormatException
- If the property type is invalid.JMSException
- If the name is invalid.public final double getDoubleProperty(String name) throws JMSException
getDoubleProperty
in interface Message
name
- The property name.MessageFormatException
- If the property type is invalid.JMSException
- If the name is invalid.public final String getStringProperty(String name) throws JMSException
getStringProperty
in interface Message
name
- The property name.MessageFormatException
- If the property type is invalid.JMSException
- If the name is invalid.public final Object getObjectProperty(String name) throws 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 Message
name
- The property name.JMSException
- If the name is invalid.private final Object doGetProperty(String name)
name
- The property name.public static Message convertJMSMessage(Message jmsMsg) throws JMSException
jmsMsg
- a JMS message.JMSException
- If an error occurs while building the message.public static void prepareJMSMessage(Message msg) throws JMSException
JMSException
protected void prepare() throws JMSException
JMSException
public Message getMomMsg()
public void toString(StringBuffer strbuf)
public boolean isBodyAssignableTo(Class c) throws JMSException
c
- the specified type
Check if the message body is capable of being assigned to specified typeJMSExeption
- if fail to return a value due to some internal errorJMSException
public <T> T getBody(Class<T> c) throws JMSException
c-
- The type to which the message body will be assigned. 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.JMSException
protected <T> T getEffectiveBody(Class<T> c) throws JMSException
JMSException
- if the JMS provider fails to return a value due to some internal error.public long getJMSDeliveryTime() throws JMSException
if
- fail to get the delivery time due to some internal error.JMSException
public void setJMSDeliveryTime(long deliveryTime) throws JMSException
deliveryTime
- the message delivery time valueif
- fail to set the delivery time due to some internal error.JMSException
Copyright © 2020 ScalAgent D.T.. All rights reserved.