/** * 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); }
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()); }
public SessionFailWatcher(SessionFailRetryLoop retryLoop) { _retryLoop = retryLoop; }