public class Resequencer<T>
extends java.lang.Object
Resequencer allows claimants to ensure proper ordering of replies by allocating long values from a
counter. When the claimant is ready to publish the results of the operation, it calls accept(long, Object),
passing the slot number it claimed in addition to the value being published. The Resequencer will ensure
that out-of-order replies are re-ordered by the claimed slot number and later replies are queued and only passed to
the configured Consumer once the earlier replies have been published.| Constructor and Description |
|---|
Resequencer(Consumer<T> delegate)
Create a
Resequencer that delegates to the given Consumer. |
Resequencer(Consumer<T> delegate,
long maxBacklog)
Create a
Resequencer that delegates to the given Consumer. |
| Modifier and Type | Method and Description |
|---|---|
void |
accept(long slot,
T t)
Accept and possibly queue a value for the given
slot. |
long |
next() |
public Resequencer(@Nonnull
Consumer<T> delegate)
Resequencer that delegates to the given Consumer.delegate - the Consumer to delegate values to.public Resequencer(@Nonnull
Consumer<T> delegate,
long maxBacklog)
Resequencer that delegates to the given Consumer. Only queue maxBacklog number of items before throwing an exception.delegate - the Consumer to delegate values to.maxBacklog - the maximum number of items to queue in the backlog waiting on an earlier reply.public void accept(long slot,
T t)
slot.slot - the slot id this value is a reply for.t - the value to publish.public long next()