M - The type of Message maintained in the dead letter of this
SequencedDeadLetterQueue.public class InMemorySequencedDeadLetterQueue<M extends Message<?>> extends Object implements SequencedDeadLetterQueue<M>
SequencedDeadLetterQueue.
Maintains a Deque per unique "sequence identifier." The maximum amount of Deques contained by this
SequencedDeadLetterQueue is 1024 (configurable through InMemorySequencedDeadLetterQueue.Builder.maxSequences(int)). The
maximum amount of dead letters per sequence also defaults to 1024 (configurable through
InMemorySequencedDeadLetterQueue.Builder.maxSequenceSize(int)).
| Modifier and Type | Class and Description |
|---|---|
static class |
InMemorySequencedDeadLetterQueue.Builder<M extends Message<?>>
Builder class to instantiate an
InMemorySequencedDeadLetterQueue. |
| Modifier | Constructor and Description |
|---|---|
protected |
InMemorySequencedDeadLetterQueue(InMemorySequencedDeadLetterQueue.Builder<M> builder)
Instantiate an in-memory
SequencedDeadLetterQueue based on the given builder. |
| Modifier and Type | Method and Description |
|---|---|
long |
amountOfSequences()
Returns the number of unique sequences contained in this queue.
|
static <M extends Message<?>> |
builder()
Instantiate a builder to construct an
InMemorySequencedDeadLetterQueue. |
void |
clear()
Clears out all
dead letters present in this queue. |
boolean |
contains(Object sequenceIdentifier)
Check whether there's a sequence of
dead letters for the given sequenceIdentifier. |
Iterable<Iterable<DeadLetter<? extends M>>> |
deadLetters()
Return all
dead letter sequences held by this queue. |
Iterable<DeadLetter<? extends M>> |
deadLetterSequence(Object sequenceIdentifier)
Return all the
dead letters for the given sequenceIdentifier in insert order. |
static <M extends Message<?>> |
defaultQueue()
Construct a default
InMemorySequencedDeadLetterQueue. |
void |
enqueue(Object sequenceIdentifier,
DeadLetter<? extends M> letter)
Enqueues a
dead letter containing an implementation of M to this queue. |
void |
evict(DeadLetter<? extends M> letter)
Evict the given
letter from this queue. |
boolean |
isFull(Object sequenceIdentifier)
Validates whether this queue is full for the given
sequenceIdentifier. |
boolean |
process(Predicate<DeadLetter<? extends M>> sequenceFilter,
Function<DeadLetter<? extends M>,EnqueueDecision<M>> processingTask)
Process a sequence of enqueued
dead letters through the given processingTask matching
the sequenceFilter. |
void |
requeue(DeadLetter<? extends M> letter,
UnaryOperator<DeadLetter<? extends M>> letterUpdater)
Reenters the given
letter, updating the contents with the letterUpdater. |
long |
sequenceSize(Object sequenceIdentifier)
Returns the number of dead letters for the sequence matching the given
sequenceIdentifier contained in
this queue. |
long |
size()
Returns the number of dead letters contained in this queue.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitenqueueIfPresent, processprotected InMemorySequencedDeadLetterQueue(InMemorySequencedDeadLetterQueue.Builder<M> builder)
SequencedDeadLetterQueue based on the given builder.builder - The InMemorySequencedDeadLetterQueue.Builder used to instantiate a InMemorySequencedDeadLetterQueue instance.public static <M extends Message<?>> InMemorySequencedDeadLetterQueue.Builder<M> builder()
InMemorySequencedDeadLetterQueue.
The maximum number of sequences defaults to 1024 and the maximum amount of dead letters inside a sequence
defaults to 1024.
M - The type of Message maintained in the dead letter of this
SequencedDeadLetterQueue.InMemorySequencedDeadLetterQueue.public static <M extends Message<?>> InMemorySequencedDeadLetterQueue<M> defaultQueue()
InMemorySequencedDeadLetterQueue.
The maximum number of sequences defaults to 1024 and the maximum amount of dead letters inside a sequence
defaults to 1024.
M - The type of Message maintained in the dead letter of this
SequencedDeadLetterQueue.InMemorySequencedDeadLetterQueue.public void enqueue(@Nonnull Object sequenceIdentifier, @Nonnull DeadLetter<? extends M> letter) throws DeadLetterQueueOverflowException
SequencedDeadLetterQueuedead letter containing an implementation of M to this queue.
The dead letter will be appended to a sequence depending on the sequenceIdentifier. If there is
no sequence yet, it will construct one.
enqueue in interface SequencedDeadLetterQueue<M extends Message<?>>sequenceIdentifier - The identifier of the sequence the letter belongs to.letter - The DeadLetter to enqueue.DeadLetterQueueOverflowException - Thrown when this queue is full.public void evict(DeadLetter<? extends M> letter)
SequencedDeadLetterQueueletter from this queue. Nothing happens if the dead letter does not
exist in this queue.evict in interface SequencedDeadLetterQueue<M extends Message<?>>letter - The dead letter to evict from this queue.public void requeue(@Nonnull DeadLetter<? extends M> letter, @Nonnull UnaryOperator<DeadLetter<? extends M>> letterUpdater) throws NoSuchDeadLetterException
SequencedDeadLetterQueueletter, updating the contents with the letterUpdater. This method should be
invoked if processing decided to keep the letter in the queue.
This operation adjusts the DeadLetter.lastTouched(). It may adjust the DeadLetter.cause() and
DeadLetter.diagnostics(), depending on the given letterUpdater.
requeue in interface SequencedDeadLetterQueue<M extends Message<?>>letter - The dead letter to reenter in this queue.letterUpdater - A lambda taking in the given letter and updating the entry for
requeueing. This may adjust the DeadLetter.cause() and
DeadLetter.diagnostics(), for example.NoSuchDeadLetterException - Thrown if the given letter does not exist in the queue.public boolean contains(@Nonnull Object sequenceIdentifier)
SequencedDeadLetterQueuedead letters for the given sequenceIdentifier.contains in interface SequencedDeadLetterQueue<M extends Message<?>>sequenceIdentifier - The identifier used to validate for contained dead letters
instances.true if there are dead letters present for the given
sequenceIdentifier, false otherwise.public Iterable<DeadLetter<? extends M>> deadLetterSequence(@Nonnull Object sequenceIdentifier)
SequencedDeadLetterQueuedead letters for the given sequenceIdentifier in insert order.deadLetterSequence in interface SequencedDeadLetterQueue<M extends Message<?>>sequenceIdentifier - The identifier of the sequence of dead lettersto return.dead letters for the given sequenceIdentifier in insert order.public Iterable<Iterable<DeadLetter<? extends M>>> deadLetters()
SequencedDeadLetterQueuedead letter sequences held by this queue. The sequences are not necessarily
returned in insert order.deadLetters in interface SequencedDeadLetterQueue<M extends Message<?>>dead letter sequences held by this queue.public boolean isFull(@Nonnull Object sequenceIdentifier)
SequencedDeadLetterQueuesequenceIdentifier.
This method returns true either when the maximum amount of sequences or the maximum sequence size is
reached.
isFull in interface SequencedDeadLetterQueue<M extends Message<?>>sequenceIdentifier - The identifier of the sequence to validate for.true either when the limit of this queue is reached. Returns false otherwise.public long size()
SequencedDeadLetterQueuesize in interface SequencedDeadLetterQueue<M extends Message<?>>public long sequenceSize(@Nonnull Object sequenceIdentifier)
SequencedDeadLetterQueuesequenceIdentifier contained in
this queue.
Note that there's a window of opportunity where the size might exceed the maximum sequence size to accompany concurrent usage.
sequenceSize in interface SequencedDeadLetterQueue<M extends Message<?>>sequenceIdentifier - The identifier of the sequence to retrieve the size from.sequenceIdentifier.public long amountOfSequences()
SequencedDeadLetterQueueNote that there's a window of opportunity where the size might exceed the maximum amount of sequences to accompany concurrent usage of this dead letter queue.
amountOfSequences in interface SequencedDeadLetterQueue<M extends Message<?>>public boolean process(@Nonnull Predicate<DeadLetter<? extends M>> sequenceFilter, @Nonnull Function<DeadLetter<? extends M>,EnqueueDecision<M>> processingTask)
SequencedDeadLetterQueuedead letters through the given processingTask matching
the sequenceFilter. Will pick the oldest available sequence based on the DeadLetter.lastTouched()
field from every sequence's first entry.
Note that only a single matching sequence is processed! Furthermore, only the first dead letter is validated, because it is the blocker for the processing of the rest of the sequence.
Uses the EnqueueDecision returned by the processingTask to decide whether to
SequencedDeadLetterQueue.evict(DeadLetter) or SequencedDeadLetterQueue.requeue(DeadLetter, UnaryOperator) a dead letter from the selected
sequence. The processingTask is invoked as long as letters are present in the selected sequence and the
result of processing returns false for EnqueueDecision.shouldEnqueue() decision. The latter means
the dead letter should be evicted.
This operation protects against concurrent invocations of the processingTask on the filtered sequence.
Doing so ensure enqueued messages are handled in order.
process in interface SequencedDeadLetterQueue<M extends Message<?>>sequenceFilter - A lambda selecting the sequences within this queue to process with the
processingTask.processingTask - A function processing a dead letter. Returns a EnqueueDecision
used to deduce whether to SequencedDeadLetterQueue.evict(DeadLetter) or
SequencedDeadLetterQueue.requeue(DeadLetter, UnaryOperator) the dead letter.true if an entire sequence of dead letters was processed successfully,
false otherwise. This means the processingTask processed all dead letters of a
sequence and the outcome was to evict each instance.public void clear()
SequencedDeadLetterQueuedead letters present in this queue.clear in interface SequencedDeadLetterQueue<M extends Message<?>>Copyright © 2010–2023. All rights reserved.