optimized OrderComparator usage
This commit is contained in:
parent
9871e94cad
commit
43caa57296
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.aop.aspectj.annotation;
|
package org.springframework.aop.aspectj.annotation;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -121,7 +120,7 @@ public class AspectJProxyFactory extends ProxyCreatorSupport {
|
||||||
List<Advisor> advisors = this.aspectFactory.getAdvisors(instanceFactory);
|
List<Advisor> advisors = this.aspectFactory.getAdvisors(instanceFactory);
|
||||||
advisors = AopUtils.findAdvisorsThatCanApply(advisors, getTargetClass());
|
advisors = AopUtils.findAdvisorsThatCanApply(advisors, getTargetClass());
|
||||||
AspectJProxyUtils.makeAdvisorChainAspectJCapableIfNecessary(advisors);
|
AspectJProxyUtils.makeAdvisorChainAspectJCapableIfNecessary(advisors);
|
||||||
Collections.sort(advisors, new OrderComparator());
|
OrderComparator.sort(advisors);
|
||||||
addAdvisors(advisors);
|
addAdvisors(advisors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2006 the original author or authors.
|
* Copyright 2002-2009 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.
|
||||||
|
|
@ -55,14 +55,14 @@ class AspectJPrecedenceComparator implements Comparator {
|
||||||
private static final int LOWER_PRECEDENCE = 1;
|
private static final int LOWER_PRECEDENCE = 1;
|
||||||
private static final int NOT_COMPARABLE = 0;
|
private static final int NOT_COMPARABLE = 0;
|
||||||
|
|
||||||
private final Comparator advisorComparator;
|
private final Comparator<? super Advisor> advisorComparator;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a default AspectJPrecedenceComparator.
|
* Create a default AspectJPrecedenceComparator.
|
||||||
*/
|
*/
|
||||||
public AspectJPrecedenceComparator() {
|
public AspectJPrecedenceComparator() {
|
||||||
this.advisorComparator = new OrderComparator();
|
this.advisorComparator = OrderComparator.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -70,7 +70,7 @@ class AspectJPrecedenceComparator implements Comparator {
|
||||||
* for comparing {@link org.springframework.aop.Advisor} instances.
|
* for comparing {@link org.springframework.aop.Advisor} instances.
|
||||||
* @param advisorComparator the Comparator to use for Advisors
|
* @param advisorComparator the Comparator to use for Advisors
|
||||||
*/
|
*/
|
||||||
public AspectJPrecedenceComparator(Comparator advisorComparator) {
|
public AspectJPrecedenceComparator(Comparator<? super Advisor> advisorComparator) {
|
||||||
Assert.notNull(advisorComparator, "Advisor comparator must not be null");
|
Assert.notNull(advisorComparator, "Advisor comparator must not be null");
|
||||||
this.advisorComparator = advisorComparator;
|
this.advisorComparator = advisorComparator;
|
||||||
}
|
}
|
||||||
|
|
@ -138,12 +138,8 @@ class AspectJPrecedenceComparator implements Comparator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean declaredInSameAspect(Advisor advisor1, Advisor advisor2) {
|
private boolean declaredInSameAspect(Advisor advisor1, Advisor advisor2) {
|
||||||
if (!(hasAspectName(advisor1) && hasAspectName(advisor2))) {
|
return (hasAspectName(advisor1) && hasAspectName(advisor2) &&
|
||||||
return false;
|
getAspectName(advisor1).equals(getAspectName(advisor2)));
|
||||||
}
|
|
||||||
else {
|
|
||||||
return getAspectName(advisor1).equals(getAspectName(advisor2));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasAspectName(Advisor anAdvisor) {
|
private boolean hasAspectName(Advisor anAdvisor) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2009 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.
|
||||||
|
|
@ -21,9 +21,7 @@ import java.io.ObjectInputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -474,7 +472,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
|
||||||
* We need to do this every time a new prototype instance is returned,
|
* We need to do this every time a new prototype instance is returned,
|
||||||
* to return distinct instances of prototype Advisors and Advices.
|
* to return distinct instances of prototype Advisors and Advices.
|
||||||
*/
|
*/
|
||||||
private List freshAdvisorChain() {
|
private List<Advisor> freshAdvisorChain() {
|
||||||
Advisor[] advisors = getAdvisors();
|
Advisor[] advisors = getAdvisors();
|
||||||
List<Advisor> freshAdvisors = new ArrayList<Advisor>(advisors.length);
|
List<Advisor> freshAdvisors = new ArrayList<Advisor>(advisors.length);
|
||||||
for (Advisor advisor : advisors) {
|
for (Advisor advisor : advisors) {
|
||||||
|
|
@ -521,7 +519,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
|
||||||
beans.add(bean);
|
beans.add(bean);
|
||||||
names.put(bean, name);
|
names.put(bean, name);
|
||||||
}
|
}
|
||||||
Collections.sort(beans, new OrderComparator());
|
OrderComparator.sort(beans);
|
||||||
for (Object bean : beans) {
|
for (Object bean : beans) {
|
||||||
String name = names.get(bean);
|
String name = names.get(bean);
|
||||||
if (name.startsWith(prefix)) {
|
if (name.startsWith(prefix)) {
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.aop.framework.autoproxy;
|
package org.springframework.aop.framework.autoproxy;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.aop.Advisor;
|
import org.springframework.aop.Advisor;
|
||||||
|
|
@ -141,7 +140,7 @@ public abstract class AbstractAdvisorAutoProxyCreator extends AbstractAutoProxyC
|
||||||
* @see org.springframework.core.OrderComparator
|
* @see org.springframework.core.OrderComparator
|
||||||
*/
|
*/
|
||||||
protected List<Advisor> sortAdvisors(List<Advisor> advisors) {
|
protected List<Advisor> sortAdvisors(List<Advisor> advisors) {
|
||||||
Collections.sort(advisors, new OrderComparator());
|
OrderComparator.sort(advisors);
|
||||||
return advisors;
|
return advisors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2009 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.
|
||||||
|
|
@ -522,8 +522,8 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
|
||||||
aliases.add(fullBeanName);
|
aliases.add(fullBeanName);
|
||||||
}
|
}
|
||||||
String[] retrievedAliases = super.getAliases(beanName);
|
String[] retrievedAliases = super.getAliases(beanName);
|
||||||
for (String retrievedAliase : retrievedAliases) {
|
for (String retrievedAlias : retrievedAliases) {
|
||||||
String alias = (factoryPrefix ? FACTORY_BEAN_PREFIX : "") + retrievedAliase;
|
String alias = (factoryPrefix ? FACTORY_BEAN_PREFIX : "") + retrievedAlias;
|
||||||
if (!alias.equals(name)) {
|
if (!alias.equals(name)) {
|
||||||
aliases.add(alias);
|
aliases.add(alias);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ package org.springframework.context.support;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
|
|
@ -515,7 +514,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, invoke the BeanFactoryPostProcessors that implement PriorityOrdered.
|
// First, invoke the BeanFactoryPostProcessors that implement PriorityOrdered.
|
||||||
Collections.sort(priorityOrderedPostProcessors, new OrderComparator());
|
OrderComparator.sort(priorityOrderedPostProcessors);
|
||||||
invokeBeanFactoryPostProcessors(beanFactory, priorityOrderedPostProcessors);
|
invokeBeanFactoryPostProcessors(beanFactory, priorityOrderedPostProcessors);
|
||||||
|
|
||||||
// Next, invoke the BeanFactoryPostProcessors that implement Ordered.
|
// Next, invoke the BeanFactoryPostProcessors that implement Ordered.
|
||||||
|
|
@ -523,7 +522,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
||||||
for (String postProcessorName : orderedPostProcessorNames) {
|
for (String postProcessorName : orderedPostProcessorNames) {
|
||||||
orderedPostProcessors.add(getBean(postProcessorName, BeanFactoryPostProcessor.class));
|
orderedPostProcessors.add(getBean(postProcessorName, BeanFactoryPostProcessor.class));
|
||||||
}
|
}
|
||||||
Collections.sort(orderedPostProcessors, new OrderComparator());
|
OrderComparator.sort(orderedPostProcessors);
|
||||||
invokeBeanFactoryPostProcessors(beanFactory, orderedPostProcessors);
|
invokeBeanFactoryPostProcessors(beanFactory, orderedPostProcessors);
|
||||||
|
|
||||||
// Finally, invoke all other BeanFactoryPostProcessors.
|
// Finally, invoke all other BeanFactoryPostProcessors.
|
||||||
|
|
@ -577,7 +576,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, register the BeanPostProcessors that implement PriorityOrdered.
|
// First, register the BeanPostProcessors that implement PriorityOrdered.
|
||||||
Collections.sort(priorityOrderedPostProcessors, new OrderComparator());
|
OrderComparator.sort(priorityOrderedPostProcessors);
|
||||||
registerBeanPostProcessors(beanFactory, priorityOrderedPostProcessors);
|
registerBeanPostProcessors(beanFactory, priorityOrderedPostProcessors);
|
||||||
|
|
||||||
// Next, register the BeanPostProcessors that implement Ordered.
|
// Next, register the BeanPostProcessors that implement Ordered.
|
||||||
|
|
@ -585,7 +584,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
||||||
for (String postProcessorName : orderedPostProcessorNames) {
|
for (String postProcessorName : orderedPostProcessorNames) {
|
||||||
orderedPostProcessors.add(getBean(postProcessorName, BeanPostProcessor.class));
|
orderedPostProcessors.add(getBean(postProcessorName, BeanPostProcessor.class));
|
||||||
}
|
}
|
||||||
Collections.sort(orderedPostProcessors, new OrderComparator());
|
OrderComparator.sort(orderedPostProcessors);
|
||||||
registerBeanPostProcessors(beanFactory, orderedPostProcessors);
|
registerBeanPostProcessors(beanFactory, orderedPostProcessors);
|
||||||
|
|
||||||
// Finally, register all other BeanPostProcessors.
|
// Finally, register all other BeanPostProcessors.
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2009 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.
|
||||||
|
|
@ -18,7 +18,6 @@ package org.springframework.transaction.support;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -77,8 +76,6 @@ public abstract class TransactionSynchronizationManager {
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(TransactionSynchronizationManager.class);
|
private static final Log logger = LogFactory.getLog(TransactionSynchronizationManager.class);
|
||||||
|
|
||||||
private static final Comparator<Object> synchronizationComparator = new OrderComparator();
|
|
||||||
|
|
||||||
private static final ThreadLocal<Map<Object, Object>> resources =
|
private static final ThreadLocal<Map<Object, Object>> resources =
|
||||||
new NamedThreadLocal<Map<Object, Object>>("Transactional resources");
|
new NamedThreadLocal<Map<Object, Object>>("Transactional resources");
|
||||||
|
|
||||||
|
|
@ -295,7 +292,7 @@ public abstract class TransactionSynchronizationManager {
|
||||||
}
|
}
|
||||||
List<TransactionSynchronization> synchs = synchronizations.get();
|
List<TransactionSynchronization> synchs = synchronizations.get();
|
||||||
// Sort lazily here, not in registerSynchronization.
|
// Sort lazily here, not in registerSynchronization.
|
||||||
Collections.sort(synchs, synchronizationComparator);
|
OrderComparator.sort(synchs);
|
||||||
// Return unmodifiable snapshot, to avoid ConcurrentModificationExceptions
|
// Return unmodifiable snapshot, to avoid ConcurrentModificationExceptions
|
||||||
// while iterating and invoking synchronization callbacks that in turn
|
// while iterating and invoking synchronization callbacks that in turn
|
||||||
// might register further synchronizations.
|
// might register further synchronizations.
|
||||||
|
|
|
||||||
|
|
@ -378,7 +378,7 @@ public class DispatcherPortlet extends FrameworkPortlet {
|
||||||
if (!matchingBeans.isEmpty()) {
|
if (!matchingBeans.isEmpty()) {
|
||||||
this.handlerMappings = new ArrayList<HandlerMapping>(matchingBeans.values());
|
this.handlerMappings = new ArrayList<HandlerMapping>(matchingBeans.values());
|
||||||
// We keep HandlerMappings in sorted order.
|
// We keep HandlerMappings in sorted order.
|
||||||
Collections.sort(this.handlerMappings, new OrderComparator());
|
OrderComparator.sort(this.handlerMappings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -416,7 +416,7 @@ public class DispatcherPortlet extends FrameworkPortlet {
|
||||||
if (!matchingBeans.isEmpty()) {
|
if (!matchingBeans.isEmpty()) {
|
||||||
this.handlerAdapters = new ArrayList<HandlerAdapter>(matchingBeans.values());
|
this.handlerAdapters = new ArrayList<HandlerAdapter>(matchingBeans.values());
|
||||||
// We keep HandlerAdapters in sorted order.
|
// We keep HandlerAdapters in sorted order.
|
||||||
Collections.sort(this.handlerAdapters, new OrderComparator());
|
OrderComparator.sort(this.handlerAdapters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -454,7 +454,7 @@ public class DispatcherPortlet extends FrameworkPortlet {
|
||||||
if (!matchingBeans.isEmpty()) {
|
if (!matchingBeans.isEmpty()) {
|
||||||
this.handlerExceptionResolvers = new ArrayList<HandlerExceptionResolver>(matchingBeans.values());
|
this.handlerExceptionResolvers = new ArrayList<HandlerExceptionResolver>(matchingBeans.values());
|
||||||
// We keep HandlerExceptionResolvers in sorted order.
|
// We keep HandlerExceptionResolvers in sorted order.
|
||||||
Collections.sort(this.handlerExceptionResolvers, new OrderComparator());
|
OrderComparator.sort(this.handlerExceptionResolvers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -493,7 +493,7 @@ public class DispatcherPortlet extends FrameworkPortlet {
|
||||||
if (!matchingBeans.isEmpty()) {
|
if (!matchingBeans.isEmpty()) {
|
||||||
this.viewResolvers = new ArrayList<ViewResolver>(matchingBeans.values());
|
this.viewResolvers = new ArrayList<ViewResolver>(matchingBeans.values());
|
||||||
// We keep ViewResolvers in sorted order.
|
// We keep ViewResolvers in sorted order.
|
||||||
Collections.sort(this.viewResolvers, new OrderComparator());
|
OrderComparator.sort(this.viewResolvers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
|
|
@ -471,7 +471,7 @@ public class DispatcherServlet extends FrameworkServlet {
|
||||||
if (!matchingBeans.isEmpty()) {
|
if (!matchingBeans.isEmpty()) {
|
||||||
this.handlerMappings = new ArrayList<HandlerMapping>(matchingBeans.values());
|
this.handlerMappings = new ArrayList<HandlerMapping>(matchingBeans.values());
|
||||||
// We keep HandlerMappings in sorted order.
|
// We keep HandlerMappings in sorted order.
|
||||||
Collections.sort(this.handlerMappings, new OrderComparator());
|
OrderComparator.sort(this.handlerMappings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -509,7 +509,7 @@ public class DispatcherServlet extends FrameworkServlet {
|
||||||
if (!matchingBeans.isEmpty()) {
|
if (!matchingBeans.isEmpty()) {
|
||||||
this.handlerAdapters = new ArrayList<HandlerAdapter>(matchingBeans.values());
|
this.handlerAdapters = new ArrayList<HandlerAdapter>(matchingBeans.values());
|
||||||
// We keep HandlerAdapters in sorted order.
|
// We keep HandlerAdapters in sorted order.
|
||||||
Collections.sort(this.handlerAdapters, new OrderComparator());
|
OrderComparator.sort(this.handlerAdapters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -547,7 +547,7 @@ public class DispatcherServlet extends FrameworkServlet {
|
||||||
if (!matchingBeans.isEmpty()) {
|
if (!matchingBeans.isEmpty()) {
|
||||||
this.handlerExceptionResolvers = new ArrayList<HandlerExceptionResolver>(matchingBeans.values());
|
this.handlerExceptionResolvers = new ArrayList<HandlerExceptionResolver>(matchingBeans.values());
|
||||||
// We keep HandlerExceptionResolvers in sorted order.
|
// We keep HandlerExceptionResolvers in sorted order.
|
||||||
Collections.sort(this.handlerExceptionResolvers, new OrderComparator());
|
OrderComparator.sort(this.handlerExceptionResolvers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -609,7 +609,7 @@ public class DispatcherServlet extends FrameworkServlet {
|
||||||
if (!matchingBeans.isEmpty()) {
|
if (!matchingBeans.isEmpty()) {
|
||||||
this.viewResolvers = new ArrayList<ViewResolver>(matchingBeans.values());
|
this.viewResolvers = new ArrayList<ViewResolver>(matchingBeans.values());
|
||||||
// We keep ViewResolvers in sorted order.
|
// We keep ViewResolvers in sorted order.
|
||||||
Collections.sort(this.viewResolvers, new OrderComparator());
|
OrderComparator.sort(this.viewResolvers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport
|
||||||
logger.warn("Did not find any ViewResolvers to delegate to; please configure them using the " +
|
logger.warn("Did not find any ViewResolvers to delegate to; please configure them using the " +
|
||||||
"'viewResolvers' property on the ContentNegotiatingViewResolver");
|
"'viewResolvers' property on the ContentNegotiatingViewResolver");
|
||||||
}
|
}
|
||||||
Collections.sort(this.viewResolvers, new OrderComparator());
|
OrderComparator.sort(this.viewResolvers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue