Polishing

This commit is contained in:
Juergen Hoeller 2013-10-30 19:30:18 +01:00
parent 9cbac985fb
commit ac7e27b785
2 changed files with 11 additions and 10 deletions

View File

@ -136,7 +136,7 @@ public abstract class AbstractApplicationEventMulticaster implements Application
protected Collection<ApplicationListener> getApplicationListeners(ApplicationEvent event) { protected Collection<ApplicationListener> getApplicationListeners(ApplicationEvent event) {
Class<? extends ApplicationEvent> eventType = event.getClass(); Class<? extends ApplicationEvent> eventType = event.getClass();
Object source = event.getSource(); Object source = event.getSource();
Class sourceType = (source == null ? null : source.getClass()); Class<?> sourceType = (source != null ? source.getClass() : null);
ListenerCacheKey cacheKey = new ListenerCacheKey(eventType, sourceType); ListenerCacheKey cacheKey = new ListenerCacheKey(eventType, sourceType);
ListenerRetriever retriever = this.retrieverCache.get(cacheKey); ListenerRetriever retriever = this.retrieverCache.get(cacheKey);
if (retriever != null) { if (retriever != null) {
@ -199,11 +199,11 @@ public abstract class AbstractApplicationEventMulticaster implements Application
*/ */
private static class ListenerCacheKey { private static class ListenerCacheKey {
private final Class eventType; private final Class<?> eventType;
private final Class sourceType; private final Class<?> sourceType;
public ListenerCacheKey(Class eventType, Class sourceType) { public ListenerCacheKey(Class<?> eventType, Class<?> sourceType) {
this.eventType = eventType; this.eventType = eventType;
this.sourceType = sourceType; this.sourceType = sourceType;
} }
@ -214,14 +214,13 @@ public abstract class AbstractApplicationEventMulticaster implements Application
return true; return true;
} }
ListenerCacheKey otherKey = (ListenerCacheKey) other; ListenerCacheKey otherKey = (ListenerCacheKey) other;
return ObjectUtils.nullSafeEquals(this.eventType, otherKey.eventType) return ObjectUtils.nullSafeEquals(this.eventType, otherKey.eventType) &&
&& ObjectUtils.nullSafeEquals(this.sourceType, otherKey.sourceType); ObjectUtils.nullSafeEquals(this.sourceType, otherKey.sourceType);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return ObjectUtils.nullSafeHashCode(this.eventType) * 29 return ObjectUtils.nullSafeHashCode(this.eventType) * 29 + ObjectUtils.nullSafeHashCode(this.sourceType);
+ ObjectUtils.nullSafeHashCode(this.sourceType);
} }
} }

View File

@ -37,6 +37,7 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProce
import org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor; import org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ApplicationEventMulticaster;
import org.springframework.core.OrderComparator; import org.springframework.core.OrderComparator;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.core.PriorityOrdered; import org.springframework.core.PriorityOrdered;
@ -369,8 +370,9 @@ class PostProcessorRegistrationDelegate {
@Override @Override
public void postProcessBeforeDestruction(Object bean, String beanName) { public void postProcessBeforeDestruction(Object bean, String beanName) {
if (bean instanceof ApplicationListener) { if (bean instanceof ApplicationListener) {
this.applicationContext.getApplicationEventMulticaster().removeApplicationListener((ApplicationListener) bean); ApplicationEventMulticaster multicaster = this.applicationContext.getApplicationEventMulticaster();
this.applicationContext.getApplicationEventMulticaster().removeApplicationListenerBean(beanName); multicaster.removeApplicationListener((ApplicationListener) bean);
multicaster.removeApplicationListenerBean(beanName);
} }
} }
} }