Class ThrottledAccumulatingConsumer

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.util.function.Consumer<java.lang.Long>

    public class ThrottledAccumulatingConsumer
    extends java.lang.Object
    implements java.util.function.Consumer<java.lang.Long>, java.io.Closeable
    Wraps a Consumer<Long> so that multiple consume calls (accept(java.lang.Long)) within a short period of time are merged into a single later call with the value accumulated up to that point.
    • Constructor Summary

      Constructors 
      Constructor Description
      ThrottledAccumulatingConsumer​(java.util.function.Consumer<java.lang.Long> callback)
      Wraps a consumer with the delay of 100 ms.
      ThrottledAccumulatingConsumer​(java.util.function.Consumer<java.lang.Long> consumer, java.time.Duration delayBetweenCallbacks, java.util.function.Supplier<java.time.Instant> getNow)
      A new configured consumer.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void accept​(java.lang.Long value)  
      void close()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.function.Consumer

        andThen
    • Constructor Detail

      • ThrottledAccumulatingConsumer

        public ThrottledAccumulatingConsumer​(java.util.function.Consumer<java.lang.Long> callback)
        Wraps a consumer with the delay of 100 ms.
        Parameters:
        callback - Consumer callback to wrap
      • ThrottledAccumulatingConsumer

        public ThrottledAccumulatingConsumer​(java.util.function.Consumer<java.lang.Long> consumer,
                                             java.time.Duration delayBetweenCallbacks,
                                             java.util.function.Supplier<java.time.Instant> getNow)
        A new configured consumer.
        Parameters:
        consumer - Consumer callback to wrap
        delayBetweenCallbacks - delay between each call to the underlying accept
        getNow - supplies of the current time Instant
    • Method Detail

      • accept

        public void accept​(java.lang.Long value)
        Specified by:
        accept in interface java.util.function.Consumer<java.lang.Long>
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable