public class PersistentDataStore extends TransientDataStore
Writes RouterInfo entries to disk as received and periodically scans for unknown entries to load into memory. Newly discovered routers are automatically added to the routing table. Implements both flat and hierarchical directory structures for efficient file organization and access.
Public only for access to static methods by startup classes.
| Modifier and Type | Field and Description |
|---|---|
(package private) static String | DIR_PREFIXDirectory prefix for netDb files. |
static FileFilter | RI_FILTERFile filter for RouterInfo files. |
_context, _log| Constructor and Description |
|---|
PersistentDataStore(RouterContext ctx,
String dbDir,
KademliaNetworkDatabaseFacade facade)Creates a new persistent data store. |
| Modifier and Type | Method and Description |
|---|---|
int | countStoredRIs()Count the number of RouterInfo files currently stored on disk. |
boolean | forcePut(Hash key,
DatabaseEntry data)Unconditionally store, bypass all newer/older checks. |
DatabaseEntry | get(Hash key)The entry for the key, or null if not found. |
DatabaseEntry | get(Hash key,
boolean persist)Prepare for having only a partial set in memory and the rest on disk |
static File | getRouterInfoFile(RouterContext ctx,
Hash hash)The persistent RI file for a hash. |
(package private) static Hash | getRouterInfoHash(String filename)Package private for installer BundleRouterInfos |
boolean | isInitialized()Whether the data store is initialized. |
static boolean | isShuttingDown(RouterContext ctx)Check if the router is in a graceful or hard shutdown state. |
boolean | put(Hash key,
DatabaseEntry data)Store a database entry with the given key. |
boolean | put(Hash key,
DatabaseEntry data,
boolean persist)For PersistentDataStore only - don't use here. |
DatabaseEntry | remove(Hash key)Remove and return the entry for the key. |
DatabaseEntry | remove(Hash key,
boolean persist)For PersistentDataStore only - don't use here. |
void | rescan()No-op - the in-memory store has no external state to rescan. |
void | stop()Clear the in-memory store. |
countLeaseSets, getEntries, getKeys, getMapEntries, isKnown, size, toStringstatic final String DIR_PREFIX
public static final FileFilter RI_FILTER
public PersistentDataStore(RouterContext ctx, String dbDir, KademliaNetworkDatabaseFacade facade) throws IOException
ctx - the router contextdbDir - relative pathfacade - the network database facadeIOException - if the database directory cannot be created or accessedpublic int countStoredRIs()
public boolean forcePut(Hash key, DatabaseEntry data)
TransientDataStoreforcePut in interface DataStoreforcePut in class TransientDataStorekey - non-nulldata - non-nullpublic DatabaseEntry get(Hash key)
TransientDataStoreget in interface DataStoreget in class TransientDataStorekey - the hash to look uppublic DatabaseEntry get(Hash key, boolean persist)
get in interface DataStoreget in class TransientDataStorepersist - if false, call super only, don't access diskkey - the hash key to look uppublic static File getRouterInfoFile(RouterContext ctx, Hash hash)
ctx - the router contexthash - the router hashstatic Hash getRouterInfoHash(String filename)
public boolean isInitialized()
TransientDataStoreisInitialized in interface DataStoreisInitialized in class TransientDataStorepublic static boolean isShuttingDown(RouterContext ctx)
ctx - the router contextpublic boolean put(Hash key, DatabaseEntry data)
DataStoreput in interface DataStoreput in class TransientDataStorekey - the hash key to store underdata - must be validated before herepublic boolean put(Hash key, DatabaseEntry data, boolean persist)
TransientDataStoreput in interface DataStoreput in class TransientDataStorekey - the hash key to store underdata - the database entry to storepersist - if true, keep the entry in persistent storagepublic DatabaseEntry remove(Hash key)
TransientDataStoreremove in interface DataStoreremove in class TransientDataStorekey - the hash to removepublic DatabaseEntry remove(Hash key, boolean persist)
TransientDataStoreremove in interface DataStoreremove in class TransientDataStorekey - the hash key to removepersist - if true, also remove from persistent storagepublic void rescan()
TransientDataStorerescan in interface DataStorerescan in class TransientDataStorepublic void stop()
TransientDataStorestop in interface DataStorestop in class TransientDataStore