|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.exolab.core.foundation.Lock
Exclusive lock and lock synchronization on an object. Each object (session, entity bean, etc) is required to have one Lock which is served as an exclusive lock. Only one transaction can acquire the lock at any given time, but multiple transactions may be waiting to acquire a lock.
In order to obtain a lock, the transaction must call acquire(org.exolab.core.foundation.TransactionContext, int)
passing itself and the lock timeout. The transaction must
attempt to obtain only one lock at any given time by synchronizing
all calls to acquire(org.exolab.core.foundation.TransactionContext, int)
.
Locks implement reference counting. The transaction may acquire the same lock any number of times, but must also release it the same number of times (in no particular order).
If a lock cannot be acquired, the transaction will hold until the
lock is available or timeout occurs. If timeout occured (or a dead
lock has been detected), LockNotGrantedException
is thrown.
If the object has been deleted while waiting for the lock, ObjectDeletedException
is thrown.
When the lock is acquired, acquire(org.exolab.core.foundation.TransactionContext, int)
will return the locked
object.
The transaction must call release(org.exolab.core.foundation.TransactionContext)
when the lock is no
longer required, allowing other transactions to obtain a lock. The
transaction must release all references to the object prior to
calling release(org.exolab.core.foundation.TransactionContext)
.
If the object has been deleted, the transaction must call delete(org.exolab.core.foundation.TransactionContext)
instead of release(org.exolab.core.foundation.TransactionContext)
.
TransactionContext
Constructor Summary | |
Lock(PersistentCapableIfc obj)
Create a new lock for the specified object. |
Method Summary | |
PersistentCapableIfc |
acquire(TransactionContext tx,
int timeout)
Acquires a lock on the object on behalf of the specified transaction. |
boolean |
anyTxWaiting()
Check to see if the current transaction context owns the lock and that no other transaction is queued waiting for it. |
void |
delete(TransactionContext tx)
Informs the lock that the object has been deleted by the transaction holding the lock. |
PersistentCapableIfc |
getObject()
Return a reference to the object that this lock guards |
boolean |
hasLock(TransactionContext tx)
Returns true if the transaction holds a lock on the object. |
void |
release(TransactionContext tx)
Releases a lock on the object previously acquired with acquire(org.exolab.core.foundation.TransactionContext, int) . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Lock(PersistentCapableIfc obj)
acquire(org.exolab.core.foundation.TransactionContext, int)
.
obj
- The object to create a lock forMethod Detail |
public boolean hasLock(TransactionContext tx)
tx
- The transaction
public PersistentCapableIfc getObject()
public PersistentCapableIfc acquire(TransactionContext tx, int timeout) throws LockNotGrantedException, ObjectDeletedWaitingForLockException
LockNotGrantedException
is thrown.
If the object has been deleted while waiting for a lock, a ObjectDeletedException
is thrown. To prevent dead locks, a
transaction must only call this method for any given object
from a single thread and must mark the lock it is trying to
acquire and return it from a call to TransactionContext#getWaitingOnLock
if the call to this method
has not returned yet. If this method has been called multiple times
by the same transaction, then release(org.exolab.core.foundation.TransactionContext)
must be called the
same number of times to release the lock.
tx
- The transaction requesting the locktimeout
- Timeout waiting to acquire lock (in milliseconds),
zero for no waiting
LockNotGrantedException
- Lock could not be granted in
the specified timeout or a dead lock has been detected
ObjectDeletedWaitingForLockException
- The object has
been deleted while waiting for the lockpublic void release(TransactionContext tx)
acquire(org.exolab.core.foundation.TransactionContext, int)
. This method must be called one time for each time
acquire(org.exolab.core.foundation.TransactionContext, int)
was called. After the lock is fully released,
other transactions might acquire it.
tx
- The transaction that holds the lockpublic boolean anyTxWaiting()
public void delete(TransactionContext tx)
ObjectDeletedException
.
tx
- The transaction that holds the lock
java.lang.RuntimeException
- Attempt to delete object without
acquiring a write lock
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |