Retry loops are handled automatically by Curator internally. If you don't pass 
a timeout to lock.acquireLock(), it will block indefinitely. If you want to 
continue lock attempts even in the face of other exceptions, just make an 
infinite loop:

for(;;) 
{
     try
     {
         lock.acquireLock(); // attempt to acquire the lock
     }
     catch ( Exception e )
     {
         log.error(e, …);
     }
}

This wouldn't be a very robust way to go, but it works.

-JZ

On Jul 17, 2013, at 6:20 PM, "[email protected]" 
<[email protected]> wrote:

> Hello,
> 
> I am trying to use the InterProcessMutex to lock a shared resource on HDFS. 
> My question is how are we supposed to handle cases where a client fails to 
> acquire the mutex lock?
> 
> I am using the method here[1] to acquire the lock. The javadoc states that an 
> "Exception" is thrown if there were ZK errors or interruptions while 
> attempting to acquire the lock. I am assuming this includes some recoverable 
> exceptions as well.
> 
> Is it wise to wrap this up in a RetryLoop? Something like:
> 
> RetryLoop retryLoop = client.newRetryLoop();
>  while ( retryLoop.shouldContinue() )
>  {
>      try
>      {
>          lock.acquireLock(); // attempt to acquire the lock
>      }
>      catch ( Exception e )
>      {
>          retryLoop.takeException(e);
>      }
>  }
> 
> Thanks,
> 
> [1] 
> http://curator.incubator.apache.org/apidocs/org/apache/curator/framework/recipes/locks/InterProcessMutex.html#acquire(long,
>  java.util.concurrent.TimeUnit)
> 
> -- 
> Swarnim

Reply via email to