Package aQute.lib.concurrent.serial
Class TriggerRepeat
- java.lang.Object
-
- aQute.lib.concurrent.serial.TriggerRepeat
-
public class TriggerRepeat extends java.lang.Object
Trigger an action and repeat it as long as it keeps being triggered. General purpose is to start a background thread but let it keep repeating until there no more triggers were received in the mean time.For example, you detect a change in the file system and then need to synchronize a persistent structure. The
trigger()
call will return the true the first time, indicating that a background thread should be started. The background tasks does it works and checks thedoit()
at the end. If it returns true, it restarts, else it returns.
-
-
Constructor Summary
Constructors Constructor Description TriggerRepeat()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
doit()
Query if the action should be executed.boolean
trigger()
Trigger the action, returns true if there was no action.
-
-
-
Method Detail
-
trigger
public boolean trigger()
Trigger the action, returns true if there was no action.- Returns:
- true if there was no action
-
doit
public boolean doit()
Query if the action should be executed. The action should be executed if there are have been more trigger() calls after the doit() call. After this call, triggers == doits. I.e. it coalesces multiple triggers.- Returns:
- true of the the triggers != dots
-
-