Source:
<code>public boolean dispatch(Message<?> message) { int dispatched = 0; int sequenceNumber = 1; Collection<MessageHandler> handlers = this.getHandlers(); if (this.requireSubscribers && handlers.size() == 0) { throw new MessageDispatchingException(message, "Dispatcher has no subscribers"); } int sequenceSize = handlers.size(); Message<?> messageToSend = message; UUID sequenceId = null; if (this.applySequence) { sequenceId = message.getHeaders().getId(); } for (MessageHandler handler : handlers) { if (this.applySequence) { <START> if (message instanceof ThreadStatePropagationChannelInterceptor.MessageWithThreadState) { <END> messageToSend = ((ThreadStatePropagationChannelInterceptor.MessageWithThreadState) message) .cloneWithSequenceDetails(sequenceId, sequenceNumber++, sequenceSize); } else { messageToSend = getMessageBuilderFactory() .fromMessage(message) .pushSequenceDetails(sequenceId, sequenceNumber++, sequenceSize) .build(); } } if (this.executor != null) { Runnable task = createMessageHandlingTask(handler, messageToSend); this.executor.execute(task); dispatched++; } else { if (this.invokeHandler(handler, messageToSend)) { dispatched++; } } } if (dispatched == 0 && this.minSubscribers == 0 && logger.isDebugEnabled()) { if (sequenceSize > 0) { logger.debug("No subscribers received message, default behavior is ignore"); } else { logger.debug("No subscribers, default behavior is ignore"); } } return dispatched >= this.minSubscribers; }</code><technical_language>tying dispatcher interceptors of this type, I prefer a new interface; like... java /** * A Message<?> implementation needs special handling in MBF.fromMessage(). */ public interface ClonableMessage { MessageBuilder cloneMessage(); // createBuilderForClone() ? } Then, in MessageBuilder.fromMessage()... java if (message instanceof ClonableMessage) { return message.cloneMessage(); } else { return new MessageBuilder(...); } Or, leave clone logic in dispatcher (using interface), I belongs in builder</technical_language>

Target:
public boolean dispatch(Message<?> message) { int dispatched = 0; int sequenceNumber = 1; Collection<MessageHandler> handlers = this.getHandlers(); if (this.requireSubscribers && handlers.size() == 0) { throw new MessageDispatchingException(message, "Dispatcher has no subscribers"); } int sequenceSize = handlers.size(); Message<?> messageToSend = message; UUID sequenceId = null; if (this.applySequence) { sequenceId = message.getHeaders().getId(); } for (MessageHandler handler : handlers) { if (this.applySequence) { messageToSend = getMessageBuilderFactory() .fromMessage(message) .pushSequenceDetails(sequenceId, sequenceNumber++, sequenceSize) .build(); if (message instanceof MessageDecorator) { messageToSend = ((MessageDecorator) message).decorateMessage(messageToSend); } } if (this.executor != null) { Runnable task = createMessageHandlingTask(handler, messageToSend); this.executor.execute(task); dispatched++; } else { if (this.invokeHandler(handler, messageToSend)) { dispatched++; } } } if (dispatched == 0 && this.minSubscribers == 0 && logger.isDebugEnabled()) { if (sequenceSize > 0) { logger.debug("No subscribers received message, default behavior is ignore"); } else { logger.debug("No subscribers, default behavior is ignore"); } } return dispatched >= this.minSubscribers; }