org.apache.camel.processor.resequencer
Class ResequencerEngine<E>

java.lang.Object
  extended by org.apache.camel.processor.resequencer.ResequencerEngine<E>
All Implemented Interfaces:
TimeoutHandler

public class ResequencerEngine<E>
extends Object
implements TimeoutHandler

Resequences elements based on a given SequenceElementComparator. This resequencer is designed for resequencing element streams. Resequenced elements are added to an output Queue. The resequencer is configured via the timeout and capacity properties.

Whenever a timeout for a certain element occurs or an element has been added to this resequencer a delivery attempt is started. If a (sub)sequence of elements is ready-for-delivery then they are added to output queue.

The resequencer remembers the last-delivered element. If an element arrives which is the immediate successor of the last-delivered element it will be delivered immediately and the last-delivered element is adjusted accordingly. If the last-delivered element is null i.e. the resequencer was newly created the first arriving element will wait timeout milliseconds for being delivered to the output queue.

Version:
$Revision
Author:
Martin Krasser

Constructor Summary
ResequencerEngine(SequenceElementComparator<E> comparator)
          Creates a new resequencer instance with a default timeout of 2000 milliseconds.
ResequencerEngine(SequenceElementComparator<E> comparator, int capacity)
          Creates a new resequencer instance with a default timeout of 2000 milliseconds.
 
Method Summary
 void add(E o)
          Adds an element to this resequencer throwing an exception if the maximum capacity is reached.
 Queue<E> getOutQueue()
          Returns the output queue.
 long getTimeout()
          Returns this resequencer's timeout value.
 void put(E o)
          Adds an element to this resequencer waiting, if necessary, until capacity becomes available.
 void setOutQueue(Queue<E> outQueue)
          Sets the output queue.
 void setTimeout(long timeout)
          Sets this sequencer's timeout value.
 void stop()
          Stops this resequencer (i.e.
 void timeout(Timeout timout)
          Handles a timeout notification by starting a delivery attempt.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResequencerEngine

public ResequencerEngine(SequenceElementComparator<E> comparator)
Creates a new resequencer instance with a default timeout of 2000 milliseconds. The capacity is set to Integer.MAX_VALUE.

Parameters:
comparator - a sequence element comparator.

ResequencerEngine

public ResequencerEngine(SequenceElementComparator<E> comparator,
                         int capacity)
Creates a new resequencer instance with a default timeout of 2000 milliseconds.

Parameters:
comparator - a sequence element comparator.
capacity - the capacity of this resequencer.
Method Detail

stop

public void stop()
Stops this resequencer (i.e. this resequencer's Timer instance).


getOutQueue

public Queue<E> getOutQueue()
Returns the output queue.

Returns:
the output queue.

setOutQueue

public void setOutQueue(Queue<E> outQueue)
Sets the output queue.

Parameters:
outQueue - output queue.

getTimeout

public long getTimeout()
Returns this resequencer's timeout value.

Returns:
the timeout in milliseconds.

setTimeout

public void setTimeout(long timeout)
Sets this sequencer's timeout value.

Parameters:
timeout - the timeout in milliseconds.

timeout

public void timeout(Timeout timout)
Handles a timeout notification by starting a delivery attempt.

Specified by:
timeout in interface TimeoutHandler
Parameters:
timout - timeout task that caused the notification.

add

public void add(E o)
Adds an element to this resequencer throwing an exception if the maximum capacity is reached.

Parameters:
o - element to be resequenced.
Throws:
IllegalStateException - if the element cannot be added at this time due to capacity restrictions.

put

public void put(E o)
         throws InterruptedException
Adds an element to this resequencer waiting, if necessary, until capacity becomes available.

Parameters:
o - element to be resequenced.
Throws:
InterruptedException - if interrupted while waiting.


Copyright © 2008 IONA Open Source Community. All Rights Reserved.