Class BaseCallback
java.lang.Object
com.tccc.kos.commons.util.concurrent.BaseCallback
- Direct Known Subclasses:
AdjustableCallback
,BackoffCallback
,PushPullCallback
,TriggeredCallback
Base class for various callback classes.
- Since:
- 1.0
- Version:
- 2022-10-12
-
Method Summary
Modifier and TypeMethodDescriptionboolean
cancel()
Cancels a pending callback.boolean
flush()
If the timer is running then the callback method is called in a background thread, otherwise no action is taken.boolean
If the timer is running, then the callback method is called while blocking in the current thread, otherwise no action is taken.void
force()
Forces the callback method to be called in a background thread, whether there's a pending timer or not.void
Forces the callback method to be called while blocking in the current thread, whether there's a pending timer or not.Returns the callback method set during object construction.long
Return the current wait time on the timer.boolean
Indicates if the internal timer is currently running or not.boolean
Indicates if the internal timer is currently stopped or not.
-
Method Details
-
getCallback
Returns the callback method set during object construction.- Returns:
- the callback method
-
isRunning
public boolean isRunning()Indicates if the internal timer is currently running or not.- Returns:
- true if the timer is currently running
-
isStopped
public boolean isStopped()Indicates if the internal timer is currently stopped or not.- Returns:
- true if the timer is currently stopped
-
cancel
public boolean cancel()Cancels a pending callback.If the timer is running, then it is cancelled, otherwise no action is taken.
- Returns:
- true if the timer was running, false if it was not
-
flush
public boolean flush()If the timer is running then the callback method is called in a background thread, otherwise no action is taken.If the timer is a one-shot then it is stopped, otherwise it's recurring and therefore the timer is restarted.
- Returns:
- true if the callback was actually called
-
flushInline
public boolean flushInline()If the timer is running, then the callback method is called while blocking in the current thread, otherwise no action is taken.If the timer is a one-shot, then it is stopped, otherwise it's recurring and therefore the timer is restarted.
- Returns:
- true if the callback was actually called
-
force
public void force()Forces the callback method to be called in a background thread, whether there's a pending timer or not.If the timer is pending then it is canceled, otherwise it's recurring, in which case it's restarted before the callback is called.
Similar to
flush()
except that the callback is always called. -
forceInline
public void forceInline()Forces the callback method to be called while blocking in the current thread, whether there's a pending timer or not.If the timer is pending then it is canceled, otherwise it's recurring, in which case it's restarted before the callback is called.
Similar to
flushInline()
except that the callback is always called. -
getWaitTime
public long getWaitTime()Return the current wait time on the timer. This is how long since the timer was started in milliseconds. If the timer is not running this returns -1.
-