Database Reference
In-Depth Information
released, this may have been addressed, which eliminates the need for this
workaround.
Connecting to ZooKeeper
A ZooKeeper session is established by creating a ZooKeeper object using
its standard constructors. The most complicated version of this constructor
has the following signature:
public ZooKeeper(
String connectString,
int sessionTimeout,
Watcher watcher,
long sessionId,
byte [] sessionPasswd,
boolean canBeReadOnly
) throws IOException
The shortest version of the constructor only needs the connectionString
and sessionTimeout arguments.
The connectionString is a comma-separated list of hostname and port
pairs. In version 3.4 and later, an optional path can be appended to the
hostname. This acts as a sort of chroot when connecting the server,
instructing the client to treat the path as the root of the server.
When the client connects to ZooKeeper, it first shuffles the hosts listed in
the connection string into a random order. It then tries the first host in the
shuffled list. If connecting to that host fails, it tries the second host and so
on through the list.
For example, to connect to three servers named zookeeper1 ,
zookeeper2 , and zookeeper3 but with subdirectory other , the
ZooKeeper client would be initialized as follows:
new ZooKeeper(
" zookeeper1,zookeeper2,zookeeper3/other",
3000,
new Watcher() {
public void process(WatchedEvent event) {
}
Search WWH ::




Custom Search