Example #1
0
        /**
         * Convenience utility: creates a "session fail" retry loop calling the given proc
         *
         * @param client Zookeeper
         * @param mode how to handle session failures
         * @param proc procedure to call with retry
         * @param <T> return type
         * @return procedure result
         * @throws Exception any non-retriable errors
         */
        public static T callWithRetry <T>(CuratorZookeeperClient client, Mode mode, ICallable <T> proc)
        {
            T result = default(T);
            SessionFailRetryLoop retryLoop = client.newSessionFailRetryLoop(mode);

            retryLoop.start();
            try
            {
                while (retryLoop.shouldContinue())
                {
                    try
                    {
                        result = proc.call();
                    }
                    catch (Exception e)
                    {
                        ThreadUtils.checkInterrupted(e);
                        retryLoop.takeException(e);
                    }
                }
            }
            finally
            {
                retryLoop.Dispose();
            }
            return(result);
        }
Example #2
0
        internal ZooKeeper getZooKeeper()
        {
            if (SessionFailRetryLoop.sessionForThreadHasFailed())
            {
                throw new SessionFailRetryLoop.SessionFailedException();
            }
            Exception exception;

            backgroundExceptions.TryDequeue(out exception);
            if (exception != null)
            {
                tracer.Get().addCount("background-exceptions", 1);
                throw exception;
            }

            bool localIsConnected = _isConnected.get();

            if (!localIsConnected)
            {
                checkTimeouts();
            }

            return(zooKeeper.getZooKeeper());
        }
Example #3
0
 public SessionFailWatcher(SessionFailRetryLoop retryLoop)
 {
     _retryLoop = retryLoop;
 }