Java Code Examples for javax.jms.Message.getJMSTimestamp()

The following are Jave code examples for showing how to use getJMSTimestamp() of the javax.jms.Message class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: cli-java   File: Utils.java   Source Code and License Vote up 6 votes
/**
 * Calculate TTL of given message from message
 * expiration time and message timestamp.
 * <p/>
 * Returns the time the message expires, which is the sum of the time-to-live value
 * specified by the client and the GMT at the time of the send
 * EXP_TIME = CLIENT_SEND+TTL (CLIENT_SEND??)
 * CLIENT_SEND time is approximately getJMSTimestamp() (time value between send()/publish() and return)
 * TODO - check for correctness
 *
 * @param message calculate TTL for this message
 * @return positive long number if TTL was calculated. Long.MIN_VALUE if error.
 */
public static long getTtl(Message message) {
    long ttl = 0;
    try {
        long expiration = message.getJMSExpiration();
        long timestamp = message.getJMSTimestamp();
        if (expiration != 0 && timestamp != 0) {
            ttl = expiration - timestamp;
        }
    } catch (JMSException jmse) {
        LOG.error("Error while calculating TTL value.\n" + jmse.getMessage());
        jmse.printStackTrace();
        System.exit(1);
    }
    return ttl;
}