java.lang.Object
net.i2p.router.JobImpl
net.i2p.router.networkdb.kademlia.PersistentDataStore.ReadJob
All Implemented Interfaces:
Job
Enclosing class:
PersistentDataStore

private class PersistentDataStore.ReadJobextends JobImpl
This was mostly for manual reseeding, i.e. the user manually copies RI files to the directory. Nobody does this, so this is run way too often.

But it's also for migrating and reading the files after a reseed. Reseed task calls wakeup() on completion. As of 0.9.4, also initiates an automatic reseed if necessary.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private long
    Last modified time.
    private long
    Last reseed time.
    private boolean
    Netdb ready flag.
    private boolean
    Whether the initial scan has completed at least once.
    private static final long
    Minimum time between automatic reseed attempts.
    private static final int
    Minimum routers before netdb is considered ready.

    Fields inherited from class JobImpl

    _id
    Modifier and Type
    Field
    Description
    final long
    Unique job identifier.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Job reading the stored entries at startup.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    checkReseed(int routerCount)
    Decide whether to reseed based on router count and time since last reseed.
    Descriptive name of the task.
    boolean
    Whether the netdb has enough routers to be usable.
    private void
    Read all RouterInfo files from disk into memory.
    private int
    readFlatFiles(File[] routerInfoFiles)
    Read RouterInfo files from the flat (non-subdirectory) layout.
    private int
    readHierarchicalFiles(File[] routerInfoFiles)
    Read RouterInfo files from the hierarchical (subdirectory) layout.
    void
    Scan for new RouterInfo files, then reschedule.
    private boolean
    Check if the netdb directory or any subdirectory has been modified since the last scan, or if we need to check for reseed.
    void
    Trigger an immediate rescan.

    Methods inherited from class JobImpl

    dropped, getContext, getJobId, getMadeReadyOn, getTiming, madeReady, requeue, toString
    Modifier and Type
    Method
    Description
    void
    Default implementation does nothing.
    The router context that this job belongs to.
    long
    The unique job ID for this job.
    long
    The timestamp when this job was last made ready for execution.
    The timing object for this job.
    void
    madeReady(long now)
    For JobQueue only, not for external use.
    protected void
    requeue(long delayMs)
    Requeue this job to run after the specified delay.
     

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • _lastModified

      private volatile long _lastModified
      Last modified time.
    • _lastReseed

      private volatile long _lastReseed
      Last reseed time.
    • _setNetDbReady

      private volatile boolean _setNetDbReady
      Netdb ready flag.
    • MIN_ROUTERS

      private static final int MIN_ROUTERS
      Minimum routers before netdb is considered ready.
      See Also:
    • MIN_RESEED_INTERVAL

      private static final long MIN_RESEED_INTERVAL
      Minimum time between automatic reseed attempts.
      See Also:
    • hasRun

      private volatile boolean hasRun
      Whether the initial scan has completed at least once.
  • Constructor Details

    • ReadJob

      public ReadJob()
      Job reading the stored entries at startup.
  • Method Details

    • getName

      public String getName()
      Description copied from interface: Job
      Descriptive name of the task.
      Returns:
      the descriptive name of the task
    • shouldScan

      private boolean shouldScan()
      Check if the netdb directory or any subdirectory has been modified since the last scan, or if we need to check for reseed.
      Returns:
      true if the netdb directory or a subdirectory has changed, the stored routers are too few, or a reseed is due
    • checkReseed

      private void checkReseed(int routerCount)
      Decide whether to reseed based on router count and time since last reseed.
      Parameters:
      routerCount - the number of RouterInfo files loaded, passed to the reseed checker
    • runJob

      public void runJob()
      Scan for new RouterInfo files, then reschedule. The first run comes soon after startup; later runs use the full read interval.
    • wakeup

      public void wakeup()
      Trigger an immediate rescan.
    • isNetDbReady

      public boolean isNetDbReady()
      Whether the netdb has enough routers to be usable.
      Returns:
      true once the netdb has enough routers to be usable
    • readFiles

      private void readFiles()
      Read all RouterInfo files from disk into memory. Handles both flat and hierarchical directory layouts. Must be called under synchronized(_dbDir).
    • readFlatFiles

      private int readFlatFiles(File[] routerInfoFiles)
      Read RouterInfo files from the flat (non-subdirectory) layout.
      Parameters:
      routerInfoFiles - the files listed from the root directory; null means there was nothing to read
      Returns:
      total router count
    • readHierarchicalFiles

      private int readHierarchicalFiles(File[] routerInfoFiles)
      Read RouterInfo files from the hierarchical (subdirectory) layout. Migrates root-level files, shuffles to avoid load bias, and triggers intermediate netdbReady events on slow systems.
      Parameters:
      routerInfoFiles - root-level RouterInfo files to migrate into the subdirectories, may be null
      Returns:
      total router count