Class PeriodicGatedConsumer<T>

  • Type Parameters:
    T - The type of the Consumer being wrapped
    All Implemented Interfaces:
    java.util.function.Consumer<T>

    public class PeriodicGatedConsumer<T>
    extends java.lang.Object
    implements java.util.function.Consumer<T>
    A wrapper for a Consumer instance which will only periodically forward call to accept method of wrapped instance. Created for taking frequent events that are published and turning them into periodic progress reporters.
    • Constructor Summary

      Constructors 
      Constructor Description
      PeriodicGatedConsumer​(@NotNull java.util.function.Consumer<T> wrappedConsumer)  
      PeriodicGatedConsumer​(@NotNull java.util.function.Consumer<T> wrappedConsumer, long intervalMillis)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void accept​(T t)
      Will periodically forward call to wrapped Consumer and then reset current interval
      void acceptImmediately​(T t)
      Will immediately forward call to wrapped Consumer and then reset current interval
      void setIntervalMinutes​(long intervalMinutes)
      Convenience method for setting millis interval to a certain number of minutes
      void setIntervalSeconds​(long intervalSeconds)
      Convenience method for setting millis interval to a certain number of seconds
      • 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

      • PeriodicGatedConsumer

        public PeriodicGatedConsumer​(@NotNull
                                     @NotNull java.util.function.Consumer<T> wrappedConsumer)
      • PeriodicGatedConsumer

        public PeriodicGatedConsumer​(@NotNull
                                     @NotNull java.util.function.Consumer<T> wrappedConsumer,
                                     long intervalMillis)
    • Method Detail

      • setIntervalSeconds

        public void setIntervalSeconds​(long intervalSeconds)
        Convenience method for setting millis interval to a certain number of seconds
        Parameters:
        intervalSeconds - The number of seconds
      • setIntervalMinutes

        public void setIntervalMinutes​(long intervalMinutes)
        Convenience method for setting millis interval to a certain number of minutes
        Parameters:
        intervalMinutes - The number of minutes
      • accept

        public void accept​(T t)
        Will periodically forward call to wrapped Consumer and then reset current interval
        Specified by:
        accept in interface java.util.function.Consumer<T>
        Parameters:
        t - the input argument
      • acceptImmediately

        public void acceptImmediately​(T t)
        Will immediately forward call to wrapped Consumer and then reset current interval
        Parameters:
        t - the input argument