org.apache.derby.impl.services.locks
Class LockSet

java.lang.Object
  extended by org.apache.derby.impl.services.locks.LockSet
All Implemented Interfaces:
LockTable

final class LockSet
extends java.lang.Object
implements LockTable

A LockSet is a complete lock table. A lock table is a hash table keyed by a Lockable and with a LockControl as the data element.

A LockControl contains information about the locks held on a Lockable.
MT - Mutable - Container Object : All non-private methods of this class are thread safe unless otherwise stated by their javadoc comments.
All searching of the hashtable is performed using java synchroization(this).
The class creates ActiveLock and LockControl objects. LockControl objects are never passed out of this class, All the methods of LockControl are called while being synchronized on this, thus providing the single threading that LockControl required. Methods of Lockables are only called by this class or LockControl, and always while being synchronized on this, thus providing the single threading that Lockable requires.

See Also:
LockControl

Field Summary
private  int blockCount
           
private  int deadlockTimeout
          Timeout for deadlocks, in ms.
private  boolean deadlockTrace
           
private  SinglePool factory
           
private  java.util.HashMap locks
          Hash table which maps Lockable objects to Locks.
private  int waitTimeout
           
 
Constructor Summary
protected LockSet(SinglePool factory)
           
 
Method Summary
 void addWaiters(java.util.Map waiters)
          Add all waiters in this lock table to a Map object.
 boolean anyoneBlocked()
          Check whether there are anyone blocked in the lock table.
private  Control getControl(Lockable ref)
          Get the Control for an object in the lock table.
 int getWaitTimeout()
          Get the wait timeout in milliseconds.
 Lock lockObject(CompatibilitySpace compatibilitySpace, Lockable ref, java.lang.Object qualifier, int timeout)
          Lock an object within a specific compatibility space.
 void oneLessWaiter()
          Decrease blockCount by one.
 void oneMoreWaiter()
          Increase blockCount by one.
 void setDeadlockTimeout(int timeout)
          Set the deadlock timeout.
 void setDeadlockTrace(boolean val)
          Enable or disable tracing of deadlocks.
 void setWaitTimeout(int timeout)
          Set the wait timeout.
 java.util.Map shallowClone()
          make a shallow clone of myself and my lock controls
 java.lang.String toDebugString()
           
 void unlock(Latch item, int unlockCount)
          Unlock an object, previously locked by lockObject().
 Lock unlockReference(CompatibilitySpace space, Lockable ref, java.lang.Object qualifier, java.util.Map group)
          Unlock an object once if it is present in the specified group.
 boolean zeroDurationLockObject(CompatibilitySpace space, Lockable ref, java.lang.Object qualifier, int timeout)
          Lock an object and release the lock immediately.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

factory

private final SinglePool factory

locks

private final java.util.HashMap locks
Hash table which maps Lockable objects to Locks.


deadlockTimeout

private int deadlockTimeout
Timeout for deadlocks, in ms.
MT - immutable


waitTimeout

private int waitTimeout

deadlockTrace

private boolean deadlockTrace

blockCount

private int blockCount
Constructor Detail

LockSet

protected LockSet(SinglePool factory)
Method Detail

lockObject

public Lock lockObject(CompatibilitySpace compatibilitySpace,
                       Lockable ref,
                       java.lang.Object qualifier,
                       int timeout)
                throws StandardException
Lock an object within a specific compatibility space.

Specified by:
lockObject in interface LockTable
Parameters:
compatibilitySpace - Compatibility space.
ref - Lockable reference.
qualifier - Qualifier.
timeout - Timeout in milli-seconds
Returns:
Object that represents the lock.
Throws:
StandardException - Standard Derby policy.

unlock

public void unlock(Latch item,
                   int unlockCount)
Unlock an object, previously locked by lockObject(). If unlockCOunt is not zero then the lock will be unlocked that many times, otherwise the unlock count is taken from item.

Specified by:
unlock in interface LockTable
Parameters:
item - the lock to unlock
unlockCount - the number of times to unlock the item; or zero, meaning take the unlock count from the item

unlockReference

public Lock unlockReference(CompatibilitySpace space,
                            Lockable ref,
                            java.lang.Object qualifier,
                            java.util.Map group)
Unlock an object once if it is present in the specified group. Also remove the object from the group.

Specified by:
unlockReference in interface LockTable
Parameters:
space - the compatibility space
ref - a reference to the locked object
qualifier - qualifier of the lock
group - a map representing the locks in a group
Returns:
the corresponding lock in the group map, or null if the object was not unlocked

zeroDurationLockObject

public boolean zeroDurationLockObject(CompatibilitySpace space,
                                      Lockable ref,
                                      java.lang.Object qualifier,
                                      int timeout)
                               throws StandardException
Lock an object and release the lock immediately. Equivalent to
 Lock lock = lockTable.lockObject(space, ref, qualifier, timeout);
 lockTable.unlock(lock, 1);
 
except that the implementation might be more efficient.

Specified by:
zeroDurationLockObject in interface LockTable
Parameters:
space - the compatibility space
ref - a reference to the locked object
qualifier - qualifier of the lock
timeout - maximum time to wait in milliseconds (C_LockFactory.NO_WAIT means don't wait)
Returns:
true if the object was locked, or false if the object couldn't be locked immediately and timeout was NO_WAIT or LockOwner had the noWait flag set
Throws:
StandardException - if the lock could not be obtained

setDeadlockTimeout

public void setDeadlockTimeout(int timeout)
Set the deadlock timeout.

Specified by:
setDeadlockTimeout in interface LockTable
Parameters:
timeout - deadlock timeout in milliseconds

setWaitTimeout

public void setWaitTimeout(int timeout)
Set the wait timeout.

Specified by:
setWaitTimeout in interface LockTable
Parameters:
timeout - wait timeout in milliseconds

getWaitTimeout

public int getWaitTimeout()
Get the wait timeout in milliseconds.

Specified by:
getWaitTimeout in interface LockTable

setDeadlockTrace

public void setDeadlockTrace(boolean val)
Description copied from interface: LockTable
Enable or disable tracing of deadlocks.

Specified by:
setDeadlockTrace in interface LockTable
Parameters:
val - true enables tracing, false disables tracing

toDebugString

public java.lang.String toDebugString()

addWaiters

public void addWaiters(java.util.Map waiters)
Add all waiters in this lock table to a Map object.
MT - must be synchronized on this LockSet object.

Specified by:
addWaiters in interface LockTable
Parameters:
waiters - the map to add the waiters to
See Also:
LockControl.addWaiters(java.util.Map)

shallowClone

public java.util.Map shallowClone()
make a shallow clone of myself and my lock controls

Specified by:
shallowClone in interface LockTable
Returns:
a shallow clone of the lock table

oneMoreWaiter

public void oneMoreWaiter()
Increase blockCount by one.
MT - must be synchronized on this LockSet object.

Specified by:
oneMoreWaiter in interface LockTable

oneLessWaiter

public void oneLessWaiter()
Decrease blockCount by one.
MT - must be synchronized on this LockSet object.

Specified by:
oneLessWaiter in interface LockTable

anyoneBlocked

public boolean anyoneBlocked()
Description copied from interface: LockTable
Check whether there are anyone blocked in the lock table.

Specified by:
anyoneBlocked in interface LockTable
Returns:
true if someone is blocked, false otherwise

getControl

private final Control getControl(Lockable ref)
Get the Control for an object in the lock table.
MT - must be synchronized on this LockSet object.


Built on Thu 2012-03-29 21:53:33+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.