public class InterProcessMutex extends java.lang.Object implements InterProcessLock, Revocable<InterProcessMutex>
Constructor and Description |
---|
InterProcessMutex(CuratorFramework client,
java.lang.String path) |
Modifier and Type | Method and Description |
---|---|
void |
acquire()
Acquire the mutex - blocking until it's available.
|
boolean |
acquire(long time,
java.util.concurrent.TimeUnit unit)
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 |
isAcquiredInThisProcess()
Returns true if the mutex is acquired by a thread in this JVM
|
void |
makeRevocable(RevocationListener<InterProcessMutex> listener)
Make the lock revocable.
|
void |
makeRevocable(RevocationListener<InterProcessMutex> listener,
java.util.concurrent.Executor executor)
Make the lock revocable.
|
void |
release()
Perform one release of the mutex if the calling thread is the same thread that acquired it.
|
public InterProcessMutex(CuratorFramework client, java.lang.String path)
client
- clientpath
- the path to lockpublic void acquire() throws java.lang.Exception
release()
acquire
in interface InterProcessLock
java.lang.Exception
- ZK errors, interruptions, another thread owns the lockpublic boolean acquire(long time, java.util.concurrent.TimeUnit unit) throws java.lang.Exception
release()
acquire
in interface InterProcessLock
time
- time to waitunit
- time unitjava.lang.Exception
- ZK errors, interruptions, another thread owns the lockpublic boolean isAcquiredInThisProcess()
isAcquiredInThisProcess
in interface InterProcessLock
public void release() throws java.lang.Exception
release
in interface InterProcessLock
java.lang.Exception
- ZK errors, interruptions, current thread does not own the lockpublic java.util.Collection<java.lang.String> getParticipantNodes() throws java.lang.Exception
java.lang.Exception
- ZK errors, interruptions, etc.public void makeRevocable(RevocationListener<InterProcessMutex> listener)
Revocable
makeRevocable
in interface Revocable<InterProcessMutex>
listener
- the listenerpublic void makeRevocable(RevocationListener<InterProcessMutex> listener, java.util.concurrent.Executor executor)
Revocable
makeRevocable
in interface Revocable<InterProcessMutex>
listener
- the listenerexecutor
- executor for the listenerprotected byte[] getLockNodeBytes()