Package com.nuix.superutilities.misc
Class PeriodicGatedConsumer<T>
- java.lang.Object
-
- com.nuix.superutilities.misc.PeriodicGatedConsumer<T>
-
- Type Parameters:
T
- The type of theConsumer
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 aConsumer
instance which will only periodically forward call toaccept
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 intervalvoid
acceptImmediately(T t)
Will immediately forward call to wrapped Consumer and then reset current intervalvoid
setIntervalMinutes(long intervalMinutes)
Convenience method for setting millis interval to a certain number of minutesvoid
setIntervalSeconds(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:
accept
in 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
-
-