|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.emory.mathcs.util.remote.locks.RemoteEisMcGLock
This class provides a generic implementation of a distributed, non-reentrant mutual exclusion lock, based on Eisenberg and MgGuire's algorithm.
There are N processes (N may vary) who share some form of memory. This memory may be phisical memory, a remote database,... just some resource that enables the N processes to maintain some global state. Each of the N processes has in its code a Critical Section (CS) and at any point in time only one process can be in its CS. To enforce this we need a mutual exclusion mechanism which enforces mutual exclusion for N processes with shared memory. Many algorithms that do this exist, here the algorithm used is Eisenberg and McGuire's Algorithm. Source: http://www.cs.wvu.edu/~jdm/classes/cs356/notes/mutex/Eisenberg.html
To maintain global state the algorithm uses a list of flags where each flag[i] holds the state of of process i. The state is one of IDLE, WAITING or ACTIVE. In addition a global turn variable is kept which is set to i if process i is in its CS.
Since this class is a generic implementation of the algorithm the exact communication
mechanism is left up to the user. Processes may coordinate through a Jini LUS,
a JavaSpace, a SQL Database, an in memory hashmap, etc. All that is required is that
the user implements the RemoteEisMcGLock.Backend
interface and passes an instance of the implementation
to this class.
Nested Class Summary | |
static interface |
RemoteEisMcGLock.Backend
|
static class |
RemoteEisMcGLock.Participant
|
Constructor Summary | |
RemoteEisMcGLock(RemoteEisMcGLock.Backend backend)
Creates a new non-reentrant remote lock, synchronizing on a specified backend. |
Method Summary | |
boolean |
equals(java.lang.Object other)
|
int |
hashCode()
|
void |
lock()
Acquires the remote lock. If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until the lock has been acquired. |
void |
lockInterruptibly()
Acquires the remote lock unless the current thread is interrupted. If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:
|
RemoteCondition |
newCondition()
Returns a new Condition instance that is bound to this RemoteLock instance. |
boolean |
tryLock()
Acquires the remote lock only if it is free at the time of invocation. If the lock is not available then this method will return immediately with the value false. |
boolean |
tryLock(long timeout,
TimeUnit unit)
Acquires the remote lock if it is free within the given waiting time and the current thread has not been interrupted. If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happens:
|
void |
unlock()
Releases the remote lock. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public RemoteEisMcGLock(RemoteEisMcGLock.Backend backend)
backend
- Backend to synchronize onMethod Detail |
public void lock() throws java.rmi.RemoteException
lock
in interface RemoteLock
java.rmi.RemoteException
- if a communication error occurspublic void lockInterruptibly() throws java.lang.InterruptedException, java.rmi.RemoteException
lockInterruptibly
in interface RemoteLock
java.rmi.RemoteException
- if a communication error occurs
java.lang.InterruptedException
- if the current thread is interrupted
while acquiring the lock (and interruption of lock acquisition is
supported).public boolean tryLock() throws java.rmi.RemoteException
tryLock
in interface RemoteLock
java.rmi.RemoteException
- if a communication error occurspublic boolean tryLock(long timeout, TimeUnit unit) throws java.lang.InterruptedException, java.rmi.RemoteException
tryLock
in interface RemoteLock
timeout
- the maximum time to wait for the lockunit
- the time unit of the time argument.
java.rmi.RemoteException
- if a communication error occurs
java.lang.InterruptedException
- if the current thread is interrupted
while acquiring the lock (and interruption of lock acquisition is
supported).public RemoteCondition newCondition() throws java.rmi.RemoteException
RemoteLock
newCondition
in interface RemoteLock
java.rmi.RemoteException
public void unlock() throws java.rmi.RemoteException
unlock
in interface RemoteLock
java.rmi.RemoteException
- if a communication error occurspublic int hashCode()
public boolean equals(java.lang.Object other)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |