/zk-client

A client library for ZooKeeper that it is a thin wrapper around Curator. It provides concise method calls with checked exceptions.

Primary LanguageJavaApache License 2.0Apache-2.0

Zookeeper Client

Tests Coverage Duplicated Lines (%) Vulnerabilities Security Rating Reliability Rating Maintainability Rating Technical Debt Quality Gate Status JitPack

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.

Checked Exceptions

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 underlying KeeperException.
  • canResolveByRetry(): Some network related exceptions can be fixed by retry, but error codes like NONODE or NODEEXISTS should be handled differently. This method helps to separate these two categories from each other.

Concise Operation Calls

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.