|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.camel.processor.resequencer.ResequencerEngine<E>
public class ResequencerEngine<E>
Resequences elements based on a given SequenceElementComparator
.
This resequencer is designed for resequencing element streams. Stream-based
resequencing has the advantage that the number of elements to be resequenced
need not be known in advance. Resequenced elements are delivered via a
SequenceSender
.
The resequencer's behaviour for a given comparator is controlled by the
timeout
property. This is the timeout (in milliseconds) for a
given element managed by this resequencer. An out-of-sequence element can
only be marked as ready-for-delivery if it either times out or if it
has an immediate predecessor (in that case it is in-sequence). If an
immediate predecessor of a waiting element arrives the timeout task for the
waiting element will be cancelled (which marks it as ready-for-delivery).
If the maximum out-of-sequence time difference between elements within a
stream is known, the timeout
value should be set to this
value. In this case it is guaranteed that all elements of a stream will be
delivered in sequence via the SequenceSender
. The lower the
timeout
value is compared to the out-of-sequence time
difference between elements within a stream the higher the probability is for
out-of-sequence elements delivered by this resequencer. Delivery of elements
must be explicitly triggered by applications using the deliver()
or
deliverNext()
methods. Only elements that are ready-for-delivery
are delivered by these methods. The longer an application waits to trigger a
delivery the more elements may become ready-for-delivery.
The resequencer remembers the last-delivered element. If an element arrives
which is the immediate successor of the last-delivered element it is
ready-for-delivery immediately. After delivery 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 needs timeout
milliseconds in any case for becoming
ready-for-delivery.
Constructor Summary | |
---|---|
ResequencerEngine(SequenceElementComparator<E> comparator)
Creates a new resequencer instance with a default timeout of 2000 milliseconds. |
Method Summary | |
---|---|
void |
deliver()
Delivers all elements which are currently ready to deliver. |
boolean |
deliverNext()
Attempts to deliver a single element from the head of the resequencer queue (sequence). |
SequenceSender<E> |
getSequenceSender()
Returns the sequence sender. |
long |
getTimeout()
Returns this resequencer's timeout value. |
void |
insert(E o)
Inserts the given element into this resequencer. |
void |
setSequenceSender(SequenceSender<E> sequenceSender)
Sets the sequence sender. |
void |
setTimeout(long timeout)
Sets this sequencer's timeout value. |
int |
size()
Returns the number of elements currently maintained by this resequencer. |
void |
start()
|
void |
stop()
Stops this resequencer (i.e. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ResequencerEngine(SequenceElementComparator<E> comparator)
comparator
- a sequence element comparator.Method Detail |
---|
public void start()
public void stop()
Timer
instance).
public int size()
public long getTimeout()
public void setTimeout(long timeout)
timeout
- the timeout in milliseconds.public SequenceSender<E> getSequenceSender()
public void setSequenceSender(SequenceSender<E> sequenceSender)
sequenceSender
- a sequence element sender.public void insert(E o)
o
- an element.public void deliver() throws Exception
Exception
- thrown by SequenceSender.sendElement(Object)
.deliverNext()
public boolean deliverNext() throws Exception
SequenceSender.sendElement(Object)
.
true
if the element has been delivered
false
otherwise.
Exception
- thrown by SequenceSender.sendElement(Object)
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |