java.lang.Object
net.i2p.router.JobImpl
net.i2p.router.networkdb.kademlia.PersistentDataStore.ReadJob
- All Implemented Interfaces:
Job
- Enclosing class:
PersistentDataStore
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
FieldsModifier and TypeFieldDescriptionprivate longLast modified time.private longLast reseed time.private booleanNetdb ready flag.private booleanWhether the initial scan has completed at least once.private static final longMinimum time between automatic reseed attempts.private static final intMinimum routers before netdb is considered ready.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionprivate voidcheckReseed(int routerCount) Decide whether to reseed based on router count and time since last reseed.getName()Descriptive name of the task.booleanWhether the netdb has enough routers to be usable.private voidRead all RouterInfo files from disk into memory.private intreadFlatFiles(File[] routerInfoFiles) Read RouterInfo files from the flat (non-subdirectory) layout.private intreadHierarchicalFiles(File[] routerInfoFiles) Read RouterInfo files from the hierarchical (subdirectory) layout.voidrunJob()Scan for new RouterInfo files, then reschedule.private booleanCheck if the netdb directory or any subdirectory has been modified since the last scan, or if we need to check for reseed.voidwakeup()Trigger an immediate rescan.Methods inherited from class JobImpl
dropped, getContext, getJobId, getMadeReadyOn, getTiming, madeReady, requeue, toStringModifier and TypeMethodDescriptionvoiddropped()Default implementation does nothing.final RouterContextThe router context that this job belongs to.longgetJobId()The unique job ID for this job.longThe timestamp when this job was last made ready for execution.The timing object for this job.voidmadeReady(long now) For JobQueue only, not for external use.protected voidrequeue(long delayMs) Requeue this job to run after the specified delay.toString()
Field Details
_lastModified
private volatile long _lastModifiedLast modified time._lastReseed
private volatile long _lastReseedLast reseed time._setNetDbReady
private volatile boolean _setNetDbReadyNetdb ready flag.MIN_ROUTERS
private static final int MIN_ROUTERSMinimum routers before netdb is considered ready.- See Also:
MIN_RESEED_INTERVAL
private static final long MIN_RESEED_INTERVALMinimum time between automatic reseed attempts.- See Also:
hasRun
private volatile boolean hasRunWhether the initial scan has completed at least once.
Constructor Details
ReadJob
public ReadJob()Job reading the stored entries at startup.
Method Details
getName
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
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
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