Class LockControl
java.lang.Object
org.apache.derby.impl.services.locks.LockControl
- All Implemented Interfaces:
Control
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateLockControl(LockControl copyFrom) protectedLockControl(Lock firstLock, Lockable ref) -
Method Summary
Modifier and TypeMethodDescriptionaddLock(LockTable ls, CompatibilitySpace compatibilitySpace, Object qualifier) Add a lock into this control, granted it if possible.private voidAdd a lock request to a list of waiters.voidaddWaiters(Map<Object, Object> waiters) Add the waiters of this lock into this Map object.booleanblockedByParent(Lock childLock) Returns true if the childLock is blocked because its parent owns a conficting lock.Return the first lock in the wait line, null if the line is empty.Return a Stack of the held locks (Lock objects) on this Lockable.final LockgetLock(CompatibilitySpace compatibilitySpace, Object qualifier) Find a granted lock matching this space and qualifierReturn the lockable object controlled by me.(package private) ActiveLockgetNextWaiter(ActiveLock item, boolean remove, LockTable ls) Get the next waiting lock (if any).protected voidgiveUpWait(Object item, LockTable ls) Give up waiting up on a lock(package private) voidGrant this lock.booleanisEmpty()booleanisGrantable(boolean noWaitersBeforeMe, CompatibilitySpace compatibilitySpace, Object qualifier) This routine can be called to see if a lock currently on the wait list could be granted.protected booleanprivate ObjectRemove and return the first lock request from a list of waiters.private ObjectremoveWaiter(int index, LockTable ls) Remove and return the lock request at the given index from a list of waiters.private intremoveWaiter(Object item, LockTable ls) Remove and return the given lock request from a list of waiters.make a shallow clone of myselfboolean
-
Field Details
-
ref
-
firstGrant
This lock control uses an optimistic locking scheme. When the first lock on an object is granted it simply sets firstGrant to be that object, removing the need to allocate a list if no other locks are granted before the first lock is release. If a second lock is granted then a list is allocated and the firstGrant lock is moved into the list. Once a list has been created it is always used. -
granted
-
waiting
-
lastPossibleSkip
-
-
Constructor Details
-
LockControl
-
LockControl
-
-
Method Details
-
getLockControl
- Specified by:
getLockControlin interfaceControl
-
isEmpty
-
grant
Grant this lock. -
unlock
-
isGrantable
public boolean isGrantable(boolean noWaitersBeforeMe, CompatibilitySpace compatibilitySpace, Object qualifier) This routine can be called to see if a lock currently on the wait list could be granted. If this lock has waiters ahead of it then we do not jump over the waiter(s) even if we can be granted. This avoids the first waiter being starved out.- Specified by:
isGrantablein interfaceControl
-
addLock
Add a lock into this control, granted it if possible. This can be entered in several states.- The Lockable is locked (granted queue not empty), and there are no waiters (waiting queue is empty)
- The Lockable is locked and there are waiters
- The Lockable is locked and there are waiters and the first is potentially granted
- The Lockable is unlocked and there are waiters and the first is potentially granted. Logically the item is still locked, it's just that the lock has just been released and the first waker has not woken up yet. This call is never entered when the object is unlocked and there are no waiters. 1) The Lockable has just been unlocked,
-
isUnlocked
protected boolean isUnlocked() -
firstWaiter
Return the first lock in the wait line, null if the line is empty.- Specified by:
firstWaiterin interfaceControl
-
getNextWaiter
Get the next waiting lock (if any). -
getLockable
Return the lockable object controlled by me.- Specified by:
getLockablein interfaceControl
-
getFirstGrant
- Specified by:
getFirstGrantin interfaceControl
-
getGranted
- Specified by:
getGrantedin interfaceControl
-
getWaiting
- Specified by:
getWaitingin interfaceControl
-
giveUpWait
-
addWaiters
Add the waiters of this lock into this Map object.
Each waiting thread gets two entries in the hashtable- key=compatibility space - value=ActiveLock
- key=ActiveLock - value={LockControl for first waiter|ActiveLock of previosue waiter}
- Specified by:
addWaitersin interfaceControl
-
getGrants
-
getLock
Find a granted lock matching this space and qualifier -
blockedByParent
Returns true if the childLock is blocked because its parent owns a conficting lock. This code was written to support the fix to DERBY-6554. The only known way that this condition arises is when a write attempt by a nested user transaction is blocked by a read lock held by the main transaction. This only happens while trying to write to SYS.SYSSEQUENCES while managing sequence generators.
-
shallowClone
make a shallow clone of myself- Specified by:
shallowClonein interfaceControl
-
addWaiter
-
popFrontWaiter
-
removeWaiter
-
removeWaiter
-