Package org.logevents.observers.batch
Class ThrottlingBatcher<T>
- java.lang.Object
-
- org.logevents.observers.batch.ThrottlingBatcher<T>
-
- Type Parameters:
T
- The type of objects to batch
- All Implemented Interfaces:
Batcher<T>
public class ThrottlingBatcher<T> extends Object implements Batcher<T>
Batches up all accepted object according to the throttling strategy. E.g. PT0S PT1M PT10M PT30M will process the first object immediately, then batch up any objects for the next minute. If any objects were received during this interval, then all object for the next ten minutes will be batched. Resets back to processing immediately if there were no objects in an interval.
-
-
Constructor Summary
Constructors Constructor Description ThrottlingBatcher(String throttles, Consumer<List<T>> callback, ScheduledExecutorService executor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(T o)
void
flush()
List<T>
getCurrentBatch()
void
shutdown()
-
-
-
Constructor Detail
-
ThrottlingBatcher
public ThrottlingBatcher(String throttles, Consumer<List<T>> callback, ScheduledExecutorService executor)
- Parameters:
throttles
- Durations as strings, e.g. "PT1M PT1H" for 0 seconds, 1 minute, 1 hour. Used to determine the time to wait for successive flushescallback
- The method to call when flushing. Will be called with an empty list when throttle is resetexecutor
- The consumer used to schedule flushes
-
-