Class NonReentrantMutex

java.lang.Object
com.complexible.common.curator.framework.locks.NonReentrantMutex
All Implemented Interfaces:
InterProcessTxLock

public class NonReentrantMutex extends Object implements InterProcessTxLock
Since:
4.3
Author:
Scott Fines
  • Constructor Details

    • NonReentrantMutex

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

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

    • acquire

      public void acquire(UUID theTxId) throws 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
      Parameters:
      theTxId -
      Throws:
      Exception - ZK errors, connection interruptions
    • acquire

      public boolean acquire(UUID theTxId, long theTime, TimeUnit theTimeUnit) throws 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:
      theTxId -
      theTime - time to wait
      theTimeUnit - time unit
      Returns:
      true if the mutex was acquired, false if not
      Throws:
      Exception - ZK errors, connection interruptions
    • isAcquiredByAny

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

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

      public void releaseAll() throws Exception
      Release all locks for all transactions that we've created.
      Specified by:
      releaseAll in interface InterProcessTxLock
      Throws:
      Exception - IllegalMonitorStateException if one of the tx registered does not exist (concurrent release)
    • release

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

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

      protected byte[] getLockNodeBytes()