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()); }
/** * 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); }