Class InterProcessSemaphoreMutex
- java.lang.Object
-
- org.apache.curator.framework.recipes.locks.InterProcessSemaphoreMutex
-
- All Implemented Interfaces:
InterProcessLock
public class InterProcessSemaphoreMutex extends java.lang.Object implements 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
Constructors Constructor Description InterProcessSemaphoreMutex(org.apache.curator.framework.CuratorFramework client, java.lang.String path)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidacquire()Acquire the mutex - blocking until it's available.booleanacquire(long time, java.util.concurrent.TimeUnit unit)Acquire the mutex - blocks until it's available or the given time expires.booleanisAcquiredInThisProcess()Returns true if the mutex is acquired by a thread in this JVMvoidrelease()Perform one release of the mutex.
-
-
-
Method Detail
-
acquire
public void acquire() throws java.lang.ExceptionDescription copied from interface:InterProcessLockAcquire the mutex - blocking until it's available. Each call to acquire must be balanced by a call toInterProcessLock.release()- Specified by:
acquirein interfaceInterProcessLock- Throws:
java.lang.Exception- ZK errors, connection interruptions
-
acquire
public boolean acquire(long time, java.util.concurrent.TimeUnit unit) throws java.lang.ExceptionDescription copied from interface:InterProcessLockAcquire 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:
acquirein interfaceInterProcessLock- Parameters:
time- time to waitunit- time unit- Returns:
- true if the mutex was acquired, false if not
- Throws:
java.lang.Exception- ZK errors, connection interruptions
-
release
public void release() throws java.lang.ExceptionDescription copied from interface:InterProcessLockPerform one release of the mutex.- Specified by:
releasein interfaceInterProcessLock- Throws:
java.lang.Exception- ZK errors, interruptions, current thread does not own the lock
-
isAcquiredInThisProcess
public boolean isAcquiredInThisProcess()
Description copied from interface:InterProcessLockReturns true if the mutex is acquired by a thread in this JVM- Specified by:
isAcquiredInThisProcessin interfaceInterProcessLock- Returns:
- true/false
-
-