zookeeper-cpp
ZooKeeper Client for C++
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Groups
zk::connection_params Class Referencefinal

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)
 

Detailed Description

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.

Constructor & Destructor Documentation

zk::connection_params::connection_params ( )
noexcept

Create an instance with default values.

Definition at line 65 of file connection.cpp.

Member Function Documentation

const std::string& zk::connection_params::chroot ( ) const
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.

const std::string& zk::connection_params::connection_schema ( ) const
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.

const host_list& zk::connection_params::hosts ( ) const
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.

connection_params zk::connection_params::parse ( string_view  conn_string)
static

Create an instance from a connection string.

Connection Strings
Connection strings follow the standard format for URLs (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".
Exceptions
std::invalid_argumentif the string is malformed in some way.

Definition at line 186 of file connection.cpp.

bool zk::connection_params::randomize_hosts ( ) const
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.

* bool zk::connection_params::read_only ( ) const
inline

Allow connections to read-only servers? The default (false) is to disallow.

Definition at line 164 of file connection.hpp.

std::chrono::milliseconds zk::connection_params::timeout ( ) const
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.


The documentation for this class was generated from the following files: