org.objectweb.jotm.impl.core.conflict
Class BasicLock

java.lang.Object
  |
  +--org.objectweb.jotm.impl.core.conflict.BasicLock
All Implemented Interfaces:
Lock

public class BasicLock
extends java.lang.Object
implements Lock

Basic Lock is a simple lock implementation.


Constructor Summary
BasicLock(ConflictTable iTable)
           
 
Method Summary
 java.lang.String acquire(Locker locker, java.lang.String mode)
          Acquires lock.
 java.lang.String checkAcquire(Locker locker, java.lang.String mode)
          Check whether lock can be acquired.
 java.lang.String[] getModes()
          Gets lock modes.
 boolean isAcquired(Locker locker)
          Tests if a lock has been acquired by the given locker.
 boolean isAcquired(Locker locker, java.lang.String mode)
          Tests if a lock of the given mode has been acquired by the given locker.
 void release(Locker locker)
          Releases lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicLock

public BasicLock(ConflictTable iTable)
Method Detail

getModes

public java.lang.String[] getModes()
Description copied from interface: Lock
Gets lock modes.

Specified by:
getModes in interface Lock
Returns:
array of lock modes

acquire

public java.lang.String acquire(Locker locker,
                                java.lang.String mode)
                         throws LockConflictException
Description copied from interface: Lock
Acquires lock. The method acquires this lock in the name of the given Locker in the given mode. If the lock has been acquired before by another Locker in a conflicting mode, then the current thread is suspended and waits for the lock release. The method finishes when the lock is not acquired by a conflicting mode by another Locker and lock can be acquired by the given Locker
If the lock has been acquired by the same Locker before, the existing lock mode is converted to a new one, which is supremum of the existing mode and the requested one according to the lock conversion table.
The method returns the mode that was effectively acquired. This is the requested mode if the locker has not acquired this lock before, or the supremum of the current and requested modes

Specified by:
acquire in interface Lock
Parameters:
locker - an entity in name of which the lock is locked
mode - requested lock mode
Returns:
effective lock acquired
Throws:
LockConflictException - if there is conflict between the current lock mode acquired by the locker and the requested mode (the supremum mode does not exist)
See Also:
LockConversionTable

isAcquired

public boolean isAcquired(Locker locker,
                          java.lang.String mode)
Description copied from interface: Lock
Tests if a lock of the given mode has been acquired by the given locker.

Specified by:
isAcquired in interface Lock
Parameters:
locker - an entity in name of which the lock is locked
mode - requested lock mode
Returns:
true if such a lock has been acquired, false otherwise

isAcquired

public boolean isAcquired(Locker locker)
Description copied from interface: Lock
Tests if a lock has been acquired by the given locker.

Specified by:
isAcquired in interface Lock
Parameters:
locker - an entity in name of which the lock is locked
Returns:
true if such a lock has been acquired, false otherwise

checkAcquire

public java.lang.String checkAcquire(Locker locker,
                                     java.lang.String mode)
                              throws LockConflictException
Description copied from interface: Lock
Check whether lock can be acquired. The method behaves the same as the Lock.acquire(org.objectweb.jotm.core.conflict.Locker, java.lang.String) method, but the lock is not acquired and the current thread is never suspended due to the lock acquired by another locker.

Specified by:
checkAcquire in interface Lock
Parameters:
locker - an entity in name of which the lock is locked
mode - requested lock mode
Returns:
effective lock that would be acquired, null if the lock has been acquired by another locker in a conflicting mode (i.e., null signalizes that the current thread would be suspended if the given locker will acquire the lock in the given mode.
Throws:
LockConflictException - if there is conflict between the current lock mode acquired by the locker and the requested mode (the supremum mode does not exist)
See Also:
Lock.acquire(org.objectweb.jotm.core.conflict.Locker, java.lang.String), LockConversionTable

release

public void release(Locker locker)
             throws NoSuchLockException
Description copied from interface: Lock
Releases lock. The method releases a lock hold by the given locker.

Specified by:
release in interface Lock
Parameters:
locker - an entity in name of which the lock is locked
Throws:
NoSuchLockException - if there is no lock hold by the given locker