Skip to content

Commit f90d91f

Browse files
committed
GH-2749: Deprecate ChannelInterceptorAware
Fixes #2749 The `org.springframework.messaging.support.InterceptableChannel` provides exact functionality as `ChannelInterceptorAware` * Make `ChannelInterceptorAware extends InterceptableChannel` * Suppress deprecation warning whenever we need to keep backward compatibility * Fix all other places to deal with `InterceptableChannel` already
1 parent d38db25 commit f90d91f

File tree

19 files changed

+134
-144
lines changed

19 files changed

+134
-144
lines changed

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/PollableAmqpChannel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -178,7 +178,7 @@ public Message<?> receive(long timeout) {
178178

179179

180180
protected Message<?> doReceive(Long timeout) {
181-
ChannelInterceptorList interceptorList = getInterceptors();
181+
ChannelInterceptorList interceptorList = getIChannelInterceptorList();
182182
Deque<ChannelInterceptor> interceptorStack = null;
183183
boolean counted = false;
184184
boolean countsEnabled = isCountsEnabled();

spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
* @author Artem Bilan
6767
*/
6868
@IntegrationManagedResource
69+
@SuppressWarnings("deprecation")
6970
public abstract class AbstractMessageChannel extends IntegrationObjectSupport
7071
implements MessageChannel, TrackableComponent, ChannelInterceptorAware, MessageChannelMetrics,
7172
ConfigurableMetricsAware<AbstractMessageChannelMetrics> {
@@ -243,7 +244,7 @@ public void setMessageConverter(MessageConverter messageConverter) {
243244
* Return a read-only list of the configured interceptors.
244245
*/
245246
@Override
246-
public List<ChannelInterceptor> getChannelInterceptors() {
247+
public List<ChannelInterceptor> getInterceptors() {
247248
return this.interceptors.getInterceptors();
248249
}
249250

@@ -259,10 +260,10 @@ public ChannelInterceptor removeInterceptor(int index) {
259260
}
260261

261262
/**
262-
* Exposes the interceptor list for subclasses.
263+
* Exposes the interceptor list instance for subclasses.
263264
* @return The channel interceptor list.
264265
*/
265-
protected ChannelInterceptorList getInterceptors() {
266+
protected ChannelInterceptorList getIChannelInterceptorList() {
266267
return this.interceptors;
267268
}
268269

spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractPollableChannel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public Message<?> receive() {
9292
@Override
9393
@Nullable
9494
public Message<?> receive(long timeout) {
95-
ChannelInterceptorList interceptorList = getInterceptors();
95+
ChannelInterceptorList interceptorList = getIChannelInterceptorList();
9696
Deque<ChannelInterceptor> interceptorStack = null;
9797
boolean counted = false;
9898
boolean countsEnabled = isCountsEnabled();
Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2018 the original author or authors.
2+
* Copyright 2014-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,8 +18,8 @@
1818

1919
import java.util.List;
2020

21-
import org.springframework.lang.Nullable;
2221
import org.springframework.messaging.support.ChannelInterceptor;
22+
import org.springframework.messaging.support.InterceptableChannel;
2323

2424
/**
2525
* A marker interface providing the ability to configure {@link ChannelInterceptor}s
@@ -30,48 +30,21 @@
3030
* *
3131
* @author Artem Bilan
3232
* @author Gary Russell
33+
*
3334
* @since 4.0
35+
*
36+
* @deprecated since 5.1.3 in favor of {@link InterceptableChannel}.
37+
* Will be removed in the next version
3438
*/
35-
public interface ChannelInterceptorAware {
36-
37-
/**
38-
* Populate the {@link ChannelInterceptor}s to the target implementation.
39-
* @param interceptors the {@link ChannelInterceptor}s to populate.
40-
*/
41-
void setInterceptors(List<ChannelInterceptor> interceptors);
42-
43-
/**
44-
* And a {@link ChannelInterceptor} to the target implementation.
45-
* @param interceptor the {@link ChannelInterceptor} to add.
46-
*/
47-
void addInterceptor(ChannelInterceptor interceptor);
48-
49-
/**
50-
* And a {@link ChannelInterceptor} to the target implementation for the specific index.
51-
* @param index the index for {@link ChannelInterceptor} to add.
52-
* @param interceptor the {@link ChannelInterceptor} to add.
53-
*/
54-
void addInterceptor(int index, ChannelInterceptor interceptor);
39+
@Deprecated
40+
public interface ChannelInterceptorAware extends InterceptableChannel {
5541

5642
/**
5743
* return the {@link ChannelInterceptor} list.
5844
* @return the {@link ChannelInterceptor} list.
5945
*/
60-
List<ChannelInterceptor> getChannelInterceptors();
61-
62-
/**
63-
* Remove the provided {@link ChannelInterceptor} from the target implementation.
64-
* @param interceptor {@link ChannelInterceptor} to remove.
65-
* @return the {@code boolean} if {@link ChannelInterceptor} has been removed.
66-
*/
67-
boolean removeInterceptor(ChannelInterceptor interceptor);
68-
69-
/**
70-
* Remove a {@link ChannelInterceptor} from the target implementation for specific index.
71-
* @param index the index for the {@link org.springframework.messaging.support.ChannelInterceptor} to remove.
72-
* @return the {@code boolean} if the {@link ChannelInterceptor} has been removed.
73-
*/
74-
@Nullable
75-
ChannelInterceptor removeInterceptor(int index);
46+
default List<ChannelInterceptor> getChannelInterceptors() {
47+
return getInterceptors();
48+
}
7649

7750
}

spring-integration-core/src/main/java/org/springframework/integration/channel/ExecutorChannelInterceptorAware.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2016 the original author or authors.
2+
* Copyright 2015-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,9 +23,12 @@
2323
* and the implementors require to know if they should make the
2424
* {@link org.springframework.messaging.support.ExecutorChannelInterceptor}
2525
* or not.
26+
*
2627
* @author Artem Bilan
28+
*
2729
* @since 4.2
2830
*/
31+
@SuppressWarnings("deprecation")
2932
public interface ExecutorChannelInterceptorAware extends ChannelInterceptorAware {
3033

3134
boolean hasExecutorInterceptors();

spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/VetoCapableInterceptor.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2018 the original author or authors.
2+
* Copyright 2014-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.integration.channel.interceptor;
1818

19-
import org.springframework.integration.channel.ChannelInterceptorAware;
20-
2119
/**
2220
* {@link org.springframework.messaging.support.ChannelInterceptor}s implementing this
2321
* interface can veto
@@ -36,6 +34,7 @@ public interface VetoCapableInterceptor {
3634
* @param channel The channel that is about to be intercepted.
3735
* @return false if the intercept wishes to veto the interception.
3836
*/
39-
boolean shouldIntercept(String beanName, ChannelInterceptorAware channel);
37+
@SuppressWarnings("deprecation")
38+
boolean shouldIntercept(String beanName, org.springframework.integration.channel.ChannelInterceptorAware channel);
4039

4140
}

spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/WireTap.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@
2323
import org.springframework.beans.factory.BeanFactory;
2424
import org.springframework.beans.factory.BeanFactoryAware;
2525
import org.springframework.context.Lifecycle;
26-
import org.springframework.integration.channel.ChannelInterceptorAware;
2726
import org.springframework.integration.core.MessageSelector;
2827
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
2928
import org.springframework.jmx.export.annotation.ManagedAttribute;
@@ -173,7 +172,10 @@ public Message<?> preSend(Message<?> message, MessageChannel channel) {
173172
}
174173

175174
@Override
176-
public boolean shouldIntercept(String beanName, ChannelInterceptorAware channel) {
175+
@SuppressWarnings("deprecation")
176+
public boolean shouldIntercept(String beanName,
177+
org.springframework.integration.channel.ChannelInterceptorAware channel) {
178+
177179
return !getChannel().equals(channel);
178180
}
179181

spring-integration-core/src/main/java/org/springframework/integration/config/GlobalChannelInterceptorProcessor.java

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,11 +18,8 @@
1818

1919
import java.util.ArrayList;
2020
import java.util.Collection;
21-
import java.util.Collections;
2221
import java.util.LinkedHashSet;
2322
import java.util.List;
24-
import java.util.Map;
25-
import java.util.Map.Entry;
2623
import java.util.Set;
2724

2825
import org.apache.commons.logging.Log;
@@ -35,7 +32,6 @@
3532
import org.springframework.beans.factory.SmartInitializingSingleton;
3633
import org.springframework.beans.factory.config.BeanPostProcessor;
3734
import org.springframework.core.OrderComparator;
38-
import org.springframework.integration.channel.ChannelInterceptorAware;
3935
import org.springframework.integration.channel.interceptor.GlobalChannelInterceptorWrapper;
4036
import org.springframework.integration.channel.interceptor.VetoCapableInterceptor;
4137
import org.springframework.integration.support.utils.PatternMatchUtils;
@@ -79,36 +75,36 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
7975
}
8076

8177
@Override
78+
@SuppressWarnings("deprecation")
8279
public void afterSingletonsInstantiated() {
8380
Collection<GlobalChannelInterceptorWrapper> interceptors =
8481
this.beanFactory.getBeansOfType(GlobalChannelInterceptorWrapper.class).values();
8582
if (CollectionUtils.isEmpty(interceptors)) {
8683
logger.debug("No global channel interceptors.");
8784
}
8885
else {
89-
for (GlobalChannelInterceptorWrapper channelInterceptor : interceptors) {
90-
if (channelInterceptor.getOrder() >= 0) {
91-
this.positiveOrderInterceptors.add(channelInterceptor);
86+
interceptors.forEach(interceptor -> {
87+
if (interceptor.getOrder() >= 0) {
88+
this.positiveOrderInterceptors.add(interceptor);
9289
}
9390
else {
94-
this.negativeOrderInterceptors.add(channelInterceptor);
91+
this.negativeOrderInterceptors.add(interceptor);
9592
}
96-
}
93+
});
9794

98-
Map<String, ChannelInterceptorAware> channels =
99-
this.beanFactory.getBeansOfType(ChannelInterceptorAware.class);
100-
for (Entry<String, ChannelInterceptorAware> entry : channels.entrySet()) {
101-
addMatchingInterceptors(entry.getValue(), entry.getKey());
102-
}
95+
this.beanFactory.getBeansOfType(org.springframework.integration.channel.ChannelInterceptorAware.class)
96+
.forEach((key, value) -> addMatchingInterceptors(value, key));
10397
}
10498

10599
this.singletonsInstantiated = true;
106100
}
107101

108102
@Override
103+
@SuppressWarnings("deprecation")
109104
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
110-
if (this.singletonsInstantiated && bean instanceof ChannelInterceptorAware) {
111-
addMatchingInterceptors((ChannelInterceptorAware) bean, beanName);
105+
if (this.singletonsInstantiated
106+
&& bean instanceof org.springframework.integration.channel.ChannelInterceptorAware) {
107+
addMatchingInterceptors((org.springframework.integration.channel.ChannelInterceptorAware) bean, beanName);
112108
}
113109
return bean;
114110
}
@@ -118,41 +114,36 @@ public Object postProcessAfterInitialization(Object bean, String beanName) throw
118114
* @param channel the message channel to add interceptors.
119115
* @param beanName the message channel bean name to match the pattern.
120116
*/
121-
public void addMatchingInterceptors(ChannelInterceptorAware channel, String beanName) {
117+
@SuppressWarnings("deprecation")
118+
public void addMatchingInterceptors(org.springframework.integration.channel.ChannelInterceptorAware channel,
119+
String beanName) {
120+
122121
if (logger.isDebugEnabled()) {
123122
logger.debug("Applying global interceptors on channel '" + beanName + "'");
124123
}
125124

126125
List<GlobalChannelInterceptorWrapper> tempInterceptors = new ArrayList<>();
127-
for (GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper : this.positiveOrderInterceptors) {
128-
String[] patterns = globalChannelInterceptorWrapper.getPatterns();
129-
patterns = StringUtils.trimArrayElements(patterns);
130-
if (beanName != null && Boolean.TRUE.equals(PatternMatchUtils.smartMatch(beanName, patterns))) {
131-
tempInterceptors.add(globalChannelInterceptorWrapper);
132-
}
133-
}
134126

135-
Collections.sort(tempInterceptors, this.comparator);
127+
this.positiveOrderInterceptors
128+
.forEach(interceptorWrapper ->
129+
addMatchingInterceptors(beanName, tempInterceptors, interceptorWrapper));
136130

137-
for (GlobalChannelInterceptorWrapper next : tempInterceptors) {
138-
ChannelInterceptor channelInterceptor = next.getChannelInterceptor();
139-
if (!(channelInterceptor instanceof VetoCapableInterceptor)
140-
|| ((VetoCapableInterceptor) channelInterceptor).shouldIntercept(beanName, channel)) {
141-
channel.addInterceptor(channelInterceptor);
142-
}
143-
}
131+
tempInterceptors.sort(this.comparator);
132+
133+
tempInterceptors
134+
.stream()
135+
.map(GlobalChannelInterceptorWrapper::getChannelInterceptor)
136+
.filter(interceptor -> !(interceptor instanceof VetoCapableInterceptor)
137+
|| ((VetoCapableInterceptor) interceptor).shouldIntercept(beanName, channel))
138+
.forEach(channel::addInterceptor);
144139

145140
tempInterceptors.clear();
146141

147-
for (GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper : this.negativeOrderInterceptors) {
148-
String[] patterns = globalChannelInterceptorWrapper.getPatterns();
149-
patterns = StringUtils.trimArrayElements(patterns);
150-
if (beanName != null && Boolean.TRUE.equals(PatternMatchUtils.smartMatch(beanName, patterns))) {
151-
tempInterceptors.add(globalChannelInterceptorWrapper);
152-
}
153-
}
142+
this.negativeOrderInterceptors
143+
.forEach(interceptorWrapper ->
144+
addMatchingInterceptors(beanName, tempInterceptors, interceptorWrapper));
154145

155-
Collections.sort(tempInterceptors, this.comparator);
146+
tempInterceptors.sort(this.comparator);
156147

157148
if (!tempInterceptors.isEmpty()) {
158149
for (int i = tempInterceptors.size() - 1; i >= 0; i--) {
@@ -165,4 +156,15 @@ public void addMatchingInterceptors(ChannelInterceptorAware channel, String bean
165156
}
166157
}
167158

159+
private static void addMatchingInterceptors(String beanName,
160+
List<GlobalChannelInterceptorWrapper> tempInterceptors,
161+
GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper) {
162+
163+
String[] patterns = globalChannelInterceptorWrapper.getPatterns();
164+
patterns = StringUtils.trimArrayElements(patterns);
165+
if (beanName != null && Boolean.TRUE.equals(PatternMatchUtils.smartMatch(beanName, patterns))) {
166+
tempInterceptors.add(globalChannelInterceptorWrapper);
167+
}
168+
}
169+
168170
}

spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlowDefinition.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.springframework.expression.Expression;
3636
import org.springframework.expression.spel.standard.SpelExpressionParser;
3737
import org.springframework.integration.aggregator.AggregatingMessageHandler;
38-
import org.springframework.integration.channel.ChannelInterceptorAware;
3938
import org.springframework.integration.channel.DirectChannel;
4039
import org.springframework.integration.channel.FixedSubscriberChannel;
4140
import org.springframework.integration.channel.FluxMessageChannel;
@@ -90,6 +89,7 @@
9089
import org.springframework.messaging.Message;
9190
import org.springframework.messaging.MessageChannel;
9291
import org.springframework.messaging.MessageHandler;
92+
import org.springframework.messaging.support.InterceptableChannel;
9393
import org.springframework.util.Assert;
9494
import org.springframework.util.CollectionUtils;
9595
import org.springframework.util.StringUtils;
@@ -430,12 +430,12 @@ public B wireTap(MessageChannel wireTapChannel, Consumer<WireTapSpec> wireTapCon
430430
*/
431431
public B wireTap(WireTapSpec wireTapSpec) {
432432
WireTap interceptor = wireTapSpec.get();
433-
if (!(this.currentMessageChannel instanceof ChannelInterceptorAware)) {
433+
if (!(this.currentMessageChannel instanceof InterceptableChannel)) {
434434
channel(new DirectChannel());
435435
this.implicitChannel = true;
436436
}
437437
addComponent(wireTapSpec);
438-
((ChannelInterceptorAware) this.currentMessageChannel).addInterceptor(interceptor);
438+
((InterceptableChannel) this.currentMessageChannel).addInterceptor(interceptor);
439439
return _this();
440440
}
441441

0 commit comments

Comments
 (0)