public class MemPersister extends java.lang.Object implements Persister
Persister which stores the data in local memory. Mirrors the behavior of
CuratorPersister.| Modifier and Type | Class and Description |
|---|---|
static class |
MemPersister.LockMode
Whether to enable or disable thread-safe locking.
|
| Constructor and Description |
|---|
MemPersister()
Creates a new instance with locking enabled and without any initial data.
|
MemPersister(MemPersister.LockMode mode,
java.util.Map<java.lang.String,byte[]> data)
Creates a new instance with the provided options.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this storage and cleans up any local client resources.
|
byte[] |
get(java.lang.String path)
Retrieves the previously stored data at the specified path, or throws an exception if the path doesn't exist.
|
java.util.Collection<java.lang.String> |
getChildren(java.lang.String path)
Returns the names of child nodes at the provided path.
|
java.lang.String |
getDebugString()
Returns a summary of this instance in a newline-separated string.
|
java.util.Map<java.lang.String,byte[]> |
getMany(java.util.Collection<java.lang.String> paths)
Atomically reads many values from storage at once, returning a mapping of paths to values.
|
void |
recursiveDelete(java.lang.String path)
Recursively deletes the data at the specified path, or throws an exception if no data existed at that location.
|
void |
recursiveDeleteMany(java.util.Collection<java.lang.String> paths)
Atomically deletes many values from storage at once, with each path entry being treated as a call to
Persister.recursiveDelete(String) for those paths. |
void |
set(java.lang.String path,
byte[] bytes)
Writes a single value to storage at the specified path, replacing any existing data at the path or creating the
path if it doesn't exist yet.
|
void |
setMany(java.util.Map<java.lang.String,byte[]> pathBytesMap)
Atomically writes many values to storage at once.
|
public MemPersister()
public MemPersister(MemPersister.LockMode mode, java.util.Map<java.lang.String,byte[]> data)
mode - Allows enabling or disabling internal thread-safe locking. Disable in cases where the caller is
already performing their own lockingdata - The initial data to be stored in the instance, or an empty map if none is applicablepublic byte[] get(java.lang.String path)
throws PersisterException
Persisternull.get in interface PersisterPersisterException - if the requested path doesn't exist, or for other access errorspublic java.util.Collection<java.lang.String> getChildren(java.lang.String path)
throws PersisterException
Persisternull data when
retrieved via Persister.get(String), indicating that these are stub parent entries to other nodes.
To translate the returned values to full absolute paths, they may be joined with the provided path
input using PersisterUtils.join(String, String).
To get the list of nodes at the root, use "" or "/" as the input path.
getChildren in interface PersisterPersisterException - if the requested path doesn't exist, or for other access errorspublic void set(java.lang.String path,
byte[] bytes)
throws PersisterException
Persisterset in interface PersisterPersisterException - in the event of an access errorpublic void setMany(java.util.Map<java.lang.String,byte[]> pathBytesMap)
throws PersisterException
PersistersetMany in interface PersisterPersisterException - in the event of an access error, in which case no changes should have been madePersister.set(String, byte[])public void recursiveDeleteMany(java.util.Collection<java.lang.String> paths)
throws PersisterException
PersisterPersister.recursiveDelete(String) for those paths.recursiveDeleteMany in interface PersisterPersisterException - in the event of an access error, in which case no changes should have been madePersister.recursiveDelete(String)public java.util.Map<java.lang.String,byte[]> getMany(java.util.Collection<java.lang.String> paths)
throws PersisterException
PersisterMap.getMany in interface PersisterPersisterException - in the event of an access errorPersister.get(String)public void recursiveDelete(java.lang.String path)
throws PersisterException
PersisterDeleting the root node (as "" or "/") will result in all nodes EXCEPT the root node being deleted.
recursiveDelete in interface PersisterPersisterException - if the data at the requested path didn't exist, or for other access errorspublic void close()
Persisterpublic java.lang.String getDebugString()