Class 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 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 flushes
        callback - The method to call when flushing. Will be called with an empty list when throttle is reset
        executor - The consumer used to schedule flushes
    • Method Detail

      • accept

        public void accept​(T o)
        Specified by:
        accept in interface Batcher<T>
      • flush

        public void flush()
        Specified by:
        flush in interface Batcher<T>
      • shutdown

        public void shutdown()