public IZooKeeper GetZooKeeper()
        {
            if (SessionFailRetryLoop.SessionForThreadHasFailed())
            {
                throw new SessionFailRetryLoop.SessionFailedException();
            }

            Exception exception;

            backgroundExceptions.TryDequeue(out exception);

            if (exception != null)
            {
                tracer.AddCount("background-exceptions", 1);
                throw exception;
            }

            bool localIsConnected = isConnected;

            //Interlocked. (ref localIsConnected, isConnected);

            if (!localIsConnected)
            {
                CheckTimeouts();
            }

            return(zooKeeper.GetZooKeeper());
        }
Exemple #2
0
        /**
         * Pass any caught exceptions here
         *
         * @param exception the exception
         * @throws Exception if not retry-able or the retry policy returned negative
         */
        public void         TakeException(Exception exception)
        {
            bool rethrow = true;

            if (IsRetryException(exception))
            {
                if (retryPolicy.AllowRetry(retryCount++, TimeSpan.FromTicks(System.DateTime.Now.Ticks - startTimeTicks), sleeper.SleepFor))
                {
                    tracer.AddCount("retries-allowed", 1);

                    rethrow = false;
                }
                else
                {
                    tracer.AddCount("retries-disallowed", 1);
                }
            }

            if (rethrow)
            {
                throw exception;
            }
        }