public class InterProcessMutex extends Object implements InterProcessLock, Revocable<InterProcessMutex>
Constructor and Description |
---|
InterProcessMutex(CuratorFramework client,
String path) |
InterProcessMutex(CuratorFramework client,
String path,
LockInternalsDriver driver) |
Modifier and Type | Method and Description |
---|---|
void |
acquire()
Acquire the mutex - blocking until it's available.
|
boolean |
acquire(long time,
TimeUnit unit)
Acquire the mutex - blocks until it's available or the given time expires.
|
protected byte[] |
getLockNodeBytes() |
protected String |
getLockPath() |
Collection<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
|
boolean |
isOwnedByCurrentThread()
Returns true if the mutex is acquired by the calling thread
|
void |
makeRevocable(RevocationListener<InterProcessMutex> listener)
Make the lock revocable.
|
void |
makeRevocable(RevocationListener<InterProcessMutex> listener,
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, String path)
client
- clientpath
- the path to lockpublic InterProcessMutex(CuratorFramework client, String path, LockInternalsDriver driver)
client
- clientpath
- the path to lockdriver
- lock driverpublic void acquire() throws Exception
release()
acquire
in interface InterProcessLock
Exception
- ZK errors, connection interruptionspublic boolean acquire(long time, TimeUnit unit) throws Exception
release()
acquire
in interface InterProcessLock
time
- time to waitunit
- time unitException
- ZK errors, connection interruptionspublic boolean isAcquiredInThisProcess()
isAcquiredInThisProcess
in interface InterProcessLock
public void release() throws Exception
release
in interface InterProcessLock
Exception
- ZK errors, interruptions, current thread does not own the lockpublic Collection<String> getParticipantNodes() throws Exception
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, Executor executor)
Revocable
makeRevocable
in interface Revocable<InterProcessMutex>
listener
- the listenerexecutor
- executor for the listenerpublic boolean isOwnedByCurrentThread()
protected byte[] getLockNodeBytes()
protected String getLockPath()
Copyright © 2011–2023 The Apache Software Foundation. All rights reserved.