@Override protected Object doHandleRequestMessage(Message<?> message) { if (this.selector.accept(message)) { return message; } else { return null; } }
public boolean accept(Message<?> message) { return (this.selector == null || this.selector.accept(message)); }
@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; }
/** * 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) { MessageChannel wireTapChannel = getChannel(); if (wireTapChannel.equals(channel)) { if (logger.isDebugEnabled()) { logger.debug("WireTap is refusing to intercept its own channel '" + wireTapChannel + "'"); } return message; } if (this.running && (this.selector == null || this.selector.accept(message))) { boolean sent = (this.timeout >= 0) ? wireTapChannel.send(message, this.timeout) : wireTapChannel.send(message); if (!sent && logger.isWarnEnabled()) { logger.warn("failed to send message to WireTap channel '" + wireTapChannel + "'"); } } return message; }
@Override public List<Message<?>> purge(MessageSelector selector) { if (selector == null) { return this.clear(); } List<Message<?>> purgedMessages = new ArrayList<>(); 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; }
/** * 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}. */ @Override 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); }
@Test public void topLevelSelector() { MessageSelector selector = (MessageSelector) context.getBean("selector"); assertTrue(selector.accept(new GenericMessage<String>("test"))); }
@Override protected Object doInvoke(MethodInvocation invocation, Message<?> message) throws Throwable { boolean accept = this.messageSelector.accept(message); if (!accept) { boolean discarded = false; MessageChannel theDiscardChannel = obtainDiscardChannel(); if (theDiscardChannel != null) { this.messagingTemplate.send(theDiscardChannel, message); discarded = true; } if (this.throwExceptionOnRejection) { throw new MessageRejectedException(message, "IdempotentReceiver '" + this + "' rejected duplicate Message: " + message); } if (!discarded) { invocation.getArguments()[0] = getMessageBuilderFactory() .fromMessage(message) .setHeader(IntegrationMessageHeaderAccessor.DUPLICATE_MESSAGE, true) .build(); } else { return null; } } return invocation.proceed(); }
@Override protected Object doHandleRequestMessage(Message<?> message) { if (this.selector.accept(message)) { return message; } else { return null; } }
public boolean accept(Message<?> message) { return (this.selector == null || this.selector.accept(message)); }
@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; }
@Override public boolean accept(Message<?> message) { return matchingHeaders.entrySet() .stream() .allMatch(entry -> factories.stream() .filter(factory -> factory.supports(entry.getKey())) .findAny() .orElse(new HeaderMatchingMessageSelector.Factory()) .create(entry.getKey(), entry.getValue(), context) .accept(message)); }
/** * Supports selective consumption of messages on the channel. The first message * to be accepted by given message selector is returned as result. * * @param selector * @return */ public Message<?> receive(MessageSelector selector) { Object[] array = this.queue.toArray(); for (Object o : array) { Message<?> message = (Message<?>) o; if (selector.accept(message) && this.queue.remove(message)) { return message; } } return null; }
/** * 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) { MessageChannel wireTapChannel = getChannel(); if (wireTapChannel.equals(channel)) { if (logger.isDebugEnabled()) { logger.debug("WireTap is refusing to intercept its own channel '" + wireTapChannel + "'"); } return message; } if (this.running && (this.selector == null || this.selector.accept(message))) { boolean sent = (this.timeout >= 0) ? wireTapChannel.send(message, this.timeout) : wireTapChannel.send(message); if (!sent && logger.isWarnEnabled()) { logger.warn("failed to send message to WireTap channel '" + wireTapChannel + "'"); } } return message; }
@Override public List<Message<?>> purge(MessageSelector selector) { if (selector == null) { return this.clear(); } List<Message<?>> purgedMessages = new ArrayList<>(); 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; }
/** * 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}. */ @Override 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 Object doInvoke(MethodInvocation invocation, Message<?> message) throws Throwable { boolean accept = this.messageSelector.accept(message); if (!accept) { boolean discarded = false; MessageChannel theDiscardChannel = obtainDiscardChannel(); if (theDiscardChannel != null) { this.messagingTemplate.send(theDiscardChannel, message); discarded = true; } if (this.throwExceptionOnRejection) { throw new MessageRejectedException(message, "IdempotentReceiver '" + this + "' rejected duplicate Message: " + message); } if (!discarded) { invocation.getArguments()[0] = getMessageBuilderFactory() .fromMessage(message) .setHeader(IntegrationMessageHeaderAccessor.DUPLICATE_MESSAGE, true) .build(); } else { return null; } } return invocation.proceed(); }