Class InterProcessSemaphoreMutex
java.lang.Object
org.apache.curator.framework.recipes.locks.InterProcessSemaphoreMutex
- All Implemented Interfaces:
InterProcessLock
A NON re-entrant mutex that works across JVMs. Uses Zookeeper to hold the lock. All processes in all JVMs that
use the same lock path will achieve an inter-process critical section.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
acquire()
Acquire the mutex - blocking until it's available.boolean
Acquire the mutex - blocks until it's available or the given time expires.boolean
Returns true if the mutex is acquired by a thread in this JVMvoid
release()
Perform one release of the mutex.
-
Constructor Details
-
InterProcessSemaphoreMutex
- Parameters:
client
- the clientpath
- path for the lock
-
-
Method Details
-
acquire
Description copied from interface:InterProcessLock
Acquire the mutex - blocking until it's available. Each call to acquire must be balanced by a call toInterProcessLock.release()
- Specified by:
acquire
in interfaceInterProcessLock
- Throws:
Exception
- ZK errors, connection interruptions
-
acquire
Description copied from interface:InterProcessLock
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 toInterProcessLock.release()
- Specified by:
acquire
in interfaceInterProcessLock
- Parameters:
time
- time to waitunit
- time unit- Returns:
- true if the mutex was acquired, false if not
- Throws:
Exception
- ZK errors, connection interruptions
-
release
Perform one release of the mutex.NOTE: Unlike other implementations of
InterProcessLock.release()
, this method will NOT throw an exception if it is called on a different thread than the one which acquired the lock.- Specified by:
release
in interfaceInterProcessLock
- Throws:
Exception
- ZK errors, interruptions
-
isAcquiredInThisProcess
public boolean isAcquiredInThisProcess()Description copied from interface:InterProcessLock
Returns true if the mutex is acquired by a thread in this JVM- Specified by:
isAcquiredInThisProcess
in interfaceInterProcessLock
- Returns:
- true/false
-