java.lang.Object
net.i2p.util.SimpleTimer2.TimedEvent
net.i2p.router.tasks.MarkLiveliness
All Implemented Interfaces:
Runnable

public class MarkLivelinessextends SimpleTimer2.TimedEvent
Router instance liveliness marker for multi-instance detection.

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 Details

    • _router

      private final Router _router
      The router whose liveliness is marked.
    • _pingFile

      private final File _pingFile
      File rewritten to mark the router alive.
    • _period

      private final long _period
      How often the ping file is written, in ms.
    • _errorLogged

      private volatile boolean _errorLogged
      True once a write failure has been logged.
  • Constructor Details

    • MarkLiveliness

      public MarkLiveliness(Router router, File pingFile, long period)
      Create a new liveliness marker.
      Parameters:
      router - the router, whose context supplies the simple timer
      pingFile - the file to write timestamps to
      period - how often to ping (ms)
  • 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:
      timeReached in class SimpleTimer2.TimedEvent
    • ping

      private void ping()
      Writes the ping file.