|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2015 the original author or authors. |
|
|
|
* Copyright 2002-2016 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -26,10 +26,15 @@ import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.BeansException; |
|
|
|
import org.springframework.beans.factory.BeanInitializationException; |
|
|
|
import org.springframework.beans.factory.BeanInitializationException; |
|
|
|
import org.springframework.beans.factory.DisposableBean; |
|
|
|
import org.springframework.beans.factory.DisposableBean; |
|
|
|
import org.springframework.beans.factory.InitializingBean; |
|
|
|
import org.springframework.beans.factory.InitializingBean; |
|
|
|
|
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
|
|
|
|
import org.springframework.context.ApplicationContextAware; |
|
|
|
|
|
|
|
import org.springframework.context.ApplicationListener; |
|
|
|
import org.springframework.context.SmartLifecycle; |
|
|
|
import org.springframework.context.SmartLifecycle; |
|
|
|
|
|
|
|
import org.springframework.context.event.ContextRefreshedEvent; |
|
|
|
import org.springframework.jms.listener.MessageListenerContainer; |
|
|
|
import org.springframework.jms.listener.MessageListenerContainer; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
|
|
|
@ -53,7 +58,8 @@ import org.springframework.util.Assert; |
|
|
|
* @see MessageListenerContainer |
|
|
|
* @see MessageListenerContainer |
|
|
|
* @see JmsListenerContainerFactory |
|
|
|
* @see JmsListenerContainerFactory |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class JmsListenerEndpointRegistry implements DisposableBean, SmartLifecycle { |
|
|
|
public class JmsListenerEndpointRegistry implements DisposableBean, SmartLifecycle, |
|
|
|
|
|
|
|
ApplicationContextAware, ApplicationListener<ContextRefreshedEvent> { |
|
|
|
|
|
|
|
|
|
|
|
protected final Log logger = LogFactory.getLog(getClass()); |
|
|
|
protected final Log logger = LogFactory.getLog(getClass()); |
|
|
|
|
|
|
|
|
|
|
|
@ -62,6 +68,15 @@ public class JmsListenerEndpointRegistry implements DisposableBean, SmartLifecyc |
|
|
|
|
|
|
|
|
|
|
|
private int phase = Integer.MAX_VALUE; |
|
|
|
private int phase = Integer.MAX_VALUE; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ApplicationContext applicationContext; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean contextRefreshed; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { |
|
|
|
|
|
|
|
this.applicationContext = applicationContext; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return the {@link MessageListenerContainer} with the specified id or |
|
|
|
* Return the {@link MessageListenerContainer} with the specified id or |
|
|
|
@ -181,6 +196,13 @@ public class JmsListenerEndpointRegistry implements DisposableBean, SmartLifecyc |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onApplicationEvent(ContextRefreshedEvent event) { |
|
|
|
|
|
|
|
if (event.getApplicationContext().equals(this.applicationContext)) { |
|
|
|
|
|
|
|
this.contextRefreshed = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Delegating implementation of SmartLifecycle
|
|
|
|
// Delegating implementation of SmartLifecycle
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@ -228,11 +250,11 @@ public class JmsListenerEndpointRegistry implements DisposableBean, SmartLifecyc |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Start the specified {@link MessageListenerContainer} if it should be started |
|
|
|
* Start the specified {@link MessageListenerContainer} if it should be started |
|
|
|
* on startup. |
|
|
|
* on startup or when start is called explicitly after startup. |
|
|
|
* @see MessageListenerContainer#isAutoStartup() |
|
|
|
* @see MessageListenerContainer#isAutoStartup() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private static void startIfNecessary(MessageListenerContainer listenerContainer) { |
|
|
|
private void startIfNecessary(MessageListenerContainer listenerContainer) { |
|
|
|
if (listenerContainer.isAutoStartup()) { |
|
|
|
if (this.contextRefreshed || listenerContainer.isAutoStartup()) { |
|
|
|
listenerContainer.start(); |
|
|
|
listenerContainer.start(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|