Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## edu.emory.mathcs.util.remote.locks
Class RemoteEisMcGLock

    java.lang.Object
      edu.emory.mathcs.util.remote.locks.RemoteEisMcGLock

All Implemented Interfaces:
  java.rmi.Remote, RemoteLock

public class RemoteEisMcGLock
extends java.lang.Object
implements RemoteLock

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.

Author:
  Dirk Gorissen

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: The lock is acquired by the current thread; or Some other thread interrupts the current thread, and interruption of lock acquisition is supported.
`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: The lock is acquired by the current thread; or Some other thread interrupts the current thread, and interruption of lock acquisition is supported; or The specified waiting time elapses
`void` | `unlock()` Releases the remote lock.

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### RemoteEisMcGLock

    public RemoteEisMcGLock(RemoteEisMcGLock.Backend backend)

  Creates a new non-reentrant remote lock, synchronizing on a specified backend.

Parameters:
  `backend` - Backend to synchronize on

Method Detail

### lock

    public void lock()
              throws java.rmi.RemoteException

  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.

  Specified by:
    `lock` in interface `RemoteLock`
  Throws:
    `java.rmi.RemoteException` - if a communication error occurs

### lockInterruptibly

    public void lockInterruptibly()
                           throws java.lang.InterruptedException,
                                  java.rmi.RemoteException

  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:
  - The lock is acquired by the current thread; or
  - Some other thread interrupts the current thread, and interruption of lock acquisition is supported.

  Specified by:
    `lockInterruptibly` in interface `RemoteLock`
  Throws:
    `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).

### tryLock

    public boolean tryLock()
                    throws java.rmi.RemoteException

  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`.

  Specified by:
    `tryLock` in interface `RemoteLock`
  Returns:
    `true` if the lock was acquired and `false` otherwise.
  Throws:
    `java.rmi.RemoteException` - if a communication error occurs

### tryLock

    public boolean tryLock(long timeout,
                           TimeUnit unit)
                    throws java.lang.InterruptedException,
                           java.rmi.RemoteException

  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:
  - The lock is acquired by the current thread; or
  - Some other thread interrupts the current thread, and interruption of lock acquisition is supported; or
  - The specified waiting time elapses

  Specified by:
    `tryLock` in interface `RemoteLock`
  Parameters:
    `timeout` - the maximum time to wait for the lock
    `unit` - the time unit of the `time` argument.
  Returns:
    `true` if the lock was acquired and `false` if the waiting time elapsed before the lock was acquired.
  Throws:
    `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).

### newCondition

    public RemoteCondition newCondition()
                                 throws java.rmi.RemoteException

  Description copied from interface: `RemoteLock`
  Returns a new Condition instance that is bound to this `RemoteLock` instance. Before waiting on the condition the lock must be held by the current thread.

  Specified by:
    `newCondition` in interface `RemoteLock`
  Returns:
    A new Condition instance for this `RemoteLock` instance.
  Throws:
    `java.rmi.RemoteException`

### unlock

    public void unlock()
                throws java.rmi.RemoteException

  Releases the remote lock.

  Specified by:
    `unlock` in interface `RemoteLock`
  Throws:
    `java.rmi.RemoteException` - if a communication error occurs

### hashCode

    public int hashCode()

### equals

    public boolean equals(java.lang.Object other)

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD