Class Lock

  • All Implemented Interfaces:
    com.yahoo.transaction.Mutex, java.lang.AutoCloseable

    public class Lock
    extends java.lang.Object
    implements com.yahoo.transaction.Mutex
    A cluster-wide re-entrant mutex which is released on (the last symmetric) close. Re-entrancy is limited to the instance of this. To ensure re-entrancy callers should access the lock through Curator.lock(Path, Duration) instead of constructing this directly.
    Author:
    bratseth
    • Constructor Summary

      Constructors 
      Constructor Description
      Lock​(java.lang.String lockPath, Curator curator)  
      Lock​(java.lang.String lockPath, org.apache.curator.framework.recipes.locks.InterProcessLock mutex)
      Public for testing only
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void acquire​(java.time.Duration timeout)
      Take the lock with the given timeout.
      void close()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Lock

        public Lock​(java.lang.String lockPath,
                    Curator curator)
      • Lock

        public Lock​(java.lang.String lockPath,
                    org.apache.curator.framework.recipes.locks.InterProcessLock mutex)
        Public for testing only
    • Method Detail

      • acquire

        public void acquire​(java.time.Duration timeout)
                     throws com.google.common.util.concurrent.UncheckedTimeoutException
        Take the lock with the given timeout. This may be called multiple times from the same thread - each matched by a close
        Throws:
        com.google.common.util.concurrent.UncheckedTimeoutException
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface com.yahoo.transaction.Mutex