net.i2p.router.networkdb.kademlia

## Class PersistentDataStore

- java.lang.Object
- - net.i2p.router.networkdb.kademlia.TransientDataStore
  - - net.i2p.router.networkdb.kademlia.PersistentDataStore

- All Implemented Interfaces:
    DataStore

      public class PersistentDataStore
      extends TransientDataStore

  Persistent network database storage with disk I/O and memory management.

  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.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `(package private) static String` | `DIR_PREFIX`
    `static FileFilter` | `RI_FILTER`

    - ### Fields inherited from class net.i2p.router.networkdb.kademlia.TransientDataStore

      `_context, _log`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PersistentDataStore(RouterContext ctx, String dbDir, KademliaNetworkDatabaseFacade facade)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    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.

    - ### Methods inherited from class net.i2p.router.networkdb.kademlia.TransientDataStore

      `countLeaseSets, getEntries, getKeys, getMapEntries, isKnown, size, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### DIR_PREFIX

          static final String DIR_PREFIX

      See Also:
        Constant Field Values

    - #### RI_FILTER

          public static final FileFilter RI_FILTER

  - ### Constructor Detail

    - #### PersistentDataStore

          public PersistentDataStore(RouterContext ctx,
                                     String dbDir,
                                     KademliaNetworkDatabaseFacade facade)
                              throws IOException

      Parameters:
        `dbDir` - relative path
      Throws:
        `IOException`

  - ### Method Detail

    - #### countStoredRIs

          public int countStoredRIs()

      Count the number of RouterInfo files currently stored on disk. This includes files in subdirectories if not using flat mode.
      Returns:
        number of RI files on disk

    - #### enableReverseLookups

          public boolean enableReverseLookups()

      Overrides:
        `enableReverseLookups` in class `TransientDataStore`

    - #### forcePut

          public boolean forcePut(Hash key,
                                  DatabaseEntry data)

      Specified by:
        `forcePut` in interface `DataStore`
      Overrides:
        `forcePut` in class `TransientDataStore`

    - #### get

          public DatabaseEntry get(Hash key)

      Description copied from interface: `DataStore`
      Retrieve the database entry for the given key.
      Specified by:
        `get` in interface `DataStore`
      Overrides:
        `get` in class `TransientDataStore`
      Parameters:
        `key` - the hash key to look up
      Returns:
        the database entry, or null if not found

    - #### get

          public DatabaseEntry get(Hash key,
                                   boolean persist)

      Prepare for having only a partial set in memory and the rest on disk
      Specified by:
        `get` in interface `DataStore`
      Overrides:
        `get` in class `TransientDataStore`
      Parameters:
        `persist` - if false, call super only, don't access disk
        `key` - the hash key to look up
      Returns:
        the database entry, or null if not found

    - #### getRouterInfoFile

          public static File getRouterInfoFile(RouterContext ctx,
                                               Hash hash)

      The persistent RI file for a hash. This is available before the netdb subsystem is running, so we can delete our old RI.
      Returns:
        non-null, should be absolute, does not necessarily exist

    - #### getRouterInfoHash

          static Hash getRouterInfoHash(String filename)

      Package private for installer BundleRouterInfos

    - #### isInitialized

          public boolean isInitialized()

      Description copied from interface: `DataStore`
      Check if the data store has been initialized.
      Specified by:
        `isInitialized` in interface `DataStore`
      Overrides:
        `isInitialized` in class `TransientDataStore`
      Returns:
        true if the store is ready for operations

    - #### isShuttingDown

          public static boolean isShuttingDown(RouterContext ctx)

    - #### put

          public boolean put(Hash key,
                             DatabaseEntry data)

      Description copied from interface: `DataStore`
      Store a database entry with the given key.
      Specified by:
        `put` in interface `DataStore`
      Overrides:
        `put` in class `TransientDataStore`
      Parameters:
        `key` - the hash key to store under
        `data` - must be validated before here
      Returns:
        success

    - #### put

          public boolean put(Hash key,
                             DatabaseEntry data,
                             boolean persist)

      Description copied from class: `TransientDataStore`
      for PersistentDataStore only - don't use here
      Specified by:
        `put` in interface `DataStore`
      Overrides:
        `put` in class `TransientDataStore`
      Parameters:
        `key` - the hash key to store under
        `data` - the database entry to store
        `persist` - if true, keep the entry in persistent storage
      Returns:
        true if the store was successful

    - #### remove

          public DatabaseEntry remove(Hash key)

      Description copied from interface: `DataStore`
      Remove the entry for the given key.
      Specified by:
        `remove` in interface `DataStore`
      Overrides:
        `remove` in class `TransientDataStore`
      Parameters:
        `key` - the hash key to remove
      Returns:
        the removed database entry, or null if not found

    - #### remove

          public DatabaseEntry remove(Hash key,
                                      boolean persist)

      Description copied from class: `TransientDataStore`
      for PersistentDataStore only - don't use here
      Specified by:
        `remove` in interface `DataStore`
      Overrides:
        `remove` in class `TransientDataStore`
      Parameters:
        `key` - the hash key to remove
        `persist` - if true, also remove from persistent storage
      Returns:
        the removed database entry, or null if not found

    - #### rescan

          public void rescan()

      Description copied from interface: `DataStore`
      Rescan the storage for any changes.
      Specified by:
        `rescan` in interface `DataStore`
      Overrides:
        `rescan` in class `TransientDataStore`

    - #### stop

          public void stop()

      Description copied from interface: `DataStore`
      Stop the data store and release resources.
      Specified by:
        `stop` in interface `DataStore`
      Overrides:
        `stop` in class `TransientDataStore`