Package etch

Class EtchStore


public class EtchStore extends AStore
Class implementing on-disk memory-mapped storage of Convex data. "There are only two hard things in Computer Science: cache invalidation and naming things." - Phil Karlton Objects are keyed by cryptographic hash. That solves naming. Objects are immutable. That solves cache invalidation. Garbage collection is left as an exercise for the reader.
  • Constructor Details

    • EtchStore

      public EtchStore(Etch etch)
  • Method Details

    • create

      public static EtchStore create(File file) throws IOException
      Creates an EtchStore using a specified file.
      Parameters:
      file - File to use for storage. Will be created it it does not already exist.
      Returns:
      EtchStore instance
      Throws:
      IOException - If an IO error occurs
    • createTemp

      public static EtchStore createTemp(String prefix)
      Create an Etch store using a new temporary file with the given prefix
      Parameters:
      prefix - String prefix for temporary file
      Returns:
      New EtchStore instance
    • createTemp

      public static EtchStore createTemp()
      Create an Etch store using a new temporary file with a generated prefix
      Returns:
      New EtchStore instance
    • refForHash

      public <T extends ACell> Ref<T> refForHash(Hash hash)
      Description copied from class: AStore
      Gets the stored Ref for a given hash value, or null if not found. If the result is non-null, the Ref will have a status equal to STORED at minimum. Calls to Ref.getValue() should therefore never throw MissingDataException.
      Specified by:
      refForHash in class AStore
      Parameters:
      hash - A hash value to look up in the persisted store
      Returns:
      The stored Ref, or null if the hash value is not persisted
    • storeRef

      public <T extends ACell> Ref<T> storeRef(Ref<T> ref, int status, Consumer<Ref<ACell>> noveltyHandler)
      Description copied from class: AStore
      Stores a @Ref in long term storage as defined by this store implementation. Will store nested Refs if required. Does not store embedded values. If it is necessary to persist an embedded value deliberately in the store, use storeTopRef(...) instead. If the persisted Ref represents novelty (i.e. not previously stored) Will call the provided noveltyHandler.
      Specified by:
      storeRef in class AStore
      Parameters:
      ref - A Ref to the given object. Should be either Direct or STORED at minimum to present risk of MissingDataException.
      status - Status to store at
      noveltyHandler - Novelty Handler function for Novelty detected. May be null.
      Returns:
      The persisted Ref, of status STORED at minimum
    • storeTopRef

      public <T extends ACell> Ref<T> storeTopRef(Ref<T> ref, int status, Consumer<Ref<ACell>> noveltyHandler)
      Description copied from class: AStore
      Stores a top level @Ref in long term storage as defined by this store implementation. Will store nested Refs if required. Will only store an embedded Ref if it is the top level item. If the persisted Ref represents novelty (i.e. not previously stored) Will call the provided noveltyHandler
      Specified by:
      storeTopRef in class AStore
      Parameters:
      ref - A Ref to the given object. Should be either Direct or STORED at minimum to present risk of MissingDataException.
      status - Status to store at
      noveltyHandler - Novelty Handler function for Novelty detected. May be null.
      Returns:
      The persisted Ref, of status STORED at minimum
    • storeRef

      public <T extends ACell> Ref<T> storeRef(Ref<T> ref, Consumer<Ref<ACell>> noveltyHandler, int requiredStatus, boolean topLevel)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getFileName

      public String getFileName()
      Gets the database file name for this EtchStore
      Returns:
      File name as a String
    • close

      public void close()
      Description copied from class: AStore
      Closes this store and frees associated resources
      Specified by:
      close in class AStore
    • flush

      public void flush() throws IOException
      Ensure the store is fully persisted to disk
      Throws:
      IOException - If an IO error occurs
    • getFile

      public File getFile()
    • getRootHash

      public Hash getRootHash() throws IOException
      Description copied from class: AStore
      Gets the Root Hash from the Store. Root hash is typically used to store the Peer state in situations where the Peer needs to be restored from persistent storage.
      Specified by:
      getRootHash in class AStore
      Returns:
      Root hash value from this store.
      Throws:
      IOException - In case of store IO error
    • setRootHash

      public void setRootHash(Hash h) throws IOException
      Description copied from class: AStore
      Sets the root hash for this Store
      Specified by:
      setRootHash in class AStore
      Parameters:
      h - Root Hash to set
      Throws:
      IOException - In case of store IO error
    • getEtch

      public Etch getEtch()
      Gets the underlying Etch instance
      Returns:
      Etch instance