org.objectweb.jotm.core.conflict
Interface Lock

All Known Implementing Classes:
BasicLock

public interface Lock

Lock represents a lock that can be acquired in several modes.


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.
 

Method Detail

getModes

public java.lang.String[] getModes()
Gets lock modes.

Returns:
array of lock modes

acquire

public java.lang.String acquire(Locker locker,
                                java.lang.String mode)
                         throws LockConflictException
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

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)
Tests if a lock of the given mode has been acquired by the given locker.

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)
Tests if a lock has been acquired by the given locker.

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
Check whether lock can be acquired. The method behaves the same as the 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.

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:
acquire(org.objectweb.jotm.core.conflict.Locker, java.lang.String), LockConversionTable

release

public void release(Locker locker)
             throws NoSuchLockException
Releases lock. The method releases a lock hold by the given locker.

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