Package com.nuix.superutilities.misc
Class PeriodicGatedConsumer<T>
- java.lang.Object
-
- com.nuix.superutilities.misc.PeriodicGatedConsumer<T>
-
- Type Parameters:
T- The type of theConsumerbeing 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 aConsumerinstance which will only periodically forward call toacceptmethod 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 voidaccept(T t)Will periodically forward call to wrapped Consumer and then reset current intervalvoidacceptImmediately(T t)Will immediately forward call to wrapped Consumer and then reset current intervalvoidsetIntervalMinutes(long intervalMinutes)Convenience method for setting millis interval to a certain number of minutesvoidsetIntervalSeconds(long intervalSeconds)Convenience method for setting millis interval to a certain number of seconds
-
-
-
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:
acceptin interfacejava.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
-
-