Class ProgressWatchdog
progress(long)); it says whether too long has passed since (stalled(long)).
What it proves. stalled is true only when at least stallMs of counted time has passed with
no progress call. Time spent held (a pause, a deliberate wait, a
forced-move hold) is not counted, so a bot that was told to stand still is not "stuck". It proves silence, not
cause: what to do about it is yours.
Unreadable. It reads no client; every time comes from you. Before the first call it counts as zero idle
time (never stalled), because a watch that has seen nothing cannot say how long nothing has happened. Pass a
monotonic clock (System.currentTimeMillis() is fine); a clock that goes backwards counts as zero.
Thread. Pure and not thread safe: call it from the one thread that runs your tick.
Lifted from AutoSlayer's stuck recovery (30 s without progress).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidheld(boolean holding, long nowMs) Starts or ends a hold.longidleMs(long nowMs) voidprogress(long nowMs) Something useful happened atnowMs: the idle clock restarts.voidreset(long nowMs) Starts over atnowMs: no idle time and no hold.booleanstalled(long nowMs)
-
Constructor Details
-
ProgressWatchdog
public ProgressWatchdog(long stallMs) - Parameters:
stallMs- counted idle time after whichstalled(long)is true (AutoSlayer used 30000)
-
-
Method Details
-
progress
public void progress(long nowMs) Something useful happened atnowMs: the idle clock restarts. -
held
public void held(boolean holding, long nowMs) Starts or ends a hold. Held time is not counted as idle. Repeating the current state changes nothing.- Parameters:
holding- true while the bot is deliberately waitingnowMs- the current time
-
idleMs
public long idleMs(long nowMs) - Returns:
- counted idle milliseconds since the last progress, never negative; 0 before any call
-
stalled
public boolean stalled(long nowMs) - Returns:
- whether counted idle time has reached the limit
-
reset
public void reset(long nowMs) Starts over atnowMs: no idle time and no hold.
-