- All Implemented Interfaces:
Runnable
This class periodically writes a timestamp to a "ping file" to indicate that this router instance is alive and running. Other router instances attempting to use the same configuration directory can check this file to detect if another instance is already active.
Purpose:
- Prevent multiple router instances using same config
- Allow detection of active router instances
- Provide timestamp-based liveliness indication
- Support automatic cleanup on router shutdown
Behavior:
- Updates timestamp periodically while router is alive
- Deletes ping file when router shuts down
- Logs errors only once to prevent log spam
- Uses secure file writing for atomic updates
The ping file contains only the current timestamp in milliseconds since epoch. Other instances can check the file age to determine if the router is recently active or abandoned.
Field Summary
FieldsFields inherited from class SimpleTimer2.TimedEvent
_state, DEFAULT_FUZZModifier and TypeFieldDescriptionprotected SimpleTimer2.TimedEventStateState of the current event.protected static final intDefault fuzz threshold in milliseconds.Constructor Summary
ConstructorsConstructorDescriptionMarkLiveliness(Router router, File pingFile, long period) Create a new liveliness marker.Method Summary
Modifier and TypeMethodDescriptionprivate voidping()Writes the ping file.voidUpdate the ping file with current timestamp if router is alive.Methods inherited from class SimpleTimer2.TimedEvent
cancel, forceReschedule, reschedule, reschedule, run, schedule, setFuzz, setPool, toStringModifier and TypeMethodDescriptionbooleancancel()Cancel the timed event.voidforceReschedule(long timeoutMs) Always use the new time - ignores fuzz.voidreschedule(long timeoutMs) Use the earliest of the new time and the old time May be called from within timeReached(), but schedule() is better there.voidreschedule(long timeoutMs, boolean useEarliestTime) May be called from within timeReached(), but schedule() is better there.voidrun()voidschedule(long timeoutMs) Schedule this event.voidsetFuzz(int fuzz) Reschedule threshold in ms.voidsetPool(SimpleTimer2 pool) Timer pool for this event.toString()Timer summary for log messages.
Field Details
_router
The router whose liveliness is marked._pingFile
File rewritten to mark the router alive._period
private final long _periodHow often the ping file is written, in ms._errorLogged
private volatile boolean _errorLoggedTrue once a write failure has been logged.
Constructor Details
MarkLiveliness
Method Details
timeReached
public void timeReached()Update the ping file with current timestamp if router is alive.If the router is alive, writes the current timestamp to the ping file. If the router is not alive, deletes the ping file to indicate that this router instance is no longer running.
The ping file allows other router instances using the same configuration to detect if another instance is already running.
- Specified by:
timeReachedin classSimpleTimer2.TimedEvent
ping
private void ping()Writes the ping file.