This is a client library for Apache ZooKeeper. In fact, it is a thin wrapper around Apache Curator. Compared with Curator, we will see the following differences.
It prefers checked exceptions over runtime ones to avoid exceptions being missed or unhandled.
So we see InterruptedException
and ZkClientException
in signature of the operation calls.
ZkClientException
is a checked exception that is a wrapper around the
KeeperException.
It provides two useful methods:
getZkErrorCode()
: returns the standard ZK error code extracted from the underlyingKeeperException
.canResolveByRetry()
: Some network related exceptions can be fixed by retry, but error codes likeNONODE
orNODEEXISTS
should be handled differently. This method helps to separate these two categories from each other.
The operations are written in a more concise manner. For example the equivalent of curator call
curator.create().withMode(CreateMode.EPHEMERAL).forPath(path, data);
is:
zkClient.addEphemeralNode(path, data);
However, it is possible to go back to the curator style, by getting the underlying curator object from ZkClient
instance:
CuratorFramework curator = zkClient.getUnderlyingCurator();
And this way you have access to the full feature list of curator.