Post interceptors are invoked in the reverse order of pre interceptors

This commit is contained in:
Mark Fisher
2008-07-09 14:09:25 +00:00
parent 0b25056392
commit 92746ebed6
4 changed files with 21 additions and 11 deletions

View File

@@ -214,7 +214,6 @@ public abstract class AbstractEndpoint implements MessageEndpoint, BeanNameAware
}
private boolean send(final Message<?> message, final int index) {
boolean result = false;
if (index == 0) {
for (EndpointInterceptor interceptor : interceptors) {
if (!interceptor.preSend(message)) {
@@ -223,21 +222,20 @@ public abstract class AbstractEndpoint implements MessageEndpoint, BeanNameAware
}
}
if (index == interceptors.size()) {
return this.doSend(message);
boolean result = this.doSend(message);
for (int i = index - 1; i >= 0; i--) {
EndpointInterceptor interceptor = this.interceptors.get(i);
interceptor.postSend(message, result);
}
return result;
}
EndpointInterceptor nextInterceptor = interceptors.get(index);
result = nextInterceptor.aroundSend(message, new MessageTarget() {
return nextInterceptor.aroundSend(message, new MessageTarget() {
@SuppressWarnings("unchecked")
public boolean send(Message message) {
return AbstractEndpoint.this.send(message, index + 1);
}
});
if (index == this.interceptors.size()) {
for (EndpointInterceptor interceptor : this.interceptors) {
interceptor.postSend(message, result);
}
}
return result;
}
private boolean doSend(Message<?> message) {

View File

@@ -17,6 +17,8 @@
package org.springframework.integration.endpoint.interceptor;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
@@ -105,6 +107,16 @@ public class ConcurrencyInterceptor extends EndpointInterceptorAdapter
if (this.executor instanceof DisposableBean) {
((DisposableBean) this.executor).destroy();
}
if (this.executor instanceof ConcurrentTaskExecutor) {
Executor innerExecutor = ((ConcurrentTaskExecutor) this.executor).getConcurrentExecutor();
if (innerExecutor instanceof ExecutorService) {
ExecutorService executorService = (ExecutorService) innerExecutor;
executorService.shutdown();
if (!executorService.awaitTermination(10, TimeUnit.SECONDS)) {
executorService.shutdownNow();
}
}
}
}
@Override

View File

@@ -213,7 +213,7 @@ public class SimpleTaskScheduler extends AbstractTaskScheduler implements Dispos
logger.warn("error occurred in task but no 'errorHandler' is available", t);
}
}
if (this.shouldRepeat) {
if (this.shouldRepeat && isRunning()) {
TaskRunner runner = new TaskRunner(this.task);
runner.setShouldRepeat(true);
executor.execute(runner);

View File

@@ -111,7 +111,7 @@ public class WireTapTests {
QueueChannel secondaryChannel = new QueueChannel();
mainChannel.addInterceptor(new WireTap(secondaryChannel));
Message<?> message = new StringMessage("testing");
Thread.sleep(3);
Thread.sleep(50);
mainChannel.send(message);
Message<?> original = mainChannel.receive(0);
Message<?> duplicate = secondaryChannel.receive(0);