Class StallingBatchInterceptor
java.lang.Object
io.fluxcapacitor.javaclient.tracking.StallingBatchInterceptor
- All Implemented Interfaces:
BatchInterceptor
A
BatchInterceptor
that stalls batch processing until a minimum desired batch size is reached or a timeout occurs.
This interceptor helps regulate the trade-off between **throughput** and **latency** by introducing intentional delays when batches are too small. It’s especially useful in cases where:
- Handlers benefit from larger batches (e.g., bulk writes, deduplication, aggregation)
- The event rate is low and batching is desirable
Behavior
- If the batch size is greater than or equal to
desiredBatchSize
, it is processed immediately. - If the batch size is too small:
- The interceptor delays processing using
Thread.sleep
in intervals ofretryFrequency
. - Once
maximumStallingDuration
has elapsed since the first refusal, the batch is processed regardless of size.
- The interceptor delays processing using
Usage Considerations
- This interceptor causes blocking in the tracker thread. It is meant for controlled environments where latency can be traded for efficiency.
- It is thread-safe and maintains its own internal stall timer across batches using an
AtomicReference
.
Example Usage
ConsumerConfiguration.builder()
.name("batchedHandler")
.batchInterceptor(StallingBatchInterceptor.builder()
.desiredBatchSize(100)
.maximumStallingDuration(Duration.ofSeconds(30))
.retryFrequency(Duration.ofMillis(500))
.build())
.build();
Defaults
desiredBatchSize
= 512maximumStallingDuration
= 60 secondsretryFrequency
= 1 second
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
intercept
(Consumer<MessageBatch> consumer, Tracker tracker) Intercepts the given batch message consumer and returns a decorated version to be invoked by the tracker.protected void
stall()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.javaclient.tracking.BatchInterceptor
andThen, shutdown
-
Constructor Details
-
StallingBatchInterceptor
public StallingBatchInterceptor()
-
-
Method Details
-
intercept
Description copied from interface:BatchInterceptor
Intercepts the given batch message consumer and returns a decorated version to be invoked by the tracker.- Specified by:
intercept
in interfaceBatchInterceptor
- Parameters:
consumer
- the original consumer that processes theMessageBatch
tracker
- the tracker invoking this interceptor- Returns:
- a wrapped consumer with additional behavior
-
hasPassedDeadline
protected boolean hasPassedDeadline() -
stall
protected void stall()
-