Search in sources :

Example 1 with OperationTimeoutException

use of org.apache.zookeeper.KeeperException.OperationTimeoutException in project SilverKing by Morgan-Stanley.

the class MetaClientCore method getZooKeeper.

public ZooKeeperExtended getZooKeeper(int getZKMaxAttempts, int getZKSleepUnit) throws KeeperException {
    ZooKeeperExtended _zk;
    int attemptIndex;
    assert getZKMaxAttempts > 0;
    assert getZKSleepUnit > 0;
    _zk = null;
    attemptIndex = 0;
    while (_zk == null) {
        _zk = _getZooKeeper();
        if (_zk == null) {
            if (attemptIndex < getZKMaxAttempts - 1) {
                ThreadUtil.randomSleep(getZKSleepUnit << attemptIndex);
                ++attemptIndex;
            } else {
                Log.warning("getZooKeeper() failed after " + (attemptIndex + 1) + " attempts");
                throw new OperationTimeoutException();
            }
        }
    }
    return _zk;
}
Also used : OperationTimeoutException(org.apache.zookeeper.KeeperException.OperationTimeoutException) ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended)

Aggregations

ZooKeeperExtended (com.ms.silverking.cloud.zookeeper.ZooKeeperExtended)1 OperationTimeoutException (org.apache.zookeeper.KeeperException.OperationTimeoutException)1