Exemplo n.º 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, Func <T> proc)
        {
            T result = default(T);
            SessionFailRetryLoop retryLoop = client.NewSessionFailRetryLoop(mode);

            retryLoop.Start();
            try{
                while (retryLoop.ShouldContinue())
                {
                    try
                    {
                        client.InternalBlockUntilConnectedOrTimedOut();

                        result = proc();
                        retryLoop.MarkComplete();
                    }
                    catch (Exception e)
                    {
                        retryLoop.TakeException(e);
                    }
                }
            }
            finally{
                retryLoop.Dispose();
            }
            return(result);
        }
Exemplo n.º 2
0
        /**
         * Convenience utility: creates a retry loop calling the given proc and retrying if needed
         *
         * @param client Zookeeper
         * @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, Func <T> proc)
        {
            T         result    = default(T);
            RetryLoop retryLoop = client.NewRetryLoop();

            while (retryLoop.ShouldContinue())
            {
                try
                {
                    client.InternalBlockUntilConnectedOrTimedOut();

                    result = proc();
                    retryLoop.MarkComplete();
                }
                catch (Exception e)
                {
                    retryLoop.TakeException(e);
                }
            }
            return(result);
        }