/** * 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) { if (Thread.CurrentThread != ourThread) { throw new InvalidOperationException("Not in the correct thread"); } bool passUp = true; if (sessionHasFailed.get()) { switch (mode) { case Mode.RETRY: { sessionHasFailed.set(false); Thread value; failedSessionThreads.TryRemove(ourThread, out value); if (exception is SessionFailedException) { isDone.set(false); passUp = false; } break; } case Mode.FAIL: { break; } } } if (passUp) { retryLoop.takeException(exception); } }
/** * 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, ICallable <T> proc) { T result = default(T); RetryLoop retryLoop = client.newRetryLoop(); while (retryLoop.shouldContinue()) { try { client.internalBlockUntilConnectedOrTimedOut(); result = proc.call(); retryLoop.markComplete(); } catch (Exception e) { ThreadUtils.checkInterrupted(e); retryLoop.takeException(e); } } return(result); }