|
|
|
@ -23,12 +23,15 @@ import java.util.Map; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.BeanClassLoaderAware; |
|
|
|
import org.springframework.beans.factory.BeanFactory; |
|
|
|
import org.springframework.beans.factory.BeanFactory; |
|
|
|
import org.springframework.beans.factory.BeanFactoryAware; |
|
|
|
import org.springframework.beans.factory.BeanFactoryAware; |
|
|
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException; |
|
|
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory; |
|
|
|
import org.springframework.context.ApplicationEvent; |
|
|
|
import org.springframework.context.ApplicationEvent; |
|
|
|
import org.springframework.context.ApplicationListener; |
|
|
|
import org.springframework.context.ApplicationListener; |
|
|
|
import org.springframework.core.OrderComparator; |
|
|
|
import org.springframework.core.OrderComparator; |
|
|
|
|
|
|
|
import org.springframework.util.ClassUtils; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -50,13 +53,16 @@ import org.springframework.util.ObjectUtils; |
|
|
|
* @see #getApplicationListeners(ApplicationEvent) |
|
|
|
* @see #getApplicationListeners(ApplicationEvent) |
|
|
|
* @see SimpleApplicationEventMulticaster |
|
|
|
* @see SimpleApplicationEventMulticaster |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public abstract class AbstractApplicationEventMulticaster implements ApplicationEventMulticaster, BeanFactoryAware { |
|
|
|
public abstract class AbstractApplicationEventMulticaster |
|
|
|
|
|
|
|
implements ApplicationEventMulticaster, BeanClassLoaderAware, BeanFactoryAware { |
|
|
|
|
|
|
|
|
|
|
|
private final ListenerRetriever defaultRetriever = new ListenerRetriever(false); |
|
|
|
private final ListenerRetriever defaultRetriever = new ListenerRetriever(false); |
|
|
|
|
|
|
|
|
|
|
|
private final Map<ListenerCacheKey, ListenerRetriever> retrieverCache = |
|
|
|
private final Map<ListenerCacheKey, ListenerRetriever> retrieverCache = |
|
|
|
new ConcurrentHashMap<ListenerCacheKey, ListenerRetriever>(64); |
|
|
|
new ConcurrentHashMap<ListenerCacheKey, ListenerRetriever>(64); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ClassLoader beanClassLoader; |
|
|
|
|
|
|
|
|
|
|
|
private BeanFactory beanFactory; |
|
|
|
private BeanFactory beanFactory; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -102,8 +108,16 @@ public abstract class AbstractApplicationEventMulticaster implements Application |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public final void setBeanFactory(BeanFactory beanFactory) { |
|
|
|
public void setBeanClassLoader(ClassLoader classLoader) { |
|
|
|
|
|
|
|
this.beanClassLoader = classLoader; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void setBeanFactory(BeanFactory beanFactory) { |
|
|
|
this.beanFactory = beanFactory; |
|
|
|
this.beanFactory = beanFactory; |
|
|
|
|
|
|
|
if (this.beanClassLoader == null && beanFactory instanceof ConfigurableBeanFactory) { |
|
|
|
|
|
|
|
this.beanClassLoader = ((ConfigurableBeanFactory) beanFactory).getBeanClassLoader(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private BeanFactory getBeanFactory() { |
|
|
|
private BeanFactory getBeanFactory() { |
|
|
|
@ -179,7 +193,11 @@ public abstract class AbstractApplicationEventMulticaster implements Application |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
OrderComparator.sort(allListeners); |
|
|
|
OrderComparator.sort(allListeners); |
|
|
|
|
|
|
|
if (this.beanClassLoader == null || |
|
|
|
|
|
|
|
(ClassUtils.isCacheSafe(eventType, this.beanClassLoader) && |
|
|
|
|
|
|
|
(sourceType == null || ClassUtils.isCacheSafe(sourceType, this.beanClassLoader)))) { |
|
|
|
this.retrieverCache.put(cacheKey, retriever); |
|
|
|
this.retrieverCache.put(cacheKey, retriever); |
|
|
|
|
|
|
|
} |
|
|
|
return allListeners; |
|
|
|
return allListeners; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|