Added MessageSelector list to MessageReceivingExecutor.
This commit is contained in:
@@ -108,14 +108,11 @@ public class DefaultMessageDispatcher extends AbstractMessageDispatcher {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
executor.processMessage(message);
|
||||
if (!this.broadcast) {
|
||||
boolean accepted = executor.acceptMessage(message);
|
||||
if (accepted && !this.broadcast) {
|
||||
return true;
|
||||
}
|
||||
iter.remove();
|
||||
if (!iter.hasNext() && !encounteredRejection) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (RejectedExecutionException rex) {
|
||||
encounteredRejection = true;
|
||||
@@ -124,6 +121,9 @@ public class DefaultMessageDispatcher extends AbstractMessageDispatcher {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.broadcast && !encounteredRejection) {
|
||||
return true;
|
||||
}
|
||||
attempts++;
|
||||
}
|
||||
if (this.shouldFailOnRejectionLimit) {
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.integration.bus;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -27,6 +29,7 @@ import org.springframework.context.Lifecycle;
|
||||
import org.springframework.integration.MessageHandlingException;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageReceiver;
|
||||
import org.springframework.integration.message.selector.MessageSelector;
|
||||
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -41,6 +44,8 @@ public class MessageReceivingExecutor implements Lifecycle {
|
||||
|
||||
private MessageReceiver receiver;
|
||||
|
||||
private List<MessageSelector> selectors = new CopyOnWriteArrayList<MessageSelector>();
|
||||
|
||||
private ThreadPoolExecutor threadPoolExecutor;
|
||||
|
||||
private int corePoolSize;
|
||||
@@ -78,6 +83,11 @@ public class MessageReceivingExecutor implements Lifecycle {
|
||||
this.maxPoolSize = maxPoolSize;
|
||||
}
|
||||
|
||||
public void addMessageSelector(MessageSelector messageSelector) {
|
||||
Assert.notNull(messageSelector, "'messageSelector' must not be null");
|
||||
this.selectors.add(messageSelector);
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return this.running;
|
||||
}
|
||||
@@ -101,11 +111,17 @@ public class MessageReceivingExecutor implements Lifecycle {
|
||||
}
|
||||
}
|
||||
|
||||
public void processMessage(Message<?> message) {
|
||||
public boolean acceptMessage(Message<?> message) {
|
||||
if (threadPoolExecutor == null) {
|
||||
throw new MessageHandlingException("executor is not running");
|
||||
}
|
||||
for (MessageSelector selector : this.selectors) {
|
||||
if (!selector.accept(message)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
this.threadPoolExecutor.execute(new MessageReceivingTask(this.receiver, message));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user