public class MutexSupport extends java.lang.Object implements WithMutexes
Constructor and Description |
---|
MutexSupport() |
Modifier and Type | Method and Description |
---|---|
void |
acquireMutex(java.lang.String mutexId,
java.lang.String description)
acquires a mutex, if available, otherwise blocks on its becoming available;
caller must release after use
|
void |
cleanup() |
void |
cleanupMutex(java.lang.String mutexId)
forces deletion of the given mutex if it is unused;
normally not required as is done automatically on close
(but possibly needed where there are cancelations and risk of memory leaks)
|
java.util.Map<java.lang.String,SemaphoreWithOwners> |
getAllSemaphores()
Returns the semaphores in use at the time the method is called, for inspection purposes (and testing).
|
boolean |
hasMutex(java.lang.String mutexId)
returns true if the calling thread has the mutex with the given ID
|
void |
releaseMutex(java.lang.String mutexId)
releases a mutex, triggering another thread to use it or cleaning it up if no one else is waiting;
this should only be called by the mutex owner (thread)
|
java.lang.String |
toString() |
boolean |
tryAcquireMutex(java.lang.String mutexId,
java.lang.String description)
acquires a mutex and returns true, if available; otherwise immediately returns false;
caller must release after use if this returns true
|
public void cleanupMutex(java.lang.String mutexId)
public void cleanup()
public boolean hasMutex(java.lang.String mutexId)
WithMutexes
hasMutex
in interface WithMutexes
public void acquireMutex(java.lang.String mutexId, java.lang.String description) throws java.lang.InterruptedException
WithMutexes
acquireMutex
in interface WithMutexes
java.lang.InterruptedException
public boolean tryAcquireMutex(java.lang.String mutexId, java.lang.String description)
WithMutexes
tryAcquireMutex
in interface WithMutexes
public void releaseMutex(java.lang.String mutexId)
WithMutexes
releaseMutex
in interface WithMutexes
public java.lang.String toString()
toString
in class java.lang.Object
public java.util.Map<java.lang.String,SemaphoreWithOwners> getAllSemaphores()