INT-847 Upgrading to Spring 3.0 snapshot (CI-475 from 2009/11/25).
This commit is contained in:
@@ -23,6 +23,7 @@ import javax.jms.Topic;
|
||||
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.SmartLifecycle;
|
||||
import org.springframework.integration.channel.SubscribableChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
@@ -52,8 +53,8 @@ import org.springframework.util.Assert;
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
public class JmsDestinationBackedMessageChannel implements
|
||||
SubscribableChannel, MessageListener, BeanNameAware, InitializingBean {
|
||||
public class JmsDestinationBackedMessageChannel implements SubscribableChannel, MessageListener,
|
||||
BeanNameAware, SmartLifecycle, InitializingBean {
|
||||
|
||||
private final JmsTemplate jmsTemplate = new JmsTemplate();
|
||||
|
||||
@@ -158,4 +159,30 @@ public class JmsDestinationBackedMessageChannel implements
|
||||
}
|
||||
}
|
||||
|
||||
// SmartLifecycle implementation (delegates to the MessageListener container)
|
||||
|
||||
public int getPhase() {
|
||||
return this.container.getPhase();
|
||||
}
|
||||
|
||||
public boolean isAutoStartup() {
|
||||
return this.container.isAutoStartup();
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return this.container.isRunning();
|
||||
}
|
||||
|
||||
public void start() {
|
||||
this.container.start();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
this.container.stop();
|
||||
}
|
||||
|
||||
public void stop(Runnable callback) {
|
||||
this.container.stop(callback);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,8 +33,6 @@ public class JmsMessageDrivenEndpoint extends AbstractEndpoint implements Dispos
|
||||
|
||||
private final ChannelPublishingJmsMessageListener listener;
|
||||
|
||||
private volatile boolean autoStartup = true;
|
||||
|
||||
|
||||
public JmsMessageDrivenEndpoint(AbstractMessageListenerContainer listenerContainer, ChannelPublishingJmsMessageListener listener) {
|
||||
Assert.notNull(listenerContainer, "listener container must not be null");
|
||||
@@ -45,18 +43,8 @@ public class JmsMessageDrivenEndpoint extends AbstractEndpoint implements Dispos
|
||||
}
|
||||
|
||||
|
||||
public void setAutoStartup(boolean autoStartup) {
|
||||
this.autoStartup = autoStartup;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onInit() throws Exception {
|
||||
if (this.autoStartup) {
|
||||
this.setStartupMode(StartupMode.ON_CONTEXT_REFRESH);
|
||||
}
|
||||
else {
|
||||
this.setStartupMode(StartupMode.MANUAL);
|
||||
}
|
||||
this.listener.afterPropertiesSet();
|
||||
if (!this.listenerContainer.isActive()) {
|
||||
this.listenerContainer.afterPropertiesSet();
|
||||
|
||||
@@ -20,9 +20,14 @@ import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
import org.apache.activemq.command.ActiveMQTopic;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
@@ -77,6 +82,7 @@ public class JmsDestinationBackedMessageChannelTests {
|
||||
JmsDestinationBackedMessageChannel channel =
|
||||
new JmsDestinationBackedMessageChannel(this.connectionFactory, this.queue);
|
||||
channel.afterPropertiesSet();
|
||||
channel.start();
|
||||
channel.subscribe(handler1);
|
||||
channel.subscribe(handler2);
|
||||
channel.send(new StringMessage("foo"));
|
||||
@@ -88,6 +94,7 @@ public class JmsDestinationBackedMessageChannelTests {
|
||||
assertEquals(1, receivedList2.size());
|
||||
assertNotNull(receivedList2.get(0));
|
||||
assertEquals("bar", receivedList2.get(0).getPayload());
|
||||
channel.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -110,6 +117,7 @@ public class JmsDestinationBackedMessageChannelTests {
|
||||
JmsDestinationBackedMessageChannel channel =
|
||||
new JmsDestinationBackedMessageChannel(this.connectionFactory, this.topic);
|
||||
channel.afterPropertiesSet();
|
||||
channel.start();
|
||||
channel.subscribe(handler1);
|
||||
channel.subscribe(handler2);
|
||||
channel.send(new StringMessage("foo"));
|
||||
@@ -121,6 +129,7 @@ public class JmsDestinationBackedMessageChannelTests {
|
||||
assertEquals(2, receivedList2.size());
|
||||
assertEquals("foo", receivedList2.get(0).getPayload());
|
||||
assertEquals("bar", receivedList2.get(1).getPayload());
|
||||
channel.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -143,6 +152,7 @@ public class JmsDestinationBackedMessageChannelTests {
|
||||
JmsDestinationBackedMessageChannel channel =
|
||||
new JmsDestinationBackedMessageChannel(this.connectionFactory, "dynamicQueue", false);
|
||||
channel.afterPropertiesSet();
|
||||
channel.start();
|
||||
channel.subscribe(handler1);
|
||||
channel.subscribe(handler2);
|
||||
channel.send(new StringMessage("foo"));
|
||||
@@ -154,6 +164,7 @@ public class JmsDestinationBackedMessageChannelTests {
|
||||
assertEquals(1, receivedList2.size());
|
||||
assertNotNull(receivedList2.get(0));
|
||||
assertEquals("bar", receivedList2.get(0).getPayload());
|
||||
channel.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -176,6 +187,7 @@ public class JmsDestinationBackedMessageChannelTests {
|
||||
JmsDestinationBackedMessageChannel channel =
|
||||
new JmsDestinationBackedMessageChannel(this.connectionFactory, "dynamicTopic", true);
|
||||
channel.afterPropertiesSet();
|
||||
channel.start();
|
||||
channel.subscribe(handler1);
|
||||
channel.subscribe(handler2);
|
||||
channel.send(new StringMessage("foo"));
|
||||
@@ -187,6 +199,23 @@ public class JmsDestinationBackedMessageChannelTests {
|
||||
assertEquals(2, receivedList2.size());
|
||||
assertEquals("foo", receivedList2.get(0).getPayload());
|
||||
assertEquals("bar", receivedList2.get(1).getPayload());
|
||||
channel.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contextManagesLifecycle() {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(JmsDestinationBackedMessageChannel.class);
|
||||
builder.addConstructorArgValue(this.connectionFactory);
|
||||
builder.addConstructorArgValue("dynamicQueue");
|
||||
builder.addConstructorArgValue(false);
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
context.registerBeanDefinition("channel", builder.getBeanDefinition());
|
||||
JmsDestinationBackedMessageChannel channel = context.getBean("channel", JmsDestinationBackedMessageChannel.class);
|
||||
assertFalse(channel.isRunning());
|
||||
context.refresh();
|
||||
assertTrue(channel.isRunning());
|
||||
context.stop();
|
||||
assertFalse(channel.isRunning());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user