Package org.objectweb.joram.mom.messages
Class Message
- java.lang.Object
-
- org.objectweb.joram.mom.messages.Message
-
- All Implemented Interfaces:
Encodable,Serializable,Comparable<Message>,MessageView
public final class Message extends Object implements Comparable<Message>, Serializable, Encodable, MessageView
TheMessageclass actually provides the transport facility for the data exchanged during MOM operations.A message content is always wrapped as a bytes array, it is characterized by properties and "header" fields.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMessage.MessageFactory
-
Field Summary
Fields Modifier and Type Field Description intacksCounterThe number of acknowledgements a message still expects from its subscribers before having been fully consumed by them (field used by JMS proxies).private SoftReference<byte[]>bodySoftRefSoftReference to the body of the MOM message.private static CryptocryptoCrypto module needed to encrypt/decrypt messages.private static StringCRYPTO_ALGOprivate static StringCRYPTO_ALGO_PROPERTYprivate static StringCRYPTO_DFLT_ALGOprivate static intCRYPTO_DFLT_ITERATION_COUNTprivate static intCRYPTO_DFLT_KEY_LENGTHprivate static StringCRYPTO_DFLT_NONCEprivate static StringCRYPTO_DFLT_PASSWORDprivate static StringCRYPTO_DFLT_SALTprivate static intCRYPTO_ITERATION_COUNTprivate static StringCRYPTO_ITERATION_COUNT_PROPERTYprivate static intCRYPTO_KEY_LENGTHprivate static StringCRYPTO_KEY_LENGTH_PROPERTYprivate static StringCRYPTO_NONCEprivate static StringCRYPTO_NONCE_PROPERTYprivate static StringCRYPTO_PASSWORDprivate static intCRYPTO_PASSWORD_MIN_LENGTHprivate static StringCRYPTO_PASSWORD_PROPERTYprivate static StringCRYPTO_SALTprivate static intCRYPTO_SALT_MIN_LENGTHprivate static StringCRYPTO_SALT_PROPERTYprivate static booleanDEBUGintdurableAcksCounterThe number of acknowledgements a message still expects from its durable subscribers before having been fully consumed by them (field used by JMS proxies).private static StringENCRYPT_BASEprivate static booleanENCRYPT_BODYprivate static StringENCRYPT_BODY_PROPERTY(package private) byte[]encryptedprivate static booleanglobalUseSoftRefDefines if the swapping mechanism is globally activated for messages in this server.private static Loggerloggerloggerprivate MessagemsgReference to the shared message.longorderArrival position of this message on its queue or proxy.private static longserialVersionUIDdefine serialVersionUID for interoperabilityprivate booleansofttrueif soft reference can be used for the message.(package private) StringtxnameName used to store the messageprivate static booleanuseLoadALLDefines if the queue restoration at startup must use the loadAll transaction mechanism when it is implemented.-
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
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description StringbodyToJSon()Deprecated.intcompareTo(Message msg)voiddecDeliveryCount()Decrements the message delivery count.voiddecode(Decoder decoder)Decode the message, if needed, is done during encoding, but the decryption is done in load method.private voiddecryptBody()Decrypts the message body if needed.voiddelete()static voiddeleteAll(String msgTxname)Deletes all persisted objects.voidencode(Encoder encoder)Encode the message.voidexportJSonToFile(File directory, boolean binary)intgetAcksCounter()private voidgetBody()Sets the body of the shared message if needed (soft and swapped), and locks it in memory.StringgetClientID()Get the clientIDStringgetCorrelationId()Returns the message correlation identifier.intgetDeliveryCount()Returns the message delivery count.longgetDeliveryTime()Returns the message delivery timeintgetDurableAcksCounter()intgetEncodableClassId()Returns a unique class identifier.intgetEncodedSize()Returns the size needed to encode this message.(package private) byte[]getEncrypted()longgetExpiration()Returns the message expiration time.MessagegetFullMessage()Returns the contained message with body.MessagegetHeaderMessage()Returns the contained message eventually without the body.StringgetId()Returns the message identifier.longgetOrder()intgetPriority()Returns the message priority.Map<String,String>getProperties()MessagegetSharedMsg()Gets the message, loads it from disk if needed, then sets the msg attribute.longgetTimestamp()Returns the message time stamp.StringgetTxName()intgetType()Returns the message type.booleanhasExpiration()Return true if the message has an expiration delay.voidincAcksCounter()voidincDeliveryCount()Increments the message delivery count.voidincDurableAcksCounter()booleanisPersistent()Returnstrueif the message is persistent.booleanisRedelivered()booleanisValid(long currentTime)Returnstrueif the message is valid.static Messageload(String txname)static Vector<Message>loadAll(String msgTxname, int max)Loads all persisted messages.private static byte[]loadBody(Transaction transaction, String txname)Loads the body of the specified message, this method should only be used for soft messagesstatic MessageloadMessage(Transaction transaction, String txname)Loads a message from transactional persistence.private voidreadObject(ObjectInputStream in)private voidreleaseBody()Releases the body of message.voidreleaseFullMessage()Creates a soft reference instead of a hard one linking to the body of the contained message.voidsave()Method used to save the initial state of the message.voidsaveHeader()Method used to save the header of a message after modification.voidsetCorrelationId(String correlationId)Sets the message correlation identifier.voidsetDeliveryCount(int deliveryCount)Sets the message delivery count.voidsetDeliveryTime(long deliveryTime)Sets the message delivery timevoidsetExpiration(long expiration)Sets the message expiration.voidsetIdentifier(String id)Sets the message identifier.voidsetObjectProperty(String name, Object value)Sets a property value.voidsetOrder(long order)voidsetPersistent(boolean persistent)Sets the message persistence mode.voidsetPriority(int priority)Sets the message priority.voidsetRedelivered()Sets the message redelivered flag.voidsetTimestamp(long timestamp)Sets the message time stamp.voidsetTxName(String txname)voidtoJSon(Appendable appendable, boolean binary)StringtoString()voidtoString(StringBuffer strbuf)private voidwriteObject(ObjectOutputStream out)
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
define serialVersionUID for interoperability- See Also:
- Constant Field Values
-
logger
private static final Logger logger
logger
-
DEBUG
private static final boolean DEBUG
-
ENCRYPT_BASE
private static final String ENCRYPT_BASE
- See Also:
- Constant Field Values
-
ENCRYPT_BODY_PROPERTY
private static final String ENCRYPT_BODY_PROPERTY
- See Also:
- Constant Field Values
-
ENCRYPT_BODY
private static final boolean ENCRYPT_BODY
-
CRYPTO_ALGO_PROPERTY
private static final String CRYPTO_ALGO_PROPERTY
- See Also:
- Constant Field Values
-
CRYPTO_DFLT_ALGO
private static final String CRYPTO_DFLT_ALGO
- See Also:
- Constant Field Values
-
CRYPTO_ALGO
private static final String CRYPTO_ALGO
-
CRYPTO_PASSWORD_PROPERTY
private static final String CRYPTO_PASSWORD_PROPERTY
- See Also:
- Constant Field Values
-
CRYPTO_DFLT_PASSWORD
private static final String CRYPTO_DFLT_PASSWORD
- See Also:
- Constant Field Values
-
CRYPTO_PASSWORD
private static final String CRYPTO_PASSWORD
-
CRYPTO_PASSWORD_MIN_LENGTH
private static final int CRYPTO_PASSWORD_MIN_LENGTH
- See Also:
- Constant Field Values
-
CRYPTO_SALT_PROPERTY
private static final String CRYPTO_SALT_PROPERTY
- See Also:
- Constant Field Values
-
CRYPTO_DFLT_SALT
private static final String CRYPTO_DFLT_SALT
- See Also:
- Constant Field Values
-
CRYPTO_SALT
private static final String CRYPTO_SALT
-
CRYPTO_SALT_MIN_LENGTH
private static final int CRYPTO_SALT_MIN_LENGTH
- See Also:
- Constant Field Values
-
CRYPTO_NONCE_PROPERTY
private static final String CRYPTO_NONCE_PROPERTY
- See Also:
- Constant Field Values
-
CRYPTO_DFLT_NONCE
private static final String CRYPTO_DFLT_NONCE
- See Also:
- Constant Field Values
-
CRYPTO_NONCE
private static final String CRYPTO_NONCE
-
CRYPTO_ITERATION_COUNT_PROPERTY
private static final String CRYPTO_ITERATION_COUNT_PROPERTY
- See Also:
- Constant Field Values
-
CRYPTO_DFLT_ITERATION_COUNT
private static final int CRYPTO_DFLT_ITERATION_COUNT
- See Also:
- Constant Field Values
-
CRYPTO_ITERATION_COUNT
private static final int CRYPTO_ITERATION_COUNT
-
CRYPTO_KEY_LENGTH_PROPERTY
private static final String CRYPTO_KEY_LENGTH_PROPERTY
- See Also:
- Constant Field Values
-
CRYPTO_DFLT_KEY_LENGTH
private static final int CRYPTO_DFLT_KEY_LENGTH
- See Also:
- Constant Field Values
-
CRYPTO_KEY_LENGTH
private static final int CRYPTO_KEY_LENGTH
-
crypto
private static Crypto crypto
Crypto module needed to encrypt/decrypt messages. This module is only use in agent reaction (engine thread) so we can define a unique static instance.
-
order
public transient long order
Arrival position of this message on its queue or proxy.
-
acksCounter
public transient int acksCounter
The number of acknowledgements a message still expects from its subscribers before having been fully consumed by them (field used by JMS proxies). Be careful, this field is not saved but set to 0 during message loading then calculated during the proxy initialization.
-
durableAcksCounter
public transient int durableAcksCounter
The number of acknowledgements a message still expects from its durable subscribers before having been fully consumed by them (field used by JMS proxies). Be careful, this field is not saved but set to 0 during message loading then calculated during the proxy initialization.
-
msg
private transient Message msg
Reference to the shared message. Should not be used directly, rather use getMsg so the message is restored from disk if necessary (currently not used)
-
useLoadALL
private static final boolean useLoadALL
Defines if the queue restoration at startup must use the loadAll transaction mechanism when it is implemented.Default value is false.
This property can be fixed either from
javalaunching command, or ina3servers.xmlconfiguration file.
-
bodySoftRef
private transient SoftReference<byte[]> bodySoftRef
SoftReference to the body of the MOM message.
-
soft
private transient boolean soft
trueif soft reference can be used for the message.
-
globalUseSoftRef
private static final boolean globalUseSoftRef
Defines if the swapping mechanism is globally activated for messages in this server.Default value is false.
Note: the message swapping can be finely configured using the
JMS_JORAM_SWAPALLOWEDproperty of the JMS message.This property can be fixed either from
javalaunching command, or ina3servers.xmlconfiguration file.
-
txname
transient String txname
Name used to store the message
-
encrypted
transient byte[] encrypted
-
-
Constructor Detail
-
Message
public Message()
Empty constructor.
-
Message
public Message(Message msg)
Constructs aMessageinstance.
-
-
Method Detail
-
decryptBody
private final void decryptBody()
Decrypts the message body if needed. Tests if encryption is configured, then decrypts the body and replaces it.
-
compareTo
public int compareTo(Message msg)
- Specified by:
compareToin interfaceComparable<Message>
-
getSharedMsg
public final Message getSharedMsg() throws InvalidMessageException
Gets the message, loads it from disk if needed, then sets the msg attribute. TODO (AF): /!\ Be careful, previously this method can return null if the message cannot be loaded from disk. Returning a specific RuntimeException is a work-around to avoid NPE. In a best world this exception should be handled at higher level.- Returns:
- the message.
- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
getHeaderMessage
public Message getHeaderMessage() throws InvalidMessageException
Returns the contained message eventually without the body.- Returns:
- The contained message.
- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
getBody
private void getBody()
Sets the body of the shared message if needed (soft and swapped), and locks it in memory. If needed the body is loaded from persistence and decrypted.
-
loadBody
private static byte[] loadBody(Transaction transaction, String txname)
Loads the body of the specified message, this method should only be used for soft messages. /!\ Be careful, if needed this body must be decrypted externally.- Parameters:
transaction-txname-- Returns:
-
releaseBody
private void releaseBody()
Releases the body of message. This body is only accessible via a soft reference, garbage can collect this object if necessary. If soft is false, or body is null, nothing happens.
-
getFullMessage
public Message getFullMessage() throws InvalidMessageException
Returns the contained message with body. If needed the body is loaded from repository.- Returns:
- The contained message.
- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
releaseFullMessage
public void releaseFullMessage() throws InvalidMessageExceptionCreates a soft reference instead of a hard one linking to the body of the contained message. The message must have been saved previously.- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
getType
public int getType() throws InvalidMessageExceptionReturns the message type.- Specified by:
getTypein interfaceMessageView- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
getId
public String getId() throws InvalidMessageException
Returns the message identifier.- Specified by:
getIdin interfaceMessageView- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
setIdentifier
public void setIdentifier(String id) throws InvalidMessageException
Sets the message identifier.- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
isPersistent
public boolean isPersistent() throws InvalidMessageExceptionReturnstrueif the message is persistent.- Specified by:
isPersistentin interfaceMessageView- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
setPersistent
public void setPersistent(boolean persistent) throws InvalidMessageExceptionSets the message persistence mode.- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
getPriority
public int getPriority() throws InvalidMessageExceptionReturns the message priority.- Specified by:
getPriorityin interfaceMessageView- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
setPriority
public void setPriority(int priority) throws InvalidMessageExceptionSets the message priority.- Parameters:
priority- Priority value: 0 the lowest, 9 the highest, 4 normal.- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
getExpiration
public long getExpiration() throws InvalidMessageExceptionReturns the message expiration time.- Specified by:
getExpirationin interfaceMessageView- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
setExpiration
public void setExpiration(long expiration) throws InvalidMessageExceptionSets the message expiration.- Parameters:
expiration- The expiration time.- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
getTimestamp
public long getTimestamp() throws InvalidMessageExceptionReturns the message time stamp.- Specified by:
getTimestampin interfaceMessageView- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
setTimestamp
public void setTimestamp(long timestamp) throws InvalidMessageExceptionSets the message time stamp.- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
getCorrelationId
public final String getCorrelationId() throws InvalidMessageException
Returns the message correlation identifier.- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
setCorrelationId
public void setCorrelationId(String correlationId) throws InvalidMessageException
Sets the message correlation identifier.- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
getDeliveryCount
public int getDeliveryCount() throws InvalidMessageExceptionReturns the message delivery count.- Specified by:
getDeliveryCountin interfaceMessageView- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
setDeliveryCount
public void setDeliveryCount(int deliveryCount) throws InvalidMessageExceptionSets the message delivery count.- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
incDeliveryCount
public void incDeliveryCount() throws InvalidMessageExceptionIncrements the message delivery count.- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
decDeliveryCount
public void decDeliveryCount() throws InvalidMessageExceptionDecrements the message delivery count.- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
setRedelivered
public void setRedelivered() throws InvalidMessageExceptionSets the message redelivered flag.- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
setDeliveryTime
public void setDeliveryTime(long deliveryTime) throws InvalidMessageExceptionSets the message delivery time- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
getDeliveryTime
public long getDeliveryTime() throws InvalidMessageExceptionReturns the message delivery time- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
getOrder
public long getOrder()
-
setOrder
public void setOrder(long order)
-
getAcksCounter
public int getAcksCounter()
-
incAcksCounter
public void incAcksCounter()
-
getDurableAcksCounter
public int getDurableAcksCounter()
-
incDurableAcksCounter
public void incDurableAcksCounter()
-
getClientID
public String getClientID() throws InvalidMessageException
Get the clientID- Returns:
- the clientID
- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
setObjectProperty
public void setObjectProperty(String name, Object value) throws InvalidMessageException
Sets a property value. If the value is not a Java primitive object its string representation is used.- Parameters:
name- The property name.value- The property value.- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
isValid
public boolean isValid(long currentTime) throws InvalidMessageExceptionReturnstrueif the message is valid. The message is valid if not expired.- Parameters:
currentTime- The current time to verify the expiration time.- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
hasExpiration
public final boolean hasExpiration() throws InvalidMessageExceptionReturn true if the message has an expiration delay.- Returns:
- true if the message has an expiration delay.
- Throws:
InvalidMessageException- The message cannot be loaded from disk.
-
setTxName
public final void setTxName(String txname)
-
getTxName
public final String getTxName()
-
load
public static Message load(String txname) throws IOException, ClassNotFoundException
- Throws:
IOExceptionClassNotFoundException
-
save
public void save()
Method used to save the initial state of the message. Should be called only once for each message.
-
saveHeader
public void saveHeader()
Method used to save the header of a message after modification. The body of a message should never be saved.
-
delete
public void delete()
-
loadAll
public static Vector<Message> loadAll(String msgTxname, int max)
Loads all persisted messages. The returned list is sorted according to the message order and priority if any. If there is more message to restore than max, the Message structure is created but the message is not loaded. Currently this method is always called with Integer.MAX_VALUE so all messages are really loaded.- Parameters:
msgTxname- prefix of messages to load.max- the maximum number of messages to load (currently unused).- Returns:
- a vector containing the loaded messages.
-
deleteAll
public static void deleteAll(String msgTxname)
Deletes all persisted objects.
-
bodyToJSon
@Deprecated public String bodyToJSon()
Deprecated.TODO: Only used by MOMCommandsImpl, to remove.- Specified by:
bodyToJSonin interfaceMessageView
-
isRedelivered
public boolean isRedelivered() throws InvalidMessageException- Specified by:
isRedeliveredin interfaceMessageView- Throws:
InvalidMessageException
-
getProperties
public Map<String,String> getProperties() throws InvalidMessageException
- Specified by:
getPropertiesin interfaceMessageView- Throws:
InvalidMessageException
-
toString
public void toString(StringBuffer strbuf)
-
toJSon
public void toJSon(Appendable appendable, boolean binary) throws IOException
- Throws:
IOException
-
exportJSonToFile
public void exportJSonToFile(File directory, boolean binary) throws IOException
- Throws:
IOException
-
loadMessage
public static Message loadMessage(Transaction transaction, String txname) throws ClassNotFoundException, IOException
Loads a message from transactional persistence. Needed for external tool, to avoid use of AgentServer.getTransaction method.- Parameters:
transaction-txname-- Returns:
- Throws:
ClassNotFoundExceptionIOException
-
getEncodableClassId
public int getEncodableClassId()
Description copied from interface:EncodableReturns a unique class identifier.- Specified by:
getEncodableClassIdin interfaceEncodable- Returns:
- a unique class identifier
-
getEncrypted
byte[] getEncrypted() throws UnsupportedEncodingException, GeneralSecurityException
-
getEncodedSize
public int getEncodedSize() throws ExceptionReturns the size needed to encode this message. Be careful, soft messages must be handled upstream, and in this case the body field should be null.- Specified by:
getEncodedSizein interfaceEncodable- Returns:
- the size of the encoded byte array
- Throws:
Exception- if an error occurs
-
encode
public void encode(Encoder encoder) throws Exception
Encode the message. Be careful to make the msg.body field null for messages whose body can be swapped (msg.soft).
-
decode
public void decode(Decoder decoder) throws Exception
Decode the message, if needed, is done during encoding, but the decryption is done in load method.
-
writeObject
private void writeObject(ObjectOutputStream out) throws IOException
- Throws:
IOException
-
readObject
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
- Throws:
ClassNotFoundExceptionIOException
-
-