|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.bigdata.concurrent.ResourceQueue<R,T>
public class ResourceQueue<R,T>
Unbounded queue of operations waiting to gain an exclusive lock on a
resource. By default, the queue imposes a "fair" schedule for access to the
resource. Deadlocks among resources are detected using a
WAITS_FOR graph that is shared by all resources and
transactions for a given database instance.
Note: deadlock detection MAY be disabled when all lock requests are (a)
pre-declared; and (b) sorted. When disabled the WAITS_FOR
graph is NOT maintained.
LockManager,
TxDag| Field Summary | |
|---|---|
protected static boolean |
DEBUG
|
protected static boolean |
INFO
|
protected static org.apache.log4j.Logger |
log
|
| Constructor Summary | |
|---|---|
ResourceQueue(R resource,
TxDag waitsFor)
Create a queue of lock requests for a resource. |
|
| Method Summary | |
|---|---|
void |
clear(T tx)
Causes pending lock requests to abort (the threads that are blocked will throw an InterruptedException) and releases the lock
held by the caller. |
int |
getQueueSize()
The #of pending requests for a lock on the resource. |
R |
getResource()
The resource whose locks are administeded by this object. |
boolean |
isGranted(T tx)
Return true if the transaction currently holds the lock. |
boolean |
isLocked()
True iff a lock is granted. |
void |
lock(T tx)
Obtain a lock on the resource. |
void |
lock(T tx,
long timeout)
Obtain a lock on the resource. |
String |
toString()
Note: This uses LinkedBlockingQueue.toString() to serialize
the state of the resource queue so the result will be consistent per
the contract of that method and
LinkedBlockingQueue.iterator(). |
void |
unlock(T tx)
Release the lock held by the tx on the resource. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected static final org.apache.log4j.Logger log
protected static final boolean INFO
protected static final boolean DEBUG
| Constructor Detail |
|---|
public ResourceQueue(R resource,
TxDag waitsFor)
resource - The resource.waitsFor - The WAITS_FOR graph shared by all transactions and all
resources (optional). When NOT specified operations MUST
pre-declare their locks and the LockManager MUST sort
the resources in each lock request into a common order such
that deadlocks CAN NOT occur.| Method Detail |
|---|
public R getResource()
public boolean isLocked()
public int getQueueSize()
public boolean isGranted(T tx)
tx - The transaction.public String toString()
LinkedBlockingQueue.toString() to serialize
the state of the resource queue so the result will be consistent per
the contract of that method and
LinkedBlockingQueue.iterator().
toString in class Object
public void lock(T tx)
throws InterruptedException,
DeadlockException
tx - The transaction.
InterruptedException - if the lock was interrupted (the transaction should
handle this exception by aborting).
DeadlockException - if the request would cause a deadlock among the running
transactions.
public void lock(T tx,
long timeout)
throws InterruptedException,
DeadlockException
tx - The transaction.timeout - The timeout (ms) -or- 0L to wait forever.
InterruptedException - if the lock was interrupted (the transaction should handle
this exception by aborting).
DeadlockException - if the request would cause a deadlock among the running
transactions.public void unlock(T tx)
tx - The transaction.
IllegalStateException - if the transaction does not hold the lock.public void clear(T tx)
InterruptedException) and releases the lock
held by the caller.
tx - The transaction.
IllegalStateException - if the transaction does not hold the lock.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||