org.springframework.integration.aggregator
Class Resequencer

java.lang.Object
  extended by org.springframework.integration.handler.AbstractMessageHandler
      extended by org.springframework.integration.aggregator.AbstractMessageBarrierHandler<java.util.SortedSet<Message<?>>>
          extended by org.springframework.integration.aggregator.Resequencer
All Implemented Interfaces:
org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.InitializingBean, org.springframework.core.Ordered, MessageHandler

public class Resequencer
extends AbstractMessageBarrierHandler<java.util.SortedSet<Message<?>>>

An AbstractMessageBarrierHandler that waits for a group of Messages to arrive and re-sends them in order, sorted by their sequenceNumber.

This handler can either release partial sequences of messages or can wait for the whole sequence to arrive before re-sending them.

All considerations regarding timeout and grouping by 'correlationId' from AbstractMessageBarrierHandler apply here as well. It is assumed that all messages have the same sequence_size header attribute and that the sequence numbers of the messages are successive, starting with 1 up to sequenceSize. Messages that do not satisfy this condition are considered out-of-sequence and thus rejected. Note: messages with the same sequence number will be treated as equivalent by this class (i.e. after a message with a given sequence number is received, further messages from within the same group, that have the same sequence number, will be ignored.

Author:
Marius Bogoevici, Alex Peters

Field Summary
 
Fields inherited from class org.springframework.integration.aggregator.AbstractMessageBarrierHandler
barriers, DEFAULT_REAPER_INTERVAL, DEFAULT_SEND_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_TRACKED_CORRRELATION_ID_CAPACITY, logger, trackedCorrelationIds
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
Resequencer()
           
 
Method Summary
protected  boolean canAddMessage(Message<?> message, MessageBarrier<java.util.SortedSet<Message<?>>> barrier)
          Verifies that a message can be added to the barrier.
protected  MessageBarrier<java.util.SortedSet<Message<?>>> createMessageBarrier(java.lang.Object correlationKey)
          Factory method for creating a MessageBarrier implementation.
protected  void processBarrier(MessageBarrier<java.util.SortedSet<Message<?>>> barrier)
          A method for processing the information in the message barrier after a message has been added or on pruning.
 void setReleasePartialSequences(boolean releasePartialSequences)
           
 
Methods inherited from class org.springframework.integration.aggregator.AbstractMessageBarrierHandler
afterPropertiesSet, discardBarrier, handleMessageInternal, isRunning, removeBarrier, resolveReplyChannelFromMessage, sendReplies, sendReply, setAutoStartup, setBeanFactory, setCorrelationStrategy, setDiscardChannel, setOutputChannel, setReaperInterval, setSendPartialResultOnTimeout, setSendTimeout, setTaskScheduler, setTimeout, setTrackedCorrelationIdCapacity, start, stop
 
Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler
getOrder, handleMessage, setOrder
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Resequencer

public Resequencer()
Method Detail

setReleasePartialSequences

public void setReleasePartialSequences(boolean releasePartialSequences)

createMessageBarrier

protected MessageBarrier<java.util.SortedSet<Message<?>>> createMessageBarrier(java.lang.Object correlationKey)
Description copied from class: AbstractMessageBarrierHandler
Factory method for creating a MessageBarrier implementation.

Specified by:
createMessageBarrier in class AbstractMessageBarrierHandler<java.util.SortedSet<Message<?>>>

processBarrier

protected void processBarrier(MessageBarrier<java.util.SortedSet<Message<?>>> barrier)
Description copied from class: AbstractMessageBarrierHandler
A method for processing the information in the message barrier after a message has been added or on pruning. The decision as to whether the messages from the MessageBarrier can be released normally belongs here, although calling code may forcibly set the MessageBarrier's 'complete' flag to true before invoking the method.

Specified by:
processBarrier in class AbstractMessageBarrierHandler<java.util.SortedSet<Message<?>>>
Parameters:
barrier - the MessageBarrier to be processed

canAddMessage

protected boolean canAddMessage(Message<?> message,
                                MessageBarrier<java.util.SortedSet<Message<?>>> barrier)
Description copied from class: AbstractMessageBarrierHandler
Verifies that a message can be added to the barrier. To be overridden by subclasses, which may add their own verifications. Subclasses overriding this method must call the method from the superclass.

Overrides:
canAddMessage in class AbstractMessageBarrierHandler<java.util.SortedSet<Message<?>>>