Package io.permazen.kv.fdb
Class FoundationKVDatabase
java.lang.Object
io.permazen.kv.fdb.FoundationKVDatabase
- All Implemented Interfaces:
KVDatabase
FoundationDB
KVDatabase
implementation.
Allows specifying a key prefix for all keys, allowing multiple independent databases. Key watches are supported.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The API version used by this class. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionCreate a new transaction.createTransaction
(Map<String, ?> options) Create a new transaction with the specified options.static long
decodeCounter
(byte[] bytes) Decode a 64 bit counter value.static byte[]
encodeCounter
(long value) Encode a 64 bit counter value.Get the underlyingDatabase
associated with this instance.byte[]
Get the key prefix for all keys.Get theNetworkOptions
associated with this instance.void
setClusterFilePath
(String clusterFilePath) Configure the cluster file path.void
setExecutor
(Executor executor) Configure theExecutor
used for the FoundationDB networking event loop.void
setKeyPrefix
(byte[] keyPrefix) Configure a prefix for all keys.void
start()
Start this instance.void
stop()
Stop this instance.
-
Field Details
-
API_VERSION
public static final int API_VERSIONThe API version used by this class.- See Also:
-
-
Constructor Details
-
FoundationKVDatabase
public FoundationKVDatabase()Constructor.- Throws:
FDBException
- ifAPI_VERSION
is not supported
-
-
Method Details
-
getNetworkOptions
Get theNetworkOptions
associated with this instance. Options must be configured prior tostart()
.- Returns:
- network options
-
setExecutor
Configure theExecutor
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
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
- ifkeyPrefix
starts with0xff
IllegalStateException
- if this instance has already been started
-
getDatabase
Get the underlyingDatabase
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 interfaceKVDatabase
-
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 interfaceKVDatabase
-
createTransaction
Description copied from interface:KVDatabase
Create a new transaction.- Specified by:
createTransaction
in interfaceKVDatabase
- Returns:
- newly created transaction
-
createTransaction
Description copied from interface:KVDatabase
Create a new transaction with the specified options.- Specified by:
createTransaction
in interfaceKVDatabase
- 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
- ifbytes
is nullIllegalArgumentException
- ifbytes
is invalid
-