Example #1
0
        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)");
                }
            }
        }
Example #2
0
 public InMemoryConnection()
 {
     try
     {
         Create("/", null, CreateMode.Persistent);
     }
     catch (KeeperException e)
     {
         throw ZKException.Create(e);
     }
     catch (ThreadInterruptedException e)
     {
         Thread.CurrentThread.Interrupt();
         throw new ZKInterruptedException(e);
     }
 }
Example #3
0
 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);
         }
     }
 }