public class CuratorPersister extends java.lang.Object implements Persister
Persister interface provides for persistence and retrieval of data from
Zookeeper. All paths passed to this instance are automatically namespaced within a framework-specific znode to avoid
conflicts with other users of the same ZK instance.| Modifier and Type | Class and Description |
|---|---|
static class |
CuratorPersister.Builder
Builder for constructing
CuratorPersister instances. |
| Constructor and Description |
|---|
CuratorPersister(java.lang.String serviceName,
CuratorFramework client) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this storage and cleans up any local client resources.
|
byte[] |
get(java.lang.String unprefixedPath)
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 unprefixedPath)
Returns the names of child nodes at the provided path.
|
java.util.Map<java.lang.String,byte[]> |
getMany(java.util.Collection<java.lang.String> unprefixedPaths)
Atomically reads many values from storage at once, returning a mapping of paths to values.
|
static CuratorPersister.Builder |
newBuilder(ServiceSpec serviceSpec)
Creates a new
CuratorPersister.Builder instance which has been initialized with reasonable default values. |
void |
recursiveDelete(java.lang.String unprefixedPath)
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> unprefixedPaths)
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 unprefixedPath,
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[]> unprefixedPathBytesMap)
Atomically writes many values to storage at once.
|
CuratorPersister(java.lang.String serviceName,
CuratorFramework client)
public static CuratorPersister.Builder newBuilder(ServiceSpec serviceSpec)
CuratorPersister.Builder instance which has been initialized with reasonable default values.serviceSpec - the service for which data will be storedpublic byte[] get(java.lang.String unprefixedPath)
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 unprefixedPath)
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 recursiveDelete(java.lang.String unprefixedPath)
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 set(java.lang.String unprefixedPath,
byte[] bytes)
throws PersisterException
Persisterset in interface PersisterPersisterException - in the event of an access errorpublic void setMany(java.util.Map<java.lang.String,byte[]> unprefixedPathBytesMap)
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> unprefixedPaths)
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> unprefixedPaths)
throws PersisterException
PersisterMap.getMany in interface PersisterPersisterException - in the event of an access errorPersister.get(String)