Class FoundationKVDatabase

java.lang.Object
io.permazen.kv.fdb.FoundationKVDatabase
All Implemented Interfaces:
KVDatabase

public class FoundationKVDatabase extends Object implements KVDatabase
FoundationDB KVDatabase implementation.

Allows specifying a key prefix for all keys, allowing multiple independent databases. Key watches are supported.

See Also:
  • Field Details

    • API_VERSION

      public static final int API_VERSION
      The API version used by this class.
      See Also:
  • Constructor Details

    • FoundationKVDatabase

      public FoundationKVDatabase()
      Constructor.
      Throws:
      FDBException - if API_VERSION is not supported
  • Method Details

    • getNetworkOptions

      public NetworkOptions getNetworkOptions()
      Get the NetworkOptions associated with this instance. Options must be configured prior to start().
      Returns:
      network options
    • setExecutor

      public void setExecutor(Executor executor)
      Configure the Executor used for the FoundationDB networking event loop.

      By default, the default thread pool is used to execute the FoundationDB network.

      Parameters:
      executor - executor for networking activity
      See Also:
    • setClusterFilePath

      public void setClusterFilePath(String clusterFilePath)
      Configure the cluster file path. Default is null, which results in the default fdb.cluster file being used.
      Parameters:
      clusterFilePath - cluster file pathname
    • getKeyPrefix

      public byte[] getKeyPrefix()
      Get the key prefix for all keys.
      Returns:
      key prefix, or null if there is none configured
    • setKeyPrefix

      public void setKeyPrefix(byte[] keyPrefix)
      Configure a prefix for all keys. The prefix will be added/removed automatically with all access. The default prefix is null, which is equivalent to an empty prefix.

      The key prefix may not be changed after this instance has started.

      Parameters:
      keyPrefix - new prefix, or null for none
      Throws:
      IllegalArgumentException - if keyPrefix starts with 0xff
      IllegalStateException - if this instance has already been started
    • getDatabase

      public Database getDatabase()
      Get the underlying Database associated with this instance.
      Returns:
      the associated Database
      Throws:
      IllegalStateException - if this instance has not yet been started
    • start

      @PostConstruct public void start()
      Description copied from interface: KVDatabase
      Start this instance. This method must be called prior to creating any transactions.

      This method is idempotent: if this instance is already started, nothing happens.

      Whether an instance that has been started and stopped can be restarted is implementation-dependent.

      Specified by:
      start in interface KVDatabase
    • stop

      @PreDestroy public void stop()
      Description copied from interface: KVDatabase
      Stop this instance.

      This method is idempotent: if this instance has not been started, or is already stopped, nothing happens.

      Specified by:
      stop in interface KVDatabase
    • createTransaction

      public FoundationKVTransaction createTransaction()
      Description copied from interface: KVDatabase
      Create a new transaction.
      Specified by:
      createTransaction in interface KVDatabase
      Returns:
      newly created transaction
    • createTransaction

      public FoundationKVTransaction createTransaction(Map<String,?> options)
      Description copied from interface: KVDatabase
      Create a new transaction with the specified options.
      Specified by:
      createTransaction in interface KVDatabase
      Parameters:
      options - optional transaction options; may be null
      Returns:
      newly created transaction
    • encodeCounter

      public static byte[] encodeCounter(long value)
      Encode a 64 bit counter value.
      Parameters:
      value - counter value
      Returns:
      encoded value
    • decodeCounter

      public static long decodeCounter(byte[] bytes)
      Decode a 64 bit counter value.
      Parameters:
      bytes - encoded value
      Returns:
      value counter value
      Throws:
      NullPointerException - if bytes is null
      IllegalArgumentException - if bytes is invalid