public class ResequencerEngine<E> extends java.lang.Object implements TimeoutHandler
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.
timeout. Defines 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 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 to the output queue. However, large timeout values
might require a very high resequencer capacity which might be
in conflict with available memory resources. The lower the
timeout value is compared to the out-of-sequence time between
elements within a stream the higher the probability is for out-of-sequence
elements delivered by this resequencer.
capacity. The capacity of this resequencer.
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.
| Constructor and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(E o)
Adds an element to this resequencer throwing an exception if the maximum
capacity is reached.
|
java.util.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(java.util.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.
|
public ResequencerEngine(SequenceElementComparator<E> comparator)
Integer.MAX_VALUE.comparator - a sequence element comparator.public ResequencerEngine(SequenceElementComparator<E> comparator, int capacity)
comparator - a sequence element comparator.capacity - the capacity of this resequencer.public void stop()
Timer instance).public java.util.Queue<E> getOutQueue()
public void setOutQueue(java.util.Queue<E> outQueue)
outQueue - output queue.public long getTimeout()
public void setTimeout(long timeout)
timeout - the timeout in milliseconds.public void timeout(Timeout timout)
timeout in interface TimeoutHandlertimout - timeout task that caused the notification.public void add(E o)
o - element to be resequenced.java.lang.IllegalStateException - if the element cannot be added at this time
due to capacity restrictions.public void put(E o) throws java.lang.InterruptedException
o - element to be resequenced.java.lang.InterruptedException - if interrupted while waiting.Copyright © 2005-2015 FuseSource. All Rights Reserved.