Package aQute.lib.concurrent.serial
Class TriggerRepeat
java.lang.Object
aQute.lib.concurrent.serial.TriggerRepeat
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 the doit()
at
the end. If it returns true, it restarts, else it returns.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
triggers
int triggers -
doits
int doits
-
-
Constructor Details
-
TriggerRepeat
public TriggerRepeat()
-
-
Method Details
-
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
-