INT-1766 the PollableJmsChannel's timeout parameter is now honored by the underlying JmsTemplate

This commit is contained in:
Mark Fisher
2011-02-02 21:24:38 -05:00
parent cbfb6945b4
commit 221c086a74
2 changed files with 9 additions and 20 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,6 @@
package org.springframework.integration.jms;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.integration.Message;
import org.springframework.integration.core.PollableChannel;
import org.springframework.integration.support.MessageBuilder;
@@ -30,9 +27,6 @@ import org.springframework.jms.core.JmsTemplate;
*/
public class PollableJmsChannel extends AbstractJmsChannel implements PollableChannel {
private Log logger = LogFactory.getLog(this.getClass());
public PollableJmsChannel(JmsTemplate jmsTemplate) {
super(jmsTemplate);
}
@@ -50,19 +44,13 @@ public class PollableJmsChannel extends AbstractJmsChannel implements PollableCh
}
public Message<?> receive(long timeout) {
if (logger.isWarnEnabled() && this.timeoutConflictsWithTemplateValue(timeout)) {
logger.warn("The JmsTemplate's receiveTimeout value is always used for the JMS channel. " +
"Its current value is " + this.getJmsTemplate().getReceiveTimeout() +
". The passed value of " + timeout + " will be ignored.");
try {
DynamicJmsTemplateProperties.setReceiveTimeout(timeout);
return this.receive();
}
finally {
DynamicJmsTemplateProperties.clearReceiveTimeout();
}
return this.receive();
}
private boolean timeoutConflictsWithTemplateValue(long timeout) {
long templateTimeout = this.getJmsTemplate().getReceiveTimeout();
return (timeout == -1 && templateTimeout != JmsTemplate.RECEIVE_TIMEOUT_INDEFINITE_WAIT)
|| (timeout == 0 && templateTimeout != JmsTemplate.RECEIVE_TIMEOUT_NO_WAIT)
|| (timeout != templateTimeout);
}
}

View File

@@ -30,6 +30,7 @@ import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.context.SmartLifecycle;
import org.springframework.integration.channel.ChannelInterceptor;
import org.springframework.integration.jms.AbstractJmsChannel;
import org.springframework.integration.jms.DynamicJmsTemplate;
import org.springframework.integration.jms.PollableJmsChannel;
import org.springframework.integration.jms.SubscribableJmsChannel;
import org.springframework.jms.core.JmsTemplate;
@@ -56,7 +57,7 @@ public class JmsChannelFactoryBean extends AbstractFactoryBean<AbstractJmsChanne
private final boolean messageDriven;
private final JmsTemplate jmsTemplate = new JmsTemplate();
private final JmsTemplate jmsTemplate = new DynamicJmsTemplate();
private volatile AbstractMessageListenerContainer container;