public class BatchingConsumer<K,I>
extends java.lang.Object
items via its accept()
method. It consumes them in 'chunks' of one or multiple items at a time. The
following properties can be set for each key to govern this behaviour (higher
up on this list is more imporant):
consumeFirst (boolean): if set, the filter consumes the
accepted item immediately if there is not yet a batch for that key. However,
the batch is created and subsequent items with the same key are collected in
the batch.maxBatchAge (Duration): the whole batch cannot become older
than this value. When it is reached, the whole batch is consumed.minChunkInterval (Duration): wait at least for this duration
between chunksmaxItemInterval (Duration): consume the current chunk when
the instant the last item was accepted is longer ago than this value.maxBatchSize (integer): consume whole batch if its size has
reached this value| Modifier and Type | Class and Description |
|---|---|
static class |
BatchingConsumer.Config |
static class |
BatchingConsumer.ConfigBuilder |
| Constructor and Description |
|---|
BatchingConsumer() |
BatchingConsumer(BatchingConsumer.Config config) |
| Modifier and Type | Method and Description |
|---|---|
void |
accept(K key,
I item,
java.util.function.Consumer<java.util.Collection<I>> consumer) |
void |
accept(K key,
I item,
java.util.function.Consumer<java.util.Collection<I>> consumer,
BatchingConsumer.Config config) |
void |
accept(K key,
I item,
java.util.Optional<java.lang.String> deduplicationKey,
java.util.function.Consumer<java.util.Collection<I>> consumer,
java.util.Optional<BatchingConsumer.Config> config)
Offer an item to the BatchingConsumer, providing an optional
deduplicationKey, a consumer and an optional config.
|
void |
accept(K key,
I item,
java.lang.String deduplicationKey,
java.util.function.Consumer<java.util.Collection<I>> consumer) |
void |
accept(K key,
I item,
java.lang.String deduplicationKey,
java.util.function.Consumer<java.util.Collection<I>> consumer,
BatchingConsumer.Config config) |
void |
cancelBatch(K key)
Removes the batch, the consumer is not invoked.
|
void |
consumeAllBatches()
Invokes the consumers for all batches immediately and removes all batches.
|
public BatchingConsumer()
public BatchingConsumer(BatchingConsumer.Config config)
public void accept(K key, I item, java.util.function.Consumer<java.util.Collection<I>> consumer)
public void accept(K key, I item, java.util.function.Consumer<java.util.Collection<I>> consumer, BatchingConsumer.Config config)
public void accept(K key, I item, java.lang.String deduplicationKey, java.util.function.Consumer<java.util.Collection<I>> consumer)
public void accept(K key, I item, java.lang.String deduplicationKey, java.util.function.Consumer<java.util.Collection<I>> consumer, BatchingConsumer.Config config)
public void accept(K key, I item, java.util.Optional<java.lang.String> deduplicationKey, java.util.function.Consumer<java.util.Collection<I>> consumer, java.util.Optional<BatchingConsumer.Config> config)
key - item - consumer - config - public void consumeAllBatches()
public void cancelBatch(K key)
key - Copyright © 2020. All Rights Reserved.