public T RetryUntilConnected <T>(Func <T> callable) { if (_zookeeperEventThread != null && Thread.CurrentThread == _zookeeperEventThread) { throw new Exception("Must not be done in the zookeeper event thread."); } long operationStartTime = DateTime.Now.ToUnixTime(); while (true) { if (_closed) { throw new Exception("ZKClient already closed!"); } try { return(callable()); } catch (ConnectionLossException e) { // we give the event thread some time to update the status to 'Disconnected' Thread.Yield(); WaitForRetry(); } catch (SessionExpiredException e) { // we give the event thread some time to update the status to 'Expired' Thread.Yield(); WaitForRetry(); } catch (KeeperException e) { throw ZKException.Create(e); } catch (ThreadInterruptedException e) { throw new ZKInterruptedException(e); } catch (Exception e) { throw ExceptionUtil.ConvertToException(e); } // before attempting a retry, check whether retry timeout has elapsed if (_operationRetryTimeoutInMillis > -1 && (DateTime.Now.ToUnixTime() - operationStartTime) >= _operationRetryTimeoutInMillis) { throw new ZKTimeoutException("Operation cannot be retried because of retry timeout (" + _operationRetryTimeoutInMillis + " milli seconds)"); } } }
public InMemoryConnection() { try { Create("/", null, CreateMode.Persistent); } catch (KeeperException e) { throw ZKException.Create(e); } catch (ThreadInterruptedException e) { Thread.CurrentThread.Interrupt(); throw new ZKInterruptedException(e); } }
public long GetCreationTime(string path) { lock (_zkEventLock) { try { return(_connection.GetCreateTime(path)); } catch (KeeperException e) { throw ZKException.Create(e); } catch (ThreadInterruptedException e) { throw new ZKInterruptedException(e); } } }