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 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 lockboolean
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.
-
-
-
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.Exception
Acquire the mutex - blocking until it's available. Each call to acquire must be balanced by a call torelease(UUID)
- Specified by:
acquire
in 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.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 torelease(UUID)
- Specified by:
acquire
in 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:
isAcquiredByAny
in 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:
isAcquired
in interfaceInterProcessTxLock
- 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 interfaceInterProcessTxLock
- 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 interfaceInterProcessTxLock
- 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()
-
-