Class NonReentrantMutex

    • Constructor Summary

      Constructors 
      Constructor Description
      NonReentrantMutex​(org.apache.curator.framework.CuratorFramework client, java.lang.String path)  
      NonReentrantMutex​(org.apache.curator.framework.CuratorFramework client, java.lang.String path, org.apache.curator.framework.recipes.locks.LockInternalsDriver driver)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void acquire​(java.util.UUID theTxId)
      Acquire the mutex - blocking until it's available.
      boolean acquire​(java.util.UUID theTxId, long theTime, java.util.concurrent.TimeUnit theTimeUnit)
      Acquire the mutex - blocks until it's available or the given time expires.
      protected byte[] getLockNodeBytes()  
      java.util.Collection<java.lang.String> getParticipantNodes()
      Return a sorted list of all current nodes participating in the lock
      boolean isAcquired​(java.util.UUID theTxId)  
      boolean isAcquiredByAny()  
      void release​(java.util.UUID theTxId)
      Release a lock for a transaction.
      void releaseAll()
      Release all locks for all transactions that we've created.
      • Methods inherited from class java.lang.Object

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

      • NonReentrantMutex

        public NonReentrantMutex​(org.apache.curator.framework.CuratorFramework client,
                                 java.lang.String path)
        Parameters:
        client - client
        path - the path to lock
      • NonReentrantMutex

        public NonReentrantMutex​(org.apache.curator.framework.CuratorFramework client,
                                 java.lang.String path,
                                 org.apache.curator.framework.recipes.locks.LockInternalsDriver driver)
        Parameters:
        client - client
        path - the path to lock
        driver - lock driver
    • Method Detail

      • acquire

        public void acquire​(java.util.UUID theTxId)
                     throws java.lang.Exception
        Acquire the mutex - blocking until it's available. Each call to acquire must be balanced by a call to release(UUID)
        Specified by:
        acquire in interface InterProcessTxLock
        Throws:
        java.lang.Exception - ZK errors, connection interruptions
      • acquire

        public boolean acquire​(java.util.UUID theTxId,
                               long theTime,
                               java.util.concurrent.TimeUnit theTimeUnit)
                        throws java.lang.Exception
        Acquire the mutex - blocks until it's available or the given time expires. Each call to acquire that returns true must be balanced by a call to release(UUID)
        Specified by:
        acquire in interface InterProcessTxLock
        Parameters:
        theTime - time to wait
        theTimeUnit - time unit
        Returns:
        true if the mutex was acquired, false if not
        Throws:
        java.lang.Exception - ZK errors, connection interruptions
      • isAcquiredByAny

        public boolean isAcquiredByAny()
                                throws java.io.IOException
        Specified by:
        isAcquiredByAny in interface InterProcessTxLock
        Returns:
        true if the mutex is acquired by any thread or process.
        Throws:
        java.io.IOException
      • isAcquired

        public boolean isAcquired​(java.util.UUID theTxId)
        Specified by:
        isAcquired in interface InterProcessTxLock
        Parameters:
        theTxId -
        Returns:
        true if there is a lock for the specified transaction id.
      • releaseAll

        public void releaseAll()
                        throws java.lang.Exception
        Release all locks for all transactions that we've created.
        Specified by:
        releaseAll in interface InterProcessTxLock
        Throws:
        java.lang.Exception
      • release

        public void release​(java.util.UUID theTxId)
                     throws java.lang.Exception
        Description copied from interface: InterProcessTxLock
        Release a lock for a transaction.
        Specified by:
        release in interface InterProcessTxLock
        Throws:
        java.lang.Exception
      • getParticipantNodes

        public java.util.Collection<java.lang.String> getParticipantNodes()
                                                                   throws java.io.IOException
        Return a sorted list of all current nodes participating in the lock
        Returns:
        list of nodes
        Throws:
        java.io.IOException - ZK errors, interruptions, etc.
      • getLockNodeBytes

        protected byte[] getLockNodeBytes()