This class extends the vanilla ZooKeeper and retries operations when ConnectionLossException happens. Asynchronous operation functions are overridden. More specifically, only the asynchronous operation functions used in d2 are overridden to retry when loss happens.
All other code that uses ZooKeeper directly won't be affected, except a few lines in ZKConnection. This avoids the work to modify the callbacks for all ZooKeeper operations invoked by other code. Instead, we wrap the original callbacks inside this Wrapper class to make the callbacks handle the ConnectionLoss situation.
All read operations will be retried until the retry limit has been reached. For write operations, - setData and delete will be retried until success or reach the limit - create is a little more complicated - for non-sequential CreateMode, we will retry until success or reach the limit - for sequential CreateMode, we need to check the success of previous create by scanning the nodes owned by us; if previous create succeeded, return, otherwise retry until reach the limit
Presumably, we may want to retry asap to avoid extra delay, but it may also help to step back and wait a while before retry (in case of network congestion). Hence, a exponential-backoff retry strategy is also provided.