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_PREFIX |
static FileFilter |
RI_FILTER |
_context, _log| Constructor and Description |
|---|
PersistentDataStore(RouterContext ctx,
String dbDir,
KademliaNetworkDatabaseFacade facade) |
| Modifier and Type | Method and Description |
|---|---|
int |
countStoredRIs()
Count the number of RouterInfo files currently stored on disk.
|
boolean |
enableReverseLookups() |
boolean |
forcePut(Hash key,
DatabaseEntry data) |
DatabaseEntry |
get(Hash key)
Retrieve the database entry for the given key.
|
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) |
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 the entry for the given key.
|
DatabaseEntry |
remove(Hash key,
boolean persist)
for PersistentDataStore only - don't use here
|
void |
rescan()
Rescan the storage for any changes.
|
void |
stop()
Stop the data store and release resources.
|
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
dbDir - relative pathIOExceptionpublic int countStoredRIs()
public boolean enableReverseLookups()
enableReverseLookups in class TransientDataStorepublic boolean forcePut(Hash key, DatabaseEntry data)
forcePut in interface DataStoreforcePut in class TransientDataStorepublic DatabaseEntry get(Hash key)
DataStoreget 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)
static Hash getRouterInfoHash(String filename)
public boolean isInitialized()
DataStoreisInitialized in interface DataStoreisInitialized in class TransientDataStorepublic static boolean isShuttingDown(RouterContext ctx)
public 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)
DataStoreremove 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()
DataStorerescan in interface DataStorerescan in class TransientDataStorepublic void stop()
DataStorestop in interface DataStorestop in class TransientDataStore