From 473ed1a6723a10689c6d550fcd5a7b9b449b3da1 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 4 Oct 2014 01:01:53 +0200 Subject: [PATCH] Polishing --- .../mail/javamail/InternetAddressEditor.java | 3 +- .../mail/javamail/MimeMailMessage.java | 3 +- .../broker/AbstractBrokerMessageHandler.java | 41 +++++++++---------- .../messaging/support/ChannelInterceptor.java | 6 +-- .../support/InterceptableChannel.java | 3 +- .../support/ChannelInterceptorTests.java | 13 +++--- 6 files changed, 33 insertions(+), 36 deletions(-) diff --git a/spring-context-support/src/main/java/org/springframework/mail/javamail/InternetAddressEditor.java b/spring-context-support/src/main/java/org/springframework/mail/javamail/InternetAddressEditor.java index 2cf0b89671..1984fa8693 100644 --- a/spring-context-support/src/main/java/org/springframework/mail/javamail/InternetAddressEditor.java +++ b/spring-context-support/src/main/java/org/springframework/mail/javamail/InternetAddressEditor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 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. @@ -17,7 +17,6 @@ package org.springframework.mail.javamail; import java.beans.PropertyEditorSupport; - import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; diff --git a/spring-context-support/src/main/java/org/springframework/mail/javamail/MimeMailMessage.java b/spring-context-support/src/main/java/org/springframework/mail/javamail/MimeMailMessage.java index 6a483168eb..9b0b01dc73 100644 --- a/spring-context-support/src/main/java/org/springframework/mail/javamail/MimeMailMessage.java +++ b/spring-context-support/src/main/java/org/springframework/mail/javamail/MimeMailMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 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. @@ -17,7 +17,6 @@ package org.springframework.mail.javamail; import java.util.Date; - import javax.mail.MessagingException; import javax.mail.internet.MimeMessage; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractBrokerMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractBrokerMessageHandler.java index f031462215..1d914cb007 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractBrokerMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractBrokerMessageHandler.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -38,7 +38,6 @@ import org.springframework.messaging.support.InterceptableChannel; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; - /** * Abstract base class for a {@link MessageHandler} that broker messages to * registered subscribers. @@ -51,7 +50,6 @@ public abstract class AbstractBrokerMessageHandler protected final Log logger = LogFactory.getLog(getClass()); - private final SubscribableChannel clientInboundChannel; private final MessageChannel clientOutboundChannel; @@ -74,7 +72,7 @@ public abstract class AbstractBrokerMessageHandler private final Object lifecycleMonitor = new Object(); - private ChannelInterceptor unsentDisconnectInterceptor = new UnsentDisconnectChannelInterceptor(); + private final ChannelInterceptor unsentDisconnectInterceptor = new UnsentDisconnectChannelInterceptor(); /** @@ -151,18 +149,6 @@ public abstract class AbstractBrokerMessageHandler return Integer.MAX_VALUE; } - /** - * Check whether this message handler is currently running. - *

Note that even when this message handler is running the - * {@link #isBrokerAvailable()} flag may still independently alternate between - * being on and off depending on the concrete sub-class implementation. - */ - @Override - public final boolean isRunning() { - synchronized (this.lifecycleMonitor) { - return this.running; - } - } @Override public void start() { @@ -177,9 +163,7 @@ public abstract class AbstractBrokerMessageHandler } startInternal(); this.running = true; - if (logger.isInfoEnabled()) { - logger.info("Started."); - } + logger.info("Started."); } } @@ -199,9 +183,7 @@ public abstract class AbstractBrokerMessageHandler ((InterceptableChannel) this.clientInboundChannel).removeInterceptor(this.unsentDisconnectInterceptor); } this.running = false; - if (logger.isDebugEnabled()) { - logger.info("Stopped."); - } + logger.info("Stopped."); } } @@ -216,6 +198,19 @@ public abstract class AbstractBrokerMessageHandler } } + /** + * Check whether this message handler is currently running. + *

Note that even when this message handler is running the + * {@link #isBrokerAvailable()} flag may still independently alternate between + * being on and off depending on the concrete sub-class implementation. + */ + @Override + public final boolean isRunning() { + synchronized (this.lifecycleMonitor) { + return this.running; + } + } + /** * Whether the message broker is currently available and able to process messages. *

Note that this is in addition to the {@link #isRunning()} flag, which @@ -245,6 +240,7 @@ public abstract class AbstractBrokerMessageHandler protected abstract void handleMessageInternal(Message message); + protected boolean checkDestinationPrefix(String destination) { if ((destination == null) || CollectionUtils.isEmpty(this.destinationPrefixes)) { return true; @@ -294,4 +290,5 @@ public abstract class AbstractBrokerMessageHandler } } } + } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/ChannelInterceptor.java b/spring-messaging/src/main/java/org/springframework/messaging/support/ChannelInterceptor.java index 0f2f2f98c8..fb28d1bbad 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/ChannelInterceptor.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/ChannelInterceptor.java @@ -47,8 +47,8 @@ public interface ChannelInterceptor { /** * Invoked after the completion of a send regardless of any exception that * have been raised thus allowing for proper resource cleanup. - *

Note that this will be invoked only if preSend successfully completed - * and returned a Message, i.e. it did not return {@code null}. + *

Note that this will be invoked only if {@link #preSend} successfully + * completed and returned a Message, i.e. it did not return {@code null}. * @since 4.1 */ void afterSendCompletion(Message message, MessageChannel channel, boolean sent, Exception ex); @@ -70,7 +70,7 @@ public interface ChannelInterceptor { /** * Invoked after the completion of a receive regardless of any exception that * have been raised thus allowing for proper resource cleanup. - *

Note that this will be invoked only if preReceive successfully + *

Note that this will be invoked only if {@link #preReceive} successfully * completed and returned {@code true}. * @since 4.1 */ diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/InterceptableChannel.java b/spring-messaging/src/main/java/org/springframework/messaging/support/InterceptableChannel.java index e8f361d049..389d33d168 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/InterceptableChannel.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/InterceptableChannel.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.messaging.support; import java.util.List; diff --git a/spring-messaging/src/test/java/org/springframework/messaging/support/ChannelInterceptorTests.java b/spring-messaging/src/test/java/org/springframework/messaging/support/ChannelInterceptorTests.java index d01c689213..56ba910b3d 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/support/ChannelInterceptorTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/support/ChannelInterceptorTests.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -33,6 +33,7 @@ import static org.mockito.Mockito.mock; /** * Test fixture for the use of {@link ChannelInterceptor}s. + * * @author Rossen Stoyanchev */ public class ChannelInterceptorTests { @@ -184,8 +185,7 @@ public class ChannelInterceptorTests { private static class TestMessageHandler implements MessageHandler { - private List> messages = new ArrayList>(); - + private final List> messages = new ArrayList>(); public List> getMessages() { return this.messages; @@ -193,17 +193,17 @@ public class ChannelInterceptorTests { @Override public void handleMessage(Message message) throws MessagingException { - this.getMessages().add(message); + this.messages.add(message); } } + private abstract static class AbstractTestInterceptor extends ChannelInterceptorAdapter { private AtomicInteger counter = new AtomicInteger(); private volatile boolean afterCompletionInvoked; - public AtomicInteger getCounter() { return this.counter; } @@ -225,13 +225,13 @@ public class ChannelInterceptorTests { } } + private static class PreSendInterceptor extends AbstractTestInterceptor { private Message messageToReturn; private RuntimeException exceptionToRaise; - public void setMessageToReturn(Message messageToReturn) { this.messageToReturn = messageToReturn; } @@ -250,6 +250,7 @@ public class ChannelInterceptorTests { } } + private static class NullReturningPreSendInterceptor extends AbstractTestInterceptor { @Override