Source:
public <T> T retryUntilConnected(final Callable<T> callable) throws IllegalArgumentException, ZkException { if (_zookeeperEventThread != null && Thread.currentThread() == _zookeeperEventThread) { throw new IllegalArgumentException("Must not be done in the zookeeper event thread."); } final long operationStartTime = System.currentTimeMillis(); if (_monitor != null) { _monitor.increaseOutstandingRequestGauge(); } try { while (true) { KeeperException.Code retryCauseCode; if (isClosed()) { throw new IllegalStateException("ZkClient already closed!"); } try { final ZkConnection zkConnection = (ZkConnection) getConnection(); if (zkConnection == null || zkConnection.getZookeeper() == null) { throw new IllegalStateException( "ZkConnection is in invalid state! Please close this ZkClient and create new client."); } return callable.call(); } catch (ConnectionLossException e) { retryCauseCode = e.code(); Thread.yield(); waitForRetry(); } catch (SessionExpiredException e) { retryCauseCode = e.code(); Thread.yield(); waitForRetry(); } catch (ZkSessionMismatchedException e) { throw e; } catch (KeeperException e) { throw ZkException.create(e); } catch (InterruptedException e) { throw new ZkInterruptedException(e); } catch (Exception e) { throw ExceptionUtil.convertToRuntimeException(e); } if (System.currentTimeMillis() - operationStartTime > _operationRetryTimeoutInMillis) { throw new ZkTimeoutException("Operation cannot be retried because of retry timeout (" + _operationRetryTimeoutInMillis + " milli seconds). Retry was caused by " + retryCauseCode); } LOG.warn("Retrying operation, caused by {}", retryCauseCode); } } finally { if (_monitor != null) { _monitor.decreaseOutstandingRequestGauge(); } } }

Target:
public <T> T retryUntilConnected(final Callable<T> callable) throws IllegalArgumentException, ZkException { if (_zookeeperEventThread != null && Thread.currentThread() == _zookeeperEventThread) { throw new IllegalArgumentException("Must not be done in the zookeeper event thread."); } final long operationStartTime = System.currentTimeMillis(); if (_monitor != null) { _monitor.increaseOutstandingRequestGauge(); } try { while (true) { KeeperException.Code retryCauseCode; if (isClosed()) { throw new IllegalStateException("ZkClient already closed!"); } try { final ZkConnection zkConnection = (ZkConnection) getConnection(); if (zkConnection == null || zkConnection.getZookeeper() == null) { throw new IllegalStateException( "ZkConnection is in invalid state! Please close this ZkClient and create new client."); } return callable.call(); } catch (ConnectionLossException e) { retryCauseCode = e.code(); Thread.yield(); waitForRetry(); } catch (SessionExpiredException e) { retryCauseCode = e.code(); Thread.yield(); waitForRetry(); } catch (ZkSessionMismatchedException e) { throw e; } catch (KeeperException e) { throw ZkException.create(e); } catch (InterruptedException e) { throw new ZkInterruptedException(e); } catch (Exception e) { throw ExceptionUtil.convertToRuntimeException(e); } LOG.debug("Retrying operation, caused by {}", retryCauseCode); if (System.currentTimeMillis() - operationStartTime > _operationRetryTimeoutInMillis) { throw new ZkTimeoutException("Operation cannot be retried because of retry timeout (" + _operationRetryTimeoutInMillis + " milli seconds). Retry was caused by " + retryCauseCode); } } } finally { if (_monitor != null) { _monitor.decreaseOutstandingRequestGauge(); } } }