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

java.lang.Object
  |
  +--org.objectweb.jotm.impl.core.conflict.TransactionalLock

public class TransactionalLock
extends java.lang.Object

Transactional Lock is a transaction-aware lock implementation. It wraps BasicLock and uses the transaction associated with the current thread as locker.


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

Constructor Detail

TransactionalLock

public TransactionalLock(ConflictTable table)
Constructs transactional lock.

Parameters:
table - conflict table for the lock
Method Detail

getModes

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

Returns:
lock modes

acquire

public java.lang.String acquire(java.lang.String mode)
                         throws LockConflictException,
                                NoTransactionException
Acquires transactional lock. The method acquires this lock for the transaction associated with the current thread. If there is none, the NoTransactionException is thrown.

Parameters:
mode - requested lock mode
Returns:
effective lock acquired
Throws:
LockConflictException - if there is conflict between the current lock mode acquired by the current transaction and the requested mode (the supremum mode does not exist)
NoTransactionException - if no transaction is associated with the current thread
See Also:
Lock, LockConversionTable

release

public void release()
             throws NoSuchLockException,
                    NoTransactionException
Releases transactional lock. The method releaes a lock acquired by the transaction associated with the current thread. If there is none, the NoTransactionException is thrown.

Throws:
NoSuchLockException - if there is no lock hold by the current transaction
NoTransactionException - if no transaction is associated with the current thread
See Also:
Lock

isAcquired

public boolean isAcquired(java.lang.String mode)
                   throws NoTransactionException
Tests if a lock of the given mode has been acquired by the current transaction.

Parameters:
mode - requested lock mode
Returns:
true if such a lock has been acquired, false otherwise
Throws:
NoTransactionException - if no transaction is associated with the current thread
See Also:
Lock

isAcquired

public boolean isAcquired()
                   throws NoTransactionException
Tests if a lock has been acquired by the current transaction.

Returns:
true if such a lock has been acquired, false otherwise
Throws:
NoTransactionException - if no transaction is associated with the current thread
See Also:
Lock

checkAcquire

public java.lang.String checkAcquire(java.lang.String mode)
                              throws LockConflictException,
                                     NoTransactionException
Check whether lock can be acquired. The method behaves the same as the acquire(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:
mode - requested lock mode
Returns:
effective lock that would be acquired, null if the lock has been acquired by another transaction in a conflicting mode (i.e., null signalizes that the current thread would be suspended if the current transaction will acquire the lock in the given mode.
Throws:
LockConflictException - if there is conflict between the current lock mode acquired by the current transaction and the requested mode (the supremum mode does not exist)
NoTransactionException - if no transaction is associated with the current thread
See Also:
acquire(java.lang.String), Lock, LockConversionTable