Class ThreadLocalRetryLoop


  • public class ThreadLocalRetryLoop
    extends java.lang.Object

    Retry loops can easily end up getting nested which can cause exponential calls of the retry policy (see https://issues.apache.org/jira/browse/CURATOR-559). This utility works around that by using an internal ThreadLocal to hold a retry loop. E.g. if the retry loop fails anywhere in the chain of nested calls it will fail for the rest of the nested calls instead.

    Example usage:

     ThreadLocalRetryLoop threadLocalRetryLoop = new ThreadLocalRetryLoop();
     RetryLoop retryLoop = threadLocalRetryLoop.getRetryLoop(client::newRetryLoop);
     try
     {
         while ( retryLoop.shouldContinue() )
         {
             try
             {
                 // do work
                 retryLoop.markComplete();
             }
             catch ( Exception e )
             {
                 ThreadUtils.checkInterrupted(e);
                 retryLoop.takeException(e);
             }
         }
     }
     finally
     {
         threadLocalRetryLoop.release();
     }
     

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      RetryLoop getRetryLoop​(java.util.function.Supplier<RetryLoop> newRetryLoopSupplier)
      Call to get the current retry loop.
      void release()
      Must be called to release the retry loop.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait