LogCabin
|
Provides access to the hierarchical key-value store. More...
#include <Client.h>
Public Member Functions | |
Tree (const Tree &other) | |
Copy constructor. | |
Tree & | operator= (const Tree &other) |
Assignment operator. | |
Result | setWorkingDirectory (const std::string &workingDirectory) |
Set the working directory for this object. | |
void | setWorkingDirectoryEx (const std::string &workingDirectory) |
Like setWorkingDirectory but throws exceptions upon errors. | |
std::string | getWorkingDirectory () const |
Return the working directory for this object. | |
std::pair< std::string, std::string > | getCondition () const |
Return the condition set by a previous call to setCondition(). | |
Result | setCondition (const std::string &path, const std::string &value) |
Set a predicate on all future operations. | |
void | setConditionEx (const std::string &path, const std::string &value) |
Like setCondition but throws exceptions upon errors. | |
uint64_t | getTimeout () const |
Return the timeout set by a previous call to setTimeout(). | |
void | setTimeout (uint64_t nanoseconds) |
Abort each future operation if it may not have completed within the specified period of time. | |
Result | makeDirectory (const std::string &path) |
Make sure a directory exists at the given path. | |
void | makeDirectoryEx (const std::string &path) |
Like makeDirectory but throws exceptions upon errors. | |
Result | listDirectory (const std::string &path, std::vector< std::string > &children) const |
List the contents of a directory. | |
std::vector< std::string > | listDirectoryEx (const std::string &path) const |
Like listDirectory but throws exceptions upon errors. | |
Result | removeDirectory (const std::string &path) |
Make sure a directory does not exist. | |
void | removeDirectoryEx (const std::string &path) |
Like removeDirectory but throws exceptions upon errors. | |
Result | write (const std::string &path, const std::string &contents) |
Set the value of a file. | |
void | writeEx (const std::string &path, const std::string &contents) |
Like write but throws exceptions upon errors. | |
Result | read (const std::string &path, std::string &contents) const |
Get the value of a file. | |
std::string | readEx (const std::string &path) const |
Like read but throws exceptions upon errors. | |
Result | removeFile (const std::string &path) |
Make sure a file does not exist. | |
void | removeFileEx (const std::string &path) |
Like removeFile but throws exceptions upon errors. | |
Private Member Functions | |
Tree (std::shared_ptr< ClientImpl > clientImpl, const std::string &workingDirectory) | |
Constructor. | |
std::shared_ptr< const TreeDetails > | getTreeDetails () const |
Get a reference to the implementation-specific members of this class. | |
Private Attributes | |
std::mutex | mutex |
Provides mutual exclusion to treeDetails pointer. | |
std::shared_ptr< const TreeDetails > | treeDetails |
Reference-counted pointer to implementation-specific members. | |
Friends | |
class | Cluster |
Provides access to the hierarchical key-value store.
You can get an instance of Tree through Cluster::getTree() or by copying an existing Tree.
A Tree has a working directory from which all relative paths (those that do not begin with a '/' are resolved). This allows different applications and modules to conveniently access their own subtrees -- they can have their own Tree instances and set their working directories accordingly.
Methods that can fail come in two flavors. The first flavor returns Result values with error codes and messages; the second throws exceptions upon errors. These can be distinguished by the "Ex" suffix in the names of methods that throw exceptions.
LogCabin::Client::Tree::Tree | ( | std::shared_ptr< ClientImpl > | clientImpl, |
const std::string & | workingDirectory | ||
) | [private] |
LogCabin::Client::Tree::Tree | ( | const Tree & | other | ) |
Result LogCabin::Client::Tree::setWorkingDirectory | ( | const std::string & | workingDirectory | ) |
Set the working directory for this object.
This directory will be created if it does not exist.
workingDirectory | The new working directory, which may be relative to the current working directory. |
void LogCabin::Client::Tree::setWorkingDirectoryEx | ( | const std::string & | workingDirectory | ) |
std::string LogCabin::Client::Tree::getWorkingDirectory | ( | ) | const |
std::pair< std::string, std::string > LogCabin::Client::Tree::getCondition | ( | ) | const |
Return the condition set by a previous call to setCondition().
Result LogCabin::Client::Tree::setCondition | ( | const std::string & | path, |
const std::string & | value | ||
) |
Set a predicate on all future operations.
Future operations will return Status::CONDITION_NOT_MET and have no effect unless the file at 'path' has the contents 'value'. To remove the predicate, pass an empty string as 'path'.
path | The relative or absolute path to the file that must have the contents specified in value, or an empty string to clear the condition. |
value | The contents that the file specified by 'path' must have for future operations to succeed. If 'value' is the empty string and the file does not exist, the condition will also be satisfied. |
void LogCabin::Client::Tree::setConditionEx | ( | const std::string & | path, |
const std::string & | value | ||
) |
uint64_t LogCabin::Client::Tree::getTimeout | ( | ) | const |
Return the timeout set by a previous call to setTimeout().
void LogCabin::Client::Tree::setTimeout | ( | uint64_t | nanoseconds | ) |
Abort each future operation if it may not have completed within the specified period of time.
nanoseconds | The maximum duration of each operation (in nanoseconds). Set to 0 for no timeout. |
Result LogCabin::Client::Tree::makeDirectory | ( | const std::string & | path | ) |
Make sure a directory exists at the given path.
Create parent directories listed in path as necessary.
path | The path where there should be a directory after this call. |
void LogCabin::Client::Tree::makeDirectoryEx | ( | const std::string & | path | ) |
Result LogCabin::Client::Tree::listDirectory | ( | const std::string & | path, |
std::vector< std::string > & | children | ||
) | const |
List the contents of a directory.
path | The directory whose direct children to list. | |
[out] | children | This will be replaced by a listing of the names of the directories and files that the directory at 'path' immediately contains. The names of directories in this listing will have a trailing slash. The order is first directories (sorted lexicographically), then files (sorted lexicographically). |
std::vector< std::string > LogCabin::Client::Tree::listDirectoryEx | ( | const std::string & | path | ) | const |
Result LogCabin::Client::Tree::removeDirectory | ( | const std::string & | path | ) |
Make sure a directory does not exist.
Also removes all direct and indirect children of the directory.
If called with the root directory, this will remove all descendants but not actually remove the root directory; it will still return status OK.
path | The path where there should not be a directory after this call. |
void LogCabin::Client::Tree::removeDirectoryEx | ( | const std::string & | path | ) |
Result LogCabin::Client::Tree::write | ( | const std::string & | path, |
const std::string & | contents | ||
) |
Set the value of a file.
path | The path where there should be a file with the given contents after this call. |
contents | The new value associated with the file. |
void LogCabin::Client::Tree::writeEx | ( | const std::string & | path, |
const std::string & | contents | ||
) |
Result LogCabin::Client::Tree::read | ( | const std::string & | path, |
std::string & | contents | ||
) | const |
Get the value of a file.
path | The path of the file whose contents to read. |
contents | The current value associated with the file. |
std::string LogCabin::Client::Tree::readEx | ( | const std::string & | path | ) | const |
Result LogCabin::Client::Tree::removeFile | ( | const std::string & | path | ) |
Make sure a file does not exist.
path | The path where there should not be a file after this call. |
void LogCabin::Client::Tree::removeFileEx | ( | const std::string & | path | ) |
std::shared_ptr< const TreeDetails > LogCabin::Client::Tree::getTreeDetails | ( | ) | const [private] |
std::mutex LogCabin::Client::Tree::mutex [mutable, private] |
std::shared_ptr<const TreeDetails> LogCabin::Client::Tree::treeDetails [private] |