Example usage for org.springframework.jms.connection JmsResourceHolder getTimeToLiveInMillis

List of usage examples for org.springframework.jms.connection JmsResourceHolder getTimeToLiveInMillis

Introduction

In this page you can find the example usage for org.springframework.jms.connection JmsResourceHolder getTimeToLiveInMillis.

Prototype

public long getTimeToLiveInMillis() throws TransactionTimedOutException 

Source Link

Document

Return the time to live for this object in milliseconds.

Usage

From source file:com.ccc.ccm.client.JMSTemplateAutowired.java

/**
* Actually receive a JMS message.//  w  ww .  ja  v  a2  s .  c o m
* @param session the JMS Session to operate on
* @param consumer the JMS MessageConsumer to receive with
* @return the JMS Message received, or <code>null</code> if none
* @throws JMSException if thrown by JMS API methods
*/
protected Message doReceive(Session session, MessageConsumer consumer) throws JMSException {
    try {
        // Use transaction timeout (if available).
        long timeout = getReceiveTimeout();
        JmsResourceHolder resourceHolder = (JmsResourceHolder) TransactionSynchronizationManager
                .getResource(getConnectionFactory());
        if (resourceHolder != null && resourceHolder.hasTimeout()) {
            timeout = resourceHolder.getTimeToLiveInMillis();
        }
        Message message = doReceive(consumer, timeout);
        if (session.getTransacted()) {
            // Commit necessary - but avoid commit call within a JTA transaction.
            if (isSessionLocallyTransacted(session)) {
                // Transacted session created by this template -> commit.
                JmsUtils.commitIfNecessary(session);
            }
        } else if (isClientAcknowledge(session)) {
            // Manually acknowledge message, if any.
            if (message != null) {
                message.acknowledge();
            }
        }
        return message;
    } finally {
        JmsUtils.closeMessageConsumer(consumer);
    }
}