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

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

final class LockSpace
extends java.lang.Object
implements CompatibilitySpace

A LockSpace represents the complete set of locks held within a single compatibility space, broken into groups of locks. A LockSpace contains a HashMap keyed by the group reference, the data for each key is a HashMap of Lock's.

A LockSpace can have an owner (for instance a transaction). Currently, the owner is used by the virtual lock table to find out which transaction a lock belongs to. Some parts of the code also use the owner as a group object which guarantees that the lock is released on a commit or an abort. The owner has no special meaning to the lock manager and can be any object, including null.


Field Summary
private  Limit callback
           
private  java.lang.Object callbackGroup
           
private  java.util.HashMap groups
          Map from group references to groups of locks.
private  boolean inLimit
           
private  int limit
           
private  int nextLimitCall
           
private  LockOwner owner
          Reference to the owner of this compatibility space.
private  java.util.HashMap[] spareGroups
           
 
Constructor Summary
LockSpace(LockOwner owner)
          Creates a new LockSpace instance.
 
Method Summary
protected  void addLock(java.lang.Object group, Lock lock)
          Add a lock to a group.
(package private)  boolean areLocksHeld()
          Return true if locks are held in this compatibility space.
(package private)  boolean areLocksHeld(java.lang.Object group)
          Return true if locks are held in a group
(package private)  void clearLimit(java.lang.Object group)
          Clear a limit set by setLimit.
(package private)  int deadlockCount(int bail)
          Return a count of the number of locks held by this space.
private  java.util.HashMap getGroupMap(java.lang.Object group)
           
 LockOwner getOwner()
          Get the object representing the owner of the compatibility space.
(package private)  boolean isLockHeld(java.lang.Object group, Lockable ref, java.lang.Object qualifier)
           
private  void mergeGroups(java.util.HashMap from, java.util.HashMap into)
           
private  void saveGroup(java.util.HashMap dl)
           
(package private)  void setLimit(java.lang.Object group, int limit, Limit callback)
           
(package private)  void transfer(java.lang.Object oldGroup, java.lang.Object newGroup)
           
(package private)  void unlockGroup(LockTable lset, java.lang.Object group)
          Unlock all the locks in a group and then remove the group.
(package private)  void unlockGroup(LockTable lset, java.lang.Object group, Matchable key)
          Unlock all locks in the group that match the key
(package private)  int unlockReference(LockTable lset, Lockable ref, java.lang.Object qualifier, java.lang.Object group)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

groups

private final java.util.HashMap groups
Map from group references to groups of locks.


owner

private final LockOwner owner
Reference to the owner of this compatibility space.


spareGroups

private java.util.HashMap[] spareGroups

callbackGroup

private java.lang.Object callbackGroup

limit

private int limit

nextLimitCall

private int nextLimitCall

callback

private Limit callback

inLimit

private boolean inLimit
Constructor Detail

LockSpace

LockSpace(LockOwner owner)
Creates a new LockSpace instance.

Parameters:
owner - an object representing the owner of the compatibility space
Method Detail

getOwner

public LockOwner getOwner()
Get the object representing the owner of the compatibility space.

Specified by:
getOwner in interface CompatibilitySpace
Returns:
the owner of the compatibility space

addLock

protected void addLock(java.lang.Object group,
                       Lock lock)
                throws StandardException
Add a lock to a group.

Throws:
StandardException

unlockGroup

void unlockGroup(LockTable lset,
                 java.lang.Object group)
Unlock all the locks in a group and then remove the group.


getGroupMap

private java.util.HashMap getGroupMap(java.lang.Object group)

saveGroup

private void saveGroup(java.util.HashMap dl)

unlockGroup

void unlockGroup(LockTable lset,
                 java.lang.Object group,
                 Matchable key)
Unlock all locks in the group that match the key


transfer

void transfer(java.lang.Object oldGroup,
              java.lang.Object newGroup)

mergeGroups

private void mergeGroups(java.util.HashMap from,
                         java.util.HashMap into)

unlockReference

int unlockReference(LockTable lset,
                    Lockable ref,
                    java.lang.Object qualifier,
                    java.lang.Object group)

areLocksHeld

boolean areLocksHeld(java.lang.Object group)
Return true if locks are held in a group


areLocksHeld

boolean areLocksHeld()
Return true if locks are held in this compatibility space.

Returns:
true if locks are held, false otherwise

isLockHeld

boolean isLockHeld(java.lang.Object group,
                   Lockable ref,
                   java.lang.Object qualifier)

setLimit

void setLimit(java.lang.Object group,
              int limit,
              Limit callback)

clearLimit

void clearLimit(java.lang.Object group)
Clear a limit set by setLimit.


deadlockCount

int deadlockCount(int bail)
Return a count of the number of locks held by this space. The argument bail indicates at which point the counting should bail out and return the current count. This routine will bail if the count is greater than bail. Thus this routine is intended to for deadlock code to find the space with the fewest number of locks.


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.