From ab9e843cfaf1972622960dc69328eed223ba2440 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Tue, 15 Aug 2017 13:36:19 -0400 Subject: [PATCH] Fix Checkstyle violations * Add `validateOnlyOverlapping = false` for `RequireThis` Checkstyle rule * Add `this.` to caught places * Use `CustomizableThreadFactory` instead of raw interface in the `UnicastSendingMessageHandler` --- .../AbstractAmqpOutboundEndpoint.java | 4 ++-- .../PublisherAnnotationBeanPostProcessor.java | 5 +---- .../MessagingAnnotationPostProcessor.java | 4 ++-- .../RoundRobinLoadBalancingStrategy.java | 18 ++++++++++------- .../file/splitter/FileSplitter.java | 2 +- .../ip/udp/UnicastSendingMessageHandler.java | 20 +++++-------------- src/checkstyle/checkstyle.xml | 1 + 7 files changed, 23 insertions(+), 31 deletions(-) diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java index d398a11caf..965e048c92 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java @@ -333,14 +333,14 @@ public abstract class AbstractAmqpOutboundEndpoint extends AbstractReplyProducin protected MessageChannel getConfirmAckChannel() { if (this.confirmAckChannel == null && this.confirmAckChannelName != null) { - this.confirmAckChannel = getChannelResolver().resolveDestination(confirmAckChannelName); + this.confirmAckChannel = getChannelResolver().resolveDestination(this.confirmAckChannelName); } return this.confirmAckChannel; } protected MessageChannel getConfirmNackChannel() { if (this.confirmNackChannel == null && this.confirmNackChannelName != null) { - this.confirmNackChannel = getChannelResolver().resolveDestination(confirmNackChannelName); + this.confirmNackChannel = getChannelResolver().resolveDestination(this.confirmNackChannelName); } return this.confirmNackChannel; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aop/PublisherAnnotationBeanPostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/aop/PublisherAnnotationBeanPostProcessor.java index bb1bc30f5a..08abfd47f7 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aop/PublisherAnnotationBeanPostProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aop/PublisherAnnotationBeanPostProcessor.java @@ -106,9 +106,6 @@ public class PublisherAnnotationBeanPostProcessor extends ProxyConfig @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { Class targetClass = AopUtils.getTargetClass(bean); - if (targetClass == null) { - return bean; - } // the set will hold records of prior class scans and will contain the bean classes that can not // be assigned to the Advisor interface and therefore can be short circuited @@ -131,7 +128,7 @@ public class PublisherAnnotationBeanPostProcessor extends ProxyConfig } else { // cannot apply advisor - nonApplicableCache.add(targetClass); + this.nonApplicableCache.add(targetClass); return bean; } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/MessagingAnnotationPostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/MessagingAnnotationPostProcessor.java index 755f30a868..086b42fba5 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/MessagingAnnotationPostProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/MessagingAnnotationPostProcessor.java @@ -163,7 +163,7 @@ public class MessagingAnnotationPostProcessor implements BeanPostProcessor, Bean ReflectionUtils.doWithMethods(beanClass, method -> { Map, List> annotationChains = new HashMap<>(); for (Class annotationType : - MessagingAnnotationPostProcessor.this.postProcessors.keySet()) { + this.postProcessors.keySet()) { if (AnnotatedElementUtils.isAnnotated(method, annotationType.getName())) { List annotationChain = getAnnotationChain(method, annotationType); if (annotationChain.size() > 0) { @@ -179,7 +179,7 @@ public class MessagingAnnotationPostProcessor implements BeanPostProcessor, Bean } if (annotationChains.size() == 0) { - noAnnotationsCache.add(beanClass); + this.noAnnotationsCache.add(beanClass); } }, ReflectionUtils.USER_DECLARED_METHODS); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/RoundRobinLoadBalancingStrategy.java b/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/RoundRobinLoadBalancingStrategy.java index 17bf4fde07..3678e7f23c 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/RoundRobinLoadBalancingStrategy.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/RoundRobinLoadBalancingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,6 +31,8 @@ import org.springframework.messaging.MessageHandler; * @author Iwein Fuld * @author Mark Fisher * @author Oleg Zhurakousky + * @author Artem Bilan + * * @since 1.0.3 */ public class RoundRobinLoadBalancingStrategy implements LoadBalancingStrategy { @@ -43,7 +45,7 @@ public class RoundRobinLoadBalancingStrategy implements LoadBalancingStrategy { * iteration, so it guarantees all handlers are returned once on subsequent * next() invocations. */ - public final Iterator getHandlerIterator(final Message message, final Collection handlers) { + public final Iterator getHandlerIterator(Message message, Collection handlers) { int size = handlers.size(); if (size < 2) { this.getNextHandlerStartIndex(size); @@ -54,28 +56,29 @@ public class RoundRobinLoadBalancingStrategy implements LoadBalancingStrategy { } private Iterator buildHandlerIterator(int size, final MessageHandler[] handlers) { - int nextHandlerStartIndex = getNextHandlerStartIndex(size); - final MessageHandler[] reorderedHandlers = new MessageHandler[size]; + MessageHandler[] reorderedHandlers = new MessageHandler[size]; System.arraycopy(handlers, nextHandlerStartIndex, reorderedHandlers, 0, size - nextHandlerStartIndex); - System.arraycopy(handlers, 0, reorderedHandlers, size - nextHandlerStartIndex, 0 + nextHandlerStartIndex); + System.arraycopy(handlers, 0, reorderedHandlers, size - nextHandlerStartIndex, nextHandlerStartIndex); return new Iterator() { + int currentIndex = 0; public boolean hasNext() { - return currentIndex < reorderedHandlers.length; + return this.currentIndex < reorderedHandlers.length; } public MessageHandler next() { - return reorderedHandlers[currentIndex++]; + return reorderedHandlers[this.currentIndex++]; } public void remove() { throw new UnsupportedOperationException("Remove is not supported by this Iterator"); } + }; } @@ -93,4 +96,5 @@ public class RoundRobinLoadBalancingStrategy implements LoadBalancingStrategy { return size; } } + } diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/splitter/FileSplitter.java b/spring-integration-file/src/main/java/org/springframework/integration/file/splitter/FileSplitter.java index 8b57138d75..bf23b85b78 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/splitter/FileSplitter.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/splitter/FileSplitter.java @@ -248,7 +248,7 @@ public class FileSplitter extends AbstractMessageSplitter { boolean markers = FileSplitter.this.markers; - boolean sof = markers; + boolean sof = this.markers; boolean eof; diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/UnicastSendingMessageHandler.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/UnicastSendingMessageHandler.java index 5479048d3c..8abf33c6b8 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/UnicastSendingMessageHandler.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/UnicastSendingMessageHandler.java @@ -31,9 +31,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; import org.springframework.expression.EvaluationContext; import org.springframework.expression.Expression; @@ -43,6 +41,7 @@ import org.springframework.messaging.Message; import org.springframework.messaging.MessageDeliveryException; import org.springframework.messaging.MessageHandlingException; import org.springframework.messaging.MessagingException; +import org.springframework.scheduling.concurrent.CustomizableThreadFactory; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -57,6 +56,7 @@ import org.springframework.util.StringUtils; * @author Gary Russell * @author Marcin Pilaczynski * @author Artem Bilan + * * @since 2.0 */ public class UnicastSendingMessageHandler extends @@ -231,21 +231,11 @@ public class UnicastSendingMessageHandler extends public void doStart() { if (this.acknowledge) { if (this.taskExecutor == null) { - Executor executor = Executors - .newSingleThreadExecutor(new ThreadFactory() { - private final AtomicInteger n = new AtomicInteger(); + CustomizableThreadFactory threadFactory = new CustomizableThreadFactory("UDP-Ack-Handler-"); + threadFactory.setDaemon(true); - @Override - public Thread newThread(Runnable runner) { - Thread thread = new Thread(runner); - thread.setName("UDP-Ack-Handler-" + n.getAndIncrement()); - thread.setDaemon(true); - return thread; - } - - }); - this.taskExecutor = executor; + this.taskExecutor = Executors.newSingleThreadExecutor(threadFactory); } startAckThread(); } diff --git a/src/checkstyle/checkstyle.xml b/src/checkstyle/checkstyle.xml index ce994a091c..25c51db30a 100644 --- a/src/checkstyle/checkstyle.xml +++ b/src/checkstyle/checkstyle.xml @@ -68,6 +68,7 @@ +