public class ResourceQueue<R,T> extends Object
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
Modifier and Type | Field and Description |
---|---|
protected static boolean |
DEBUG |
protected static boolean |
INFO |
protected static org.apache.log4j.Logger |
log |
Constructor and Description |
---|
ResourceQueue(R resource,
TxDag waitsFor)
Create a queue of lock requests for a resource.
|
Modifier and Type | Method and Description |
---|---|
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.
|
protected static final org.apache.log4j.Logger log
protected static final boolean INFO
protected static final boolean DEBUG
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.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()
.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.Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.