Class LockSpace
- java.lang.Object
-
- 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, includingnull
.
-
-
Field Summary
Fields Modifier and Type Field Description private Limit
callback
private java.lang.Object
callbackGroup
private java.util.HashMap<java.lang.Object,java.util.HashMap<Lock,Lock>>
groups
Map from group references to groups of locks.private boolean
inLimit
private int
limit
private static int
MAX_CACHED_GROUPS
The maximum number of elements to cache inspareGroups
.private int
nextLimitCall
private LockOwner
owner
Reference to the owner of this compatibility space.private java.util.ArrayDeque<java.util.HashMap<Lock,Lock>>
spareGroups
Cached HashMaps for storing lock groups.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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<Lock,Lock>
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<Lock,Lock> from, java.util.HashMap<Lock,Lock> into)
private void
saveGroup(java.util.HashMap<Lock,Lock> 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)
-
-
-
Field Detail
-
groups
private final java.util.HashMap<java.lang.Object,java.util.HashMap<Lock,Lock>> groups
Map from group references to groups of locks.
-
owner
private final LockOwner owner
Reference to the owner of this compatibility space.
-
MAX_CACHED_GROUPS
private static final int MAX_CACHED_GROUPS
The maximum number of elements to cache inspareGroups
.- See Also:
- Constant Field Values
-
spareGroups
private final java.util.ArrayDeque<java.util.HashMap<Lock,Lock>> spareGroups
Cached HashMaps for storing lock groups.
-
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 newLockSpace
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 interfaceCompatibilitySpace
- 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.
-
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<Lock,Lock> from, java.util.HashMap<Lock,Lock> 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.
-
-