ChannelInterceptor default methods + deprecate adapter
This commit is contained in:
@@ -34,7 +34,6 @@ import org.springframework.messaging.SubscribableChannel;
|
||||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
||||
import org.springframework.messaging.simp.SimpMessageType;
|
||||
import org.springframework.messaging.support.ChannelInterceptor;
|
||||
import org.springframework.messaging.support.ChannelInterceptorAdapter;
|
||||
import org.springframework.messaging.support.InterceptableChannel;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -274,7 +273,7 @@ public abstract class AbstractBrokerMessageHandler
|
||||
/**
|
||||
* Detect unsent DISCONNECT messages and process them anyway.
|
||||
*/
|
||||
private class UnsentDisconnectChannelInterceptor extends ChannelInterceptorAdapter {
|
||||
private class UnsentDisconnectChannelInterceptor implements ChannelInterceptor {
|
||||
|
||||
@Override
|
||||
public void afterSendCompletion(
|
||||
|
||||
@@ -38,13 +38,16 @@ public interface ChannelInterceptor {
|
||||
* send invocation will not occur.
|
||||
*/
|
||||
@Nullable
|
||||
Message<?> preSend(Message<?> message, MessageChannel channel);
|
||||
default Message<?> preSend(Message<?> message, MessageChannel channel) {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked immediately after the send invocation. The boolean
|
||||
* value argument represents the return value of that invocation.
|
||||
*/
|
||||
void postSend(Message<?> message, MessageChannel channel, boolean sent);
|
||||
default void postSend(Message<?> message, MessageChannel channel, boolean sent) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked after the completion of a send regardless of any exception that
|
||||
@@ -53,14 +56,18 @@ public interface ChannelInterceptor {
|
||||
* completed and returned a Message, i.e. it did not return {@code null}.
|
||||
* @since 4.1
|
||||
*/
|
||||
void afterSendCompletion(Message<?> message, MessageChannel channel, boolean sent, @Nullable Exception ex);
|
||||
default void afterSendCompletion(Message<?> message, MessageChannel channel, boolean sent,
|
||||
@Nullable Exception ex) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked as soon as receive is called and before a Message is
|
||||
* actually retrieved. If the return value is 'false', then no
|
||||
* Message will be retrieved. This only applies to PollableChannels.
|
||||
*/
|
||||
boolean preReceive(MessageChannel channel);
|
||||
default boolean preReceive(MessageChannel channel) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked immediately after a Message has been retrieved but before
|
||||
@@ -69,7 +76,9 @@ public interface ChannelInterceptor {
|
||||
* This only applies to PollableChannels.
|
||||
*/
|
||||
@Nullable
|
||||
Message<?> postReceive(Message<?> message, MessageChannel channel);
|
||||
default Message<?> postReceive(Message<?> message, MessageChannel channel) {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked after the completion of a receive regardless of any exception that
|
||||
@@ -78,6 +87,8 @@ public interface ChannelInterceptor {
|
||||
* completed and returned {@code true}.
|
||||
* @since 4.1
|
||||
*/
|
||||
void afterReceiveCompletion(@Nullable Message<?> message, MessageChannel channel, @Nullable Exception ex);
|
||||
default void afterReceiveCompletion(@Nullable Message<?> message, MessageChannel channel,
|
||||
@Nullable Exception ex) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -27,7 +27,11 @@ import org.springframework.messaging.MessageChannel;
|
||||
* @author Mark Fisher
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
* @deprecated as of 5.0.7 {@link ChannelInterceptor} has default methods (made
|
||||
* possible by a Java 8 baseline) and can be implemented directly without the
|
||||
* need for this no-op adapter
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class ChannelInterceptorAdapter implements ChannelInterceptor {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -30,7 +30,7 @@ import org.springframework.messaging.MessageChannel;
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.1.2
|
||||
*/
|
||||
public class ImmutableMessageChannelInterceptor extends ChannelInterceptorAdapter {
|
||||
public class ImmutableMessageChannelInterceptor implements ChannelInterceptor {
|
||||
|
||||
@Override
|
||||
public Message<?> preSend(Message<?> message, MessageChannel channel) {
|
||||
|
||||
@@ -17,10 +17,8 @@
|
||||
package org.springframework.messaging.simp.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@@ -64,7 +62,6 @@ import org.springframework.messaging.simp.user.UserDestinationMessageHandler;
|
||||
import org.springframework.messaging.simp.user.UserRegistryMessageHandler;
|
||||
import org.springframework.messaging.support.AbstractSubscribableChannel;
|
||||
import org.springframework.messaging.support.ChannelInterceptor;
|
||||
import org.springframework.messaging.support.ChannelInterceptorAdapter;
|
||||
import org.springframework.messaging.support.ExecutorSubscribableChannel;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
@@ -607,7 +604,7 @@ public class MessageBrokerConfigurationTests {
|
||||
@Configuration
|
||||
static class CustomConfig extends BaseTestMessageBrokerConfig {
|
||||
|
||||
private ChannelInterceptor interceptor = new ChannelInterceptorAdapter() {};
|
||||
private ChannelInterceptor interceptor = new ChannelInterceptor() {};
|
||||
|
||||
@Override
|
||||
protected void configureClientInboundChannel(ChannelRegistration registration) {
|
||||
|
||||
@@ -88,7 +88,7 @@ public class ChannelInterceptorTests {
|
||||
public void postSendInterceptorMessageWasSent() {
|
||||
final AtomicBoolean preSendInvoked = new AtomicBoolean(false);
|
||||
final AtomicBoolean completionInvoked = new AtomicBoolean(false);
|
||||
this.channel.addInterceptor(new ChannelInterceptorAdapter() {
|
||||
this.channel.addInterceptor(new ChannelInterceptor() {
|
||||
@Override
|
||||
public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
|
||||
assertInput(message, channel, sent);
|
||||
@@ -121,7 +121,7 @@ public class ChannelInterceptorTests {
|
||||
};
|
||||
final AtomicBoolean preSendInvoked = new AtomicBoolean(false);
|
||||
final AtomicBoolean completionInvoked = new AtomicBoolean(false);
|
||||
testChannel.addInterceptor(new ChannelInterceptorAdapter() {
|
||||
testChannel.addInterceptor(new ChannelInterceptor() {
|
||||
@Override
|
||||
public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
|
||||
assertInput(message, channel, sent);
|
||||
@@ -199,7 +199,7 @@ public class ChannelInterceptorTests {
|
||||
}
|
||||
|
||||
|
||||
private abstract static class AbstractTestInterceptor extends ChannelInterceptorAdapter {
|
||||
private abstract static class AbstractTestInterceptor implements ChannelInterceptor {
|
||||
|
||||
private AtomicInteger counter = new AtomicInteger();
|
||||
|
||||
|
||||
@@ -186,8 +186,7 @@ public class ExecutorSubscribableChannelTests {
|
||||
}
|
||||
|
||||
|
||||
private abstract static class AbstractTestInterceptor extends ChannelInterceptorAdapter
|
||||
implements ExecutorChannelInterceptor {
|
||||
private abstract static class AbstractTestInterceptor implements ChannelInterceptor, ExecutorChannelInterceptor {
|
||||
|
||||
private AtomicInteger counter = new AtomicInteger();
|
||||
|
||||
@@ -209,7 +208,9 @@ public class ExecutorSubscribableChannelTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterMessageHandled(Message<?> message, MessageChannel channel, MessageHandler handler, Exception ex) {
|
||||
public void afterMessageHandled(Message<?> message, MessageChannel channel, MessageHandler handler,
|
||||
Exception ex) {
|
||||
|
||||
this.afterHandledInvoked = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user