From a637213246fed065ab41e93b0d51541f54a1a8c9 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 2 Jul 2016 15:15:09 +0200 Subject: [PATCH] Aligned default Map capacity --- .../AbstractMethodMessageHandler.java | 110 +++++++++--------- 1 file changed, 58 insertions(+), 52 deletions(-) diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java index b28641a2a8..004d25ed11 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java @@ -83,17 +83,25 @@ public abstract class AbstractMethodMessageHandler protected final Log logger = LogFactory.getLog(getClass()); - private final List customArgumentResolvers = new ArrayList(4); + private Collection destinationPrefixes = new ArrayList(); - private final List customReturnValueHandlers = new ArrayList(4); + private final List customArgumentResolvers = + new ArrayList(4); - private final HandlerMethodArgumentResolverComposite argumentResolvers = new HandlerMethodArgumentResolverComposite(); + private final List customReturnValueHandlers = + new ArrayList(4); - private final HandlerMethodReturnValueHandlerComposite returnValueHandlers =new HandlerMethodReturnValueHandlerComposite(); + private final HandlerMethodArgumentResolverComposite argumentResolvers = + new HandlerMethodArgumentResolverComposite(); - private final Map handlerMethods = new LinkedHashMap(); + private final HandlerMethodReturnValueHandlerComposite returnValueHandlers = + new HandlerMethodReturnValueHandlerComposite(); - private final MultiValueMap destinationLookup = new LinkedMultiValueMap(); + private ApplicationContext applicationContext; + + private final Map handlerMethods = new LinkedHashMap(64); + + private final MultiValueMap destinationLookup = new LinkedMultiValueMap(64); private final Map, AbstractExceptionHandlerMethodResolver> exceptionHandlerCache = new ConcurrentHashMap, AbstractExceptionHandlerMethodResolver>(64); @@ -101,16 +109,6 @@ public abstract class AbstractMethodMessageHandler private final Map exceptionHandlerAdviceCache = new LinkedHashMap(64); - private Collection destinationPrefixes = new ArrayList(); - - private ApplicationContext applicationContext; - - /** - * Return the configured destination prefixes. - */ - public Collection getDestinationPrefixes() { - return this.destinationPrefixes; - } /** * When this property is configured only messages to destinations matching @@ -130,6 +128,24 @@ public abstract class AbstractMethodMessageHandler } } + /** + * Return the configured destination prefixes, if any. + */ + public Collection getDestinationPrefixes() { + return this.destinationPrefixes; + } + + /** + * Sets the list of custom {@code HandlerMethodArgumentResolver}s that will be used + * after resolvers for supported argument type. + */ + public void setCustomArgumentResolvers(List customArgumentResolvers) { + this.customArgumentResolvers.clear(); + if (customArgumentResolvers != null) { + this.customArgumentResolvers.addAll(customArgumentResolvers); + } + } + /** * Return the configured custom argument resolvers, if any. */ @@ -138,14 +154,13 @@ public abstract class AbstractMethodMessageHandler } /** - * Sets the list of custom {@code HandlerMethodArgumentResolver}s that will be used - * after resolvers for supported argument type. - * @param customArgumentResolvers the list of resolvers; never {@code null}. + * Set the list of custom {@code HandlerMethodReturnValueHandler}s that will be used + * after return value handlers for known types. */ - public void setCustomArgumentResolvers(List customArgumentResolvers) { - this.customArgumentResolvers.clear(); - if (customArgumentResolvers != null) { - this.customArgumentResolvers.addAll(customArgumentResolvers); + public void setCustomReturnValueHandlers(List customReturnValueHandlers) { + this.customReturnValueHandlers.clear(); + if (customReturnValueHandlers != null) { + this.customReturnValueHandlers.addAll(customReturnValueHandlers); } } @@ -157,27 +172,8 @@ public abstract class AbstractMethodMessageHandler } /** - * Set the list of custom {@code HandlerMethodReturnValueHandler}s that will be used - * after return value handlers for known types. - * @param customReturnValueHandlers the list of custom return value handlers, never {@code null}. - */ - public void setCustomReturnValueHandlers(List customReturnValueHandlers) { - this.customReturnValueHandlers.clear(); - if (customReturnValueHandlers != null) { - this.customReturnValueHandlers.addAll(customReturnValueHandlers); - } - } - - /** - * Return the configured argument resolvers, if any. - */ - public List getArgumentResolvers() { - return this.argumentResolvers.getResolvers(); - } - - /** - * Configure the complete list of supported argument types effectively overriding - * the ones configured by default. This is an advanced option. For most use cases + * Configure the complete list of supported argument types, effectively overriding + * the ones configured by default. This is an advanced option; for most use cases * it should be sufficient to use {@link #setCustomArgumentResolvers}. */ public void setArgumentResolvers(List argumentResolvers) { @@ -189,15 +185,15 @@ public abstract class AbstractMethodMessageHandler } /** - * Return the configured return value handlers, if any. + * Return the complete list of argument resolvers. */ - public List getReturnValueHandlers() { - return this.returnValueHandlers.getReturnValueHandlers(); + public List getArgumentResolvers() { + return this.argumentResolvers.getResolvers(); } /** - * Configure the complete list of supported return value types effectively overriding - * the ones configured by default. This is an advanced option. For most use cases + * Configure the complete list of supported return value types, effectively overriding + * the ones configured by default. This is an advanced option; for most use cases * it should be sufficient to use {@link #setCustomReturnValueHandlers}. */ public void setReturnValueHandlers(List returnValueHandlers) { @@ -208,8 +204,11 @@ public abstract class AbstractMethodMessageHandler this.returnValueHandlers.addHandlers(returnValueHandlers); } - public ApplicationContext getApplicationContext() { - return this.applicationContext; + /** + * Return the complete list of return value handlers. + */ + public List getReturnValueHandlers() { + return this.returnValueHandlers.getReturnValueHandlers(); } @Override @@ -217,6 +216,11 @@ public abstract class AbstractMethodMessageHandler this.applicationContext = applicationContext; } + public ApplicationContext getApplicationContext() { + return this.applicationContext; + } + + @Override public void afterPropertiesSet() { if (this.argumentResolvers.getResolvers().isEmpty()) { @@ -359,7 +363,9 @@ public abstract class AbstractMethodMessageHandler * (e.g. to support "global" {@code @MessageExceptionHandler}). * @since 4.2 */ - protected void registerExceptionHandlerAdvice(MessagingAdviceBean bean, AbstractExceptionHandlerMethodResolver resolver) { + protected void registerExceptionHandlerAdvice( + MessagingAdviceBean bean, AbstractExceptionHandlerMethodResolver resolver) { + this.exceptionHandlerAdviceCache.put(bean, resolver); }