Top Description Fields Constructors Methods
org.apache.derby.impl.services.locks

pack-priv final Class LockControl

extends Object
implements Control
Class Inheritance
All Implemented Interfaces
org.apache.derby.impl.services.locks.Control
Imports
org.apache.derby.iapi.services.locks.CompatibilitySpace, .Lockable, .Latch, .LockOwner, org.apache.derby.shared.common.sanity.SanityManager, java.util.List, .ListIterator, .Map

A LockControl contains a reference to the item being locked and doubly linked lists for the granted locks and the waiting locks.

MT - Mutable - Container object : single thread required

Field Summary

Modifier and TypeField and Description
private Lock
firstGrant

This lock control uses an optimistic locking scheme.

private List<Lock>
private Lock
private final Lockable
private List<Lock>

Constructor Summary

AccessConstructor and Description
protected
LockControl(Lock firstLock, Lockable ref)

private

Method Summary

Modifier and TypeMethod and Description
public Lock
addLock(LockTable ls, CompatibilitySpace compatibilitySpace, Object qualifier)

Add a lock into this control, granted it if possible.

private void
addWaiter(Lock
The lock request
lockItem
,
LockTable
The lock table
ls
)

Add a lock request to a list of waiters.

public void
addWaiters(Map<Object, Object> waiters)

Implements org.apache.derby.impl.services.locks.Control.addWaiters.

Add the waiters of this lock into this Map object.

public boolean
blockedByParent(Lock childLock)

Returns true if the childLock is blocked because its parent owns a conficting lock.

public ActiveLock
firstWaiter()

Implements org.apache.derby.impl.services.locks.Control.firstWaiter.

Return the first lock in the wait line, null if the line is empty.

public Lock
public List<Lock>
pack-priv List<Lock>
getGrants()

Return a Stack of the held locks (Lock objects) on this Lockable.

public final Lock
getLock(CompatibilitySpace compatibilitySpace, Object qualifier)

Implements org.apache.derby.impl.services.locks.Control.getLock.

Find a granted lock matching this space and qualifier

public Lockable
getLockable()

Implements org.apache.derby.impl.services.locks.Control.getLockable.

Return the lockable object controlled by me.

public LockControl
pack-priv ActiveLock
getNextWaiter(ActiveLock item, boolean remove, LockTable ls)

Get the next waiting lock (if any).

public List<Lock>
protected void
giveUpWait(Object item, LockTable ls)

Give up waiting up on a lock

pack-priv void
grant(Lock lockItem)

Grant this lock.

public boolean
public boolean
isGrantable(boolean noWaitersBeforeMe, CompatibilitySpace compatibilitySpace, Object qualifier)

Implements org.apache.derby.impl.services.locks.Control.isGrantable.

This routine can be called to see if a lock currently on the wait list could be granted.

protected boolean
private Object

Returns:

The removed lock request
popFrontWaiter
(LockTable
The lock table
ls
)

Remove and return the first lock request from a list of waiters.

private Object

Returns:

The removed lock request
removeWaiter
(int
The index at which to remove the lock request
index
,
LockTable
The lock table
ls
)

Remove and return the lock request at the given index from a list of waiters.

private int

Returns:

The number of items removed
removeWaiter
(Object
The item to remove
item
,
LockTable
The lock table
ls
)

Remove and return the given lock request from a list of waiters.

public Control
shallowClone()

Implements org.apache.derby.impl.services.locks.Control.shallowClone.

make a shallow clone of myself

public boolean
unlock(Latch lockInGroup, int unlockCount)

Implements org.apache.derby.impl.services.locks.Control.unlock.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

firstGrantback to summary
private Lock 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.

grantedback to summary
private List<Lock> granted
lastPossibleSkipback to summary
private Lock lastPossibleSkip
refback to summary
private final Lockable ref
waitingback to summary
private List<Lock> waiting

Constructor Detail

LockControlback to summary
protected LockControl(Lock firstLock, Lockable ref)
LockControlback to summary
private LockControl(LockControl copyFrom)

Method Detail

addLockback to summary
public Lock addLock(LockTable ls, CompatibilitySpace compatibilitySpace, Object qualifier)

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,
  • addWaiterback to summary
    private void addWaiter(Lock lockItem, LockTable ls)

    Add a lock request to a list of waiters.

    Parameters
    lockItem:Lock

    The lock request

    ls:LockTable

    The lock table

    addWaitersback to summary
    public void addWaiters(Map<Object, Object> waiters)

    Implements org.apache.derby.impl.services.locks.Control.addWaiters.

    Add the waiters of this lock into this Map object.
    Each waiting thread gets two entries in the hashtable

    1. key=compatibility space - value=ActiveLock
    2. key=ActiveLock - value={LockControl for first waiter|ActiveLock of previosue waiter}
    blockedByParentback to summary
    public boolean blockedByParent(Lock childLock)

    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.

    firstWaiterback to summary
    public ActiveLock firstWaiter()

    Implements org.apache.derby.impl.services.locks.Control.firstWaiter.

    Return the first lock in the wait line, null if the line is empty.

    getFirstGrantback to summary
    public Lock getFirstGrant()

    Implements org.apache.derby.impl.services.locks.Control.getFirstGrant.

    getGrantedback to summary
    public List<Lock> getGranted()

    Implements org.apache.derby.impl.services.locks.Control.getGranted.

    getGrantsback to summary
    pack-priv List<Lock> getGrants()

    Return a Stack of the held locks (Lock objects) on this Lockable.

    getLockback to summary
    public final Lock getLock(CompatibilitySpace compatibilitySpace, Object qualifier)

    Implements org.apache.derby.impl.services.locks.Control.getLock.

    Find a granted lock matching this space and qualifier

    getLockableback to summary
    public Lockable getLockable()

    Implements org.apache.derby.impl.services.locks.Control.getLockable.

    Return the lockable object controlled by me.

    getLockControlback to summary
    public LockControl getLockControl()

    Implements org.apache.derby.impl.services.locks.Control.getLockControl.

    getNextWaiterback to summary
    pack-priv ActiveLock getNextWaiter(ActiveLock item, boolean remove, LockTable ls)

    Get the next waiting lock (if any).

    getWaitingback to summary
    public List<Lock> getWaiting()

    Implements org.apache.derby.impl.services.locks.Control.getWaiting.

    giveUpWaitback to summary
    protected void giveUpWait(Object item, LockTable ls)

    Give up waiting up on a lock

    grantback to summary
    pack-priv void grant(Lock lockItem)

    Grant this lock.

    isEmptyback to summary
    public boolean isEmpty()

    Implements org.apache.derby.impl.services.locks.Control.isEmpty.

    isGrantableback to summary
    public boolean isGrantable(boolean noWaitersBeforeMe, CompatibilitySpace compatibilitySpace, Object qualifier)

    Implements org.apache.derby.impl.services.locks.Control.isGrantable.

    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.

    isUnlockedback to summary
    protected boolean isUnlocked()
    popFrontWaiterback to summary
    private Object popFrontWaiter(LockTable ls)

    Remove and return the first lock request from a list of waiters.

    Parameters
    ls:LockTable

    The lock table

    Returns:Object

    The removed lock request

    removeWaiterback to summary
    private Object removeWaiter(int index, LockTable ls)

    Remove and return the lock request at the given index from a list of waiters.

    Parameters
    index:int

    The index at which to remove the lock request

    ls:LockTable

    The lock table

    Returns:Object

    The removed lock request

    removeWaiterback to summary
    private int removeWaiter(Object item, LockTable ls)

    Remove and return the given lock request from a list of waiters.

    Parameters
    item:Object

    The item to remove

    ls:LockTable

    The lock table

    Returns:int

    The number of items removed

    shallowCloneback to summary
    public Control shallowClone()

    Implements org.apache.derby.impl.services.locks.Control.shallowClone.

    make a shallow clone of myself

    unlockback to summary
    public boolean unlock(Latch lockInGroup, int unlockCount)

    Implements org.apache.derby.impl.services.locks.Control.unlock.