zookeeper-cpp
ZooKeeper Client for C++
|
Used to specify parameters for a connection
.
More...
#include <zk/connection.hpp>
Public Types | |
using | host_list = std::vector< std::string > |
Public Member Functions | |
connection_params () noexcept | |
Create an instance with default values. More... | |
const std::string & | connection_schema () const |
std::string & | connection_schema () |
const host_list & | hosts () const |
host_list & | hosts () |
const std::string & | chroot () const |
std::string & | chroot () |
bool | randomize_hosts () const |
bool & | randomize_hosts () |
*bool | read_only () const |
bool & | read_only () |
std::chrono::milliseconds | timeout () const |
std::chrono::milliseconds & | timeout () |
Static Public Member Functions | |
static connection_params | parse (string_view conn_string) |
Create an instance from a connection string. More... | |
Static Public Attributes | |
static constexpr std::chrono::milliseconds | default_timeout = std::chrono::seconds(10) |
Used to specify parameters for a connection
.
This can either be created manually or through a connection string.
Definition at line 84 of file connection.hpp.
|
noexcept |
Create an instance with default values.
Definition at line 65 of file connection.cpp.
|
inline |
Specifying a value for chroot
as something aside from ""
or "/"
will run the client commands while interpreting all paths relative to the specified path. For example, specifying "/app/a"
will make requests for "/foo/bar"
sent to "/app/a/foo/bar"
(from the server's perspective). If unspecified, the path will be treated as "/"
.
Definition at line 151 of file connection.hpp.
|
inline |
Determines the underlying zk::connection implementation to use. The valid values are "zk"
and "fakezk"
.
zk
: The standard-issue ZooKeeper connection to a real ZooKeeper cluster. This schema uses zk::connection_zk as the underlying connection.fakezk
: Create a client connected to a fake ZooKeeper server (zk::fake::server). Here, the host_address
refers to the name of the in-memory DB created when the server instance was. This schema uses zk::fake::connection_fake as the underlying connection. Definition at line 132 of file connection.hpp.
|
inline |
Addresses for the ensemble to connect to. This can be IP addresses (IPv4 or IPv6) or hostnames, but IP addresses are the recommended method of specification. If the port is left unspecified, 2181
is assumed (as it is the de facto standard for ZooKeeper server). For IPv6 addresses, use the boxed format (e.g. [::1]:2181
); this is required even when the port is 2181
to disambiguate between a host named in hexadecimal and an IPv6 address (e.g. "[fd2d:8413:d6c6::73b]"
or "[::1]:2181"
).
Definition at line 142 of file connection.hpp.
|
static |
Create an instance from a connection string.
schema://host_address/path?querystring
). The schema
is the type of connection (usually "zk"
), auth
is potential authentication, the host_address
is the list of servers, the path
is the chroot to use for this connection and the querystring
allows for configuring advanced options. For example: "zk://server-a:2181,server-b:2181,server-c:2181/?timeout=5"
."zk://localhost/?timeout=10&read_only=true"
specifies a timeout of 10 seconds and sets a read-only client. Boolean values can be specified with true
, t
, or 1
for true
or false
, f
, or 0
for false
. It is important to note that, unlike regular HTTP URLs, query parameters which are not understood will result in an error.randomize_hosts
: connection_params::randomize_hostsread_only
: connection_params::read_onlytimeout
: connection_params::timeoutstd::invalid_argument | if the string is malformed in some way. |
Definition at line 186 of file connection.cpp.
|
inline |
Connect to a host at random (as opposed to attempting connections in order)? The default is to randomize (the use cases for sequential connections are usually limited to testing purposes).
Definition at line 158 of file connection.hpp.
|
inline |
Allow connections to read-only servers? The default (false
) is to disallow.
Definition at line 164 of file connection.hpp.
|
inline |
The session timeout between this client and the server. The server will attempt to respect this value, but will automatically use a lower timeout value if this value is too large (see the ZooKeeper Programmer's Guide for more information on maximum values). The default is 10 seconds.
When specified in a query string, this value is specified either with floating-point seconds or as an ISO 8601 duration (PT8.93S
for 8.930
seconds).
Definition at line 175 of file connection.hpp.