INT-3719: AbstractMessageChannel Optimizations
JIRA: https://jira.spring.io/browse/INT-3719 YourKit profiling for a lightweight XD stream indicates a large amount of time in `AMC.send()`. - Only call `logger.isDebugEnabled()` once - Eliminate the need to create an `UnmodifiableList` and calling `size()` to get the size of the interceptor list. Polishing INT-3719: Fix (PR Comment)
This commit is contained in:
committed by
Artem Bilan
parent
88a3b275dc
commit
68b3047d59
@@ -273,10 +273,11 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport
|
||||
if (this.datatypes.length > 0) {
|
||||
message = this.convertPayloadIfNecessary(message);
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
boolean debugEnabled = logger.isDebugEnabled();
|
||||
if (debugEnabled) {
|
||||
logger.debug("preSend on channel '" + this + "', message: " + message);
|
||||
}
|
||||
if (interceptors.getInterceptors().size() > 0) {
|
||||
if (interceptors.getSize() > 0) {
|
||||
interceptorStack = new ArrayDeque<ChannelInterceptor>();
|
||||
message = this.interceptors.preSend(message, this, interceptorStack);
|
||||
if (message == null) {
|
||||
@@ -285,7 +286,7 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport
|
||||
}
|
||||
sent = this.doSend(message, timeout);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
if (debugEnabled) {
|
||||
logger.debug("postSend (sent=" + sent + ") on channel '" + this + "', message: " + message);
|
||||
}
|
||||
if (interceptorStack != null) {
|
||||
@@ -356,6 +357,8 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport
|
||||
|
||||
private final List<ChannelInterceptor> interceptors = new CopyOnWriteArrayList<ChannelInterceptor>();
|
||||
|
||||
private volatile int size;
|
||||
|
||||
public ChannelInterceptorList(Log logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
@@ -363,21 +366,28 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport
|
||||
public boolean set(List<ChannelInterceptor> interceptors) {
|
||||
synchronized (this.interceptors) {
|
||||
this.interceptors.clear();
|
||||
this.size = interceptors.size();
|
||||
return this.interceptors.addAll(interceptors);
|
||||
}
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return this.size;
|
||||
}
|
||||
|
||||
public boolean add(ChannelInterceptor interceptor) {
|
||||
this.size++;
|
||||
return this.interceptors.add(interceptor);
|
||||
}
|
||||
|
||||
public void add(int index, ChannelInterceptor interceptor) {
|
||||
this.size++;
|
||||
this.interceptors.add(index, interceptor);
|
||||
}
|
||||
|
||||
public Message<?> preSend(Message<?> message, MessageChannel channel,
|
||||
Deque<ChannelInterceptor> interceptorStack) {
|
||||
if (this.interceptors.size() > 0) {
|
||||
if (this.size > 0) {
|
||||
for (ChannelInterceptor interceptor : this.interceptors) {
|
||||
message = interceptor.preSend(message, channel);
|
||||
if (message == null) {
|
||||
@@ -395,7 +405,7 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport
|
||||
}
|
||||
|
||||
public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
|
||||
if (this.interceptors.size() > 0) {
|
||||
if (this.size > 0) {
|
||||
for (ChannelInterceptor interceptor : interceptors) {
|
||||
interceptor.postSend(message, channel, sent);
|
||||
}
|
||||
@@ -416,7 +426,7 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport
|
||||
}
|
||||
|
||||
public boolean preReceive(MessageChannel channel, Deque<ChannelInterceptor> interceptorStack) {
|
||||
if (this.interceptors.size() > 0) {
|
||||
if (this.size > 0) {
|
||||
for (ChannelInterceptor interceptor : interceptors) {
|
||||
if (!interceptor.preReceive(channel)) {
|
||||
afterReceiveCompletion(null, channel, null, interceptorStack);
|
||||
@@ -429,7 +439,7 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport
|
||||
}
|
||||
|
||||
public Message<?> postReceive(Message<?> message, MessageChannel channel) {
|
||||
if (this.interceptors.size() > 0) {
|
||||
if (this.size > 0) {
|
||||
for (ChannelInterceptor interceptor : interceptors) {
|
||||
message = interceptor.postReceive(message, channel);
|
||||
if (message == null) {
|
||||
@@ -458,11 +468,21 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport
|
||||
}
|
||||
|
||||
public boolean remove(ChannelInterceptor interceptor) {
|
||||
return this.interceptors.remove(interceptor);
|
||||
if (this.interceptors.remove(interceptor)) {
|
||||
this.size--;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public ChannelInterceptor remove(int index) {
|
||||
return this.interceptors.remove(index);
|
||||
ChannelInterceptor removed = this.interceptors.remove(index);
|
||||
if (removed != null) {
|
||||
this.size--;
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user