Class NonReentrantMutex
- java.lang.Object
-
- com.complexible.common.curator.framework.locks.NonReentrantMutex
-
- All Implemented Interfaces:
InterProcessTxLock
public class NonReentrantMutex extends java.lang.Object implements InterProcessTxLock
- Since:
- 4.3
- Author:
- Scott Fines
-
-
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 voidacquire(java.util.UUID theTxId)Acquire the mutex - blocking until it's available.booleanacquire(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 lockbooleanisAcquired(java.util.UUID theTxId)booleanisAcquiredByAny()voidrelease(java.util.UUID theTxId)Release a lock for a transaction.voidreleaseAll()Release all locks for all transactions that we've created.
-
-
-
Constructor Detail
-
NonReentrantMutex
public NonReentrantMutex(org.apache.curator.framework.CuratorFramework client, java.lang.String path)- Parameters:
client- clientpath- 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- clientpath- the path to lockdriver- lock driver
-
-
Method Detail
-
acquire
public void acquire(java.util.UUID theTxId) throws java.lang.ExceptionAcquire the mutex - blocking until it's available. Each call to acquire must be balanced by a call torelease(UUID)- Specified by:
acquirein interfaceInterProcessTxLock- 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.ExceptionAcquire 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 torelease(UUID)- Specified by:
acquirein interfaceInterProcessTxLock- Parameters:
theTime- time to waittheTimeUnit- 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:
isAcquiredByAnyin interfaceInterProcessTxLock- 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:
isAcquiredin interfaceInterProcessTxLock- Parameters:
theTxId-- Returns:
- true if there is a lock for the specified transaction id.
-
releaseAll
public void releaseAll() throws java.lang.ExceptionRelease all locks for all transactions that we've created.- Specified by:
releaseAllin interfaceInterProcessTxLock- Throws:
java.lang.Exception
-
release
public void release(java.util.UUID theTxId) throws java.lang.ExceptionDescription copied from interface:InterProcessTxLockRelease a lock for a transaction.- Specified by:
releasein interfaceInterProcessTxLock- Throws:
java.lang.Exception
-
getParticipantNodes
public java.util.Collection<java.lang.String> getParticipantNodes() throws java.io.IOExceptionReturn 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()
-
-