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_PREFIXD i r p r e f i x |
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 | enableReverseLookups()enableReverseLookups. |
boolean | forcePut(Hash key,
DatabaseEntry data)forcePut. |
DatabaseEntry | get(Hash key)get. |
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()Check if the data store has been 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. |
DatabaseEntry | remove(Hash key,
boolean persist)for PersistentDataStore only - don't use here |
void | rescan()rescan. |
void | stop()stop. |
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 enableReverseLookups()
TransientDataStoreenableReverseLookups in class TransientDataStorepublic boolean forcePut(Hash key, DatabaseEntry data)
TransientDataStoreforcePut in interface DataStoreforcePut in class TransientDataStorepublic DatabaseEntry get(Hash key)
TransientDataStoreget in interface DataStoreget in class TransientDataStorekey - the hash key 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()
DataStoreisInitialized 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 key 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