@Override public Message<?> preSend(Message<?> message, MessageChannel channel) { for (MessageSelector selector : this.selectors) { if (!selector.accept(message)) { throw new MessageDeliveryException(message, "selector '" + selector + "' did not accept message"); } } return message; }
public List<Message<?>> purge(MessageSelector selector) { if (selector == null) { return this.clear(); } List<Message<?>> purgedMessages = new ArrayList<Message<?>>(); Object[] array = this.queue.toArray(); for (Object o : array) { Message<?> message = (Message<?>) o; if (!selector.accept(message) && this.queue.remove(message)) { purgedMessages.add(message); } } return purgedMessages; }
/** * Intercept the Message and, <em>if accepted</em> by the {@link MessageSelector}, * send it to the secondary target. If this wire tap's {@link MessageSelector} is * <code>null</code>, it will accept all messages. */ @Override public Message<?> preSend(Message<?> message, MessageChannel channel) { if (this.running && (this.selector == null || this.selector.accept(message))) { boolean sent = (this.timeout >= 0) ? this.channel.send(message, this.timeout) : this.channel.send(message); if (!sent && logger.isWarnEnabled()) { logger.warn("failed to send message to WireTap channel '" + this.channel + "'"); } } return message; }
/** * Remove and return any messages that are stored for the current thread * and do not match the provided selector. */ public List<Message<?>> purge(MessageSelector selector) { List<Message<?>> removedMessages = new ArrayList<Message<?>>(); Object[] allMessages = messageHolder.get().toArray(); for (Object next : allMessages) { Message<?> message = (Message<?>) next; if (!selector.accept(message) && messageHolder.get().remove(message)) { removedMessages.add(message); } } return removedMessages; }
/** * Pass the message through the selector chain. Whether the Message is * {@link #accept(Message) accepted} is based upon the tallied results of * the individual selectors' responses in accordance with this chain's * {@link VotingStrategy}. */ public final boolean accept(Message<?> message) { int count = 0; int accepted = 0; for (MessageSelector next : this.selectors) { count++; if (next.accept(message)) { if (this.votingStrategy.equals(VotingStrategy.ANY)) { return true; } accepted++; } else if (this.votingStrategy.equals(VotingStrategy.ALL)) { return false; } } return this.decide(accepted, count); }
@Override protected void handleRequestMessage(Message<?> message, ReplyMessageHolder replyHolder) { if (this.selector.accept(message)) { replyHolder.set(message); } else { if (this.discardChannel != null) { boolean discarded = this.sendReplyMessage(message, this.discardChannel); if (!discarded) { throw new MessageDeliveryException(message, "failed to send rejected Message to the discard channel"); } } if (this.throwExceptionOnRejection) { throw new MessageRejectedException(message); } } }