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

java.lang.Object
  extended by org.apache.derby.impl.services.locks.AbstractPool
All Implemented Interfaces:
LockFactory, PropertySetCallback
Direct Known Subclasses:
ConcurrentPool, SinglePool

abstract class AbstractPool
extends java.lang.Object
implements LockFactory

An abstract implementation of LockFactory that allows different implementations of the lock table to be plugged in. All the methods of LockFactory are implemented. Subclasses must implement the createLockTable() method and make it return the desired LockTable object.
MT - Mutable - Container Object : Thread Aware


Field Summary
(package private)  int deadlockMonitor
          True if all deadlocks errors should be logged.
protected  LockTable lockTable
          The complete set of locks in the system
MT - immutable - content dynamic : LockSet is ThreadSafe
 
Constructor Summary
protected AbstractPool()
           
 
Method Summary
 boolean anyoneBlocked()
          Returns true if locks by anyone are blocking anyone else
 Serviceable apply(java.lang.String key, java.io.Serializable value, java.util.Dictionary p)
          Apply a property change.
 boolean areLocksHeld(CompatibilitySpace compatibilitySpace)
          Return true if locks are held in this space
MT - thread safe
 boolean areLocksHeld(CompatibilitySpace compatibilitySpace, java.lang.Object group)
          Return true if locks are held in this group and this space.
 void clearLimit(CompatibilitySpace compatibilitySpace, java.lang.Object group)
          Clear a limit set by setLimit.
 CompatibilitySpace createCompatibilitySpace(LockOwner owner)
          Create an object which can be used as a compatibility space within this lock manager.
protected abstract  LockTable createLockTable()
          Create the lock table that contains the mapping from Lockables to locks.
private  void getAndApply(boolean dbOnly, java.util.Dictionary p, java.lang.String key)
           
 int getWaitTimeout()
          Get the lock timeout in milliseconds.
private static int getWaitValue(java.lang.String value, int defaultValue)
           
 void init(boolean dbOnly, java.util.Dictionary p)
          Initialize the properties for this callback.
 boolean isLockHeld(CompatibilitySpace compatibilitySpace, java.lang.Object group, Lockable ref, java.lang.Object qualifier)
          Check to see if a specific lock is held.
 boolean lockObject(CompatibilitySpace compatibilitySpace, java.lang.Object group, Lockable ref, java.lang.Object qualifier, int timeout)
          Lock a specific object with a timeout.
 java.util.Enumeration makeVirtualLockTable()
          Routines to support lock diagnostics VTIs for the benefit of VirtualLockTable
 java.io.Serializable map(java.lang.String key, java.io.Serializable value, java.util.Dictionary p)
          Map a proposed new value for a property to an official value.
(package private) static boolean noLockWait(int timeout, CompatibilitySpace compat)
          Check if we should not wait for locks, given the specified timeout and compatibility space.
 void setLimit(CompatibilitySpace compatibilitySpace, java.lang.Object group, int limit, Limit callback)
          Install a limit that is called when the size of the group exceeds the required limit.
 void transfer(CompatibilitySpace compatibilitySpace, java.lang.Object oldGroup, java.lang.Object newGroup)
          Transfer a set of locks from one group to another.
 int unlock(CompatibilitySpace compatibilitySpace, java.lang.Object group, Lockable ref, java.lang.Object qualifier)
          Unlock a specific object
MT - thread safe
 void unlockGroup(CompatibilitySpace compatibilitySpace, java.lang.Object group)
          Unlock a group of objects.
 void unlockGroup(CompatibilitySpace compatibilitySpace, java.lang.Object group, Matchable key)
          Unlock all locks on a group that match the passed in value.
 boolean validate(java.lang.String key, java.io.Serializable value, java.util.Dictionary p)
          Validate a property change.
 boolean zeroDurationlockObject(CompatibilitySpace compatibilitySpace, Lockable ref, java.lang.Object qualifier, int timeout)
          Lock an object with zero duration within a compatibility space, waits up to timeout milli-seconds for the object to become unlocked.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lockTable

protected final LockTable lockTable
The complete set of locks in the system
MT - immutable - content dynamic : LockSet is ThreadSafe


deadlockMonitor

int deadlockMonitor
True if all deadlocks errors should be logged.

Constructor Detail

AbstractPool

protected AbstractPool()
Method Detail

createLockTable

protected abstract LockTable createLockTable()
Create the lock table that contains the mapping from Lockables to locks.

Returns:
an object implementing the LockTable interface

lockObject

public boolean lockObject(CompatibilitySpace compatibilitySpace,
                          java.lang.Object group,
                          Lockable ref,
                          java.lang.Object qualifier,
                          int timeout)
                   throws StandardException
Lock a specific object with a timeout.
MT - thread safe

Specified by:
lockObject in interface LockFactory
Parameters:
compatibilitySpace - object defining compatibility space
group - handle of group, must be private to a thread.
ref - reference to object to be locked
qualifier - A qualification of the request.
timeout - the maximum time to wait in milliseconds, LockFactory.NO_WAIT means don't wait.
Returns:
true if the lock was obtained, false if timeout is equal to LockFactory.NO_WAIT and the lock could not be granted.
Throws:
StandardException - Standard Derby error policy
See Also:
LockFactory.lockObject(org.apache.derby.iapi.services.locks.CompatibilitySpace, java.lang.Object, org.apache.derby.iapi.services.locks.Lockable, java.lang.Object, int)

createCompatibilitySpace

public CompatibilitySpace createCompatibilitySpace(LockOwner owner)
Create an object which can be used as a compatibility space within this lock manager.

Specified by:
createCompatibilitySpace in interface LockFactory
Parameters:
owner - the owner of the compatibility space
Returns:
an object which represents a compatibility space

unlock

public int unlock(CompatibilitySpace compatibilitySpace,
                  java.lang.Object group,
                  Lockable ref,
                  java.lang.Object qualifier)
Unlock a specific object
MT - thread safe

Specified by:
unlock in interface LockFactory
Parameters:
compatibilitySpace - object defining compatibility space
group - handle of group.
ref - Reference to object to be unlocked.
qualifier - qualifier of lock to be unlocked
Returns:
number of locks released (one or zero).
See Also:
LockFactory.unlock(org.apache.derby.iapi.services.locks.CompatibilitySpace, java.lang.Object, org.apache.derby.iapi.services.locks.Lockable, java.lang.Object)

unlockGroup

public void unlockGroup(CompatibilitySpace compatibilitySpace,
                        java.lang.Object group)
Unlock a group of objects.
MT - thread safe

Specified by:
unlockGroup in interface LockFactory
Parameters:
group - handle of group that objects were locked with. If group is null then this call is equivilent to unlockAll().
compatibilitySpace - object defining compatibility space
See Also:
LockFactory.unlockGroup(org.apache.derby.iapi.services.locks.CompatibilitySpace, java.lang.Object)

unlockGroup

public void unlockGroup(CompatibilitySpace compatibilitySpace,
                        java.lang.Object group,
                        Matchable key)
Description copied from interface: LockFactory
Unlock all locks on a group that match the passed in value.

Specified by:
unlockGroup in interface LockFactory

transfer

public void transfer(CompatibilitySpace compatibilitySpace,
                     java.lang.Object oldGroup,
                     java.lang.Object newGroup)
Transfer a set of locks from one group to another.
MT - thread safe

Specified by:
transfer in interface LockFactory
See Also:
LockFactory.transfer(org.apache.derby.iapi.services.locks.CompatibilitySpace, java.lang.Object, java.lang.Object)

anyoneBlocked

public boolean anyoneBlocked()
Returns true if locks by anyone are blocking anyone else

Specified by:
anyoneBlocked in interface LockFactory

areLocksHeld

public boolean areLocksHeld(CompatibilitySpace compatibilitySpace,
                            java.lang.Object group)
Return true if locks are held in this group and this space.
MT - thread safe

Specified by:
areLocksHeld in interface LockFactory
Parameters:
group - handle of group that objects were locked with.
See Also:
LockFactory.areLocksHeld(org.apache.derby.iapi.services.locks.CompatibilitySpace, java.lang.Object)

areLocksHeld

public boolean areLocksHeld(CompatibilitySpace compatibilitySpace)
Return true if locks are held in this space
MT - thread safe

Specified by:
areLocksHeld in interface LockFactory
See Also:
LockFactory.areLocksHeld(org.apache.derby.iapi.services.locks.CompatibilitySpace, java.lang.Object)

zeroDurationlockObject

public boolean zeroDurationlockObject(CompatibilitySpace compatibilitySpace,
                                      Lockable ref,
                                      java.lang.Object qualifier,
                                      int timeout)
                               throws StandardException
Description copied from interface: LockFactory
Lock an object with zero duration within a compatibility space, waits up to timeout milli-seconds for the object to become unlocked. A timeout of 0 means do not wait for the lock to be unlocked. Note the actual time waited is approximate.

Zero duration means the lock is released as soon as it is obtained.

A compatibility space in an space where lock requests are assumed to be compatible and granted by the lock manager if the trio {compatibilitySpace, ref, qualifier} are equal (i.e. reference equality for qualifier and compatibilitySpace, equals() method for ref). Granted by the lock manager means that the Lockable object may or may not be queried to see if the request is compatible.
A compatibility space is not assumed to be owned by a single thread.

Specified by:
zeroDurationlockObject in interface LockFactory
Parameters:
compatibilitySpace - object defining compatibility space
ref - reference to object to be locked
qualifier - A qualification of the request.
timeout - the maximum time to wait in milliseconds, LockFactory.NO_WAIT means don't wait.
Returns:
true if the lock was obtained, false if timeout is equal to LockFactory.NO_WAIT and the lock could not be granted.
Throws:
StandardException - A deadlock has occured (message id will be LockFactory.Deadlock)

isLockHeld

public boolean isLockHeld(CompatibilitySpace compatibilitySpace,
                          java.lang.Object group,
                          Lockable ref,
                          java.lang.Object qualifier)
Description copied from interface: LockFactory
Check to see if a specific lock is held.

Specified by:
isLockHeld in interface LockFactory

getWaitTimeout

public int getWaitTimeout()
Get the lock timeout in milliseconds. A negative number means that there is no timeout.

Specified by:
getWaitTimeout in interface LockFactory

setLimit

public void setLimit(CompatibilitySpace compatibilitySpace,
                     java.lang.Object group,
                     int limit,
                     Limit callback)
Description copied from interface: LockFactory
Install a limit that is called when the size of the group exceeds the required limit.
It is not guaranteed that the callback method (Limit.reached) is called as soon as the group size exceeds the given limit. If the callback method does not result in a decrease in the number of locks held then the lock factory implementation may delay calling the method again. E.g. with a limit of 500 and a reached() method that does nothing, may result in the call back method only being called when the group size reaches 550.
Only one limit may be in place for a group at any time.

Specified by:
setLimit in interface LockFactory
See Also:
Limit

clearLimit

public void clearLimit(CompatibilitySpace compatibilitySpace,
                       java.lang.Object group)
Clear a limit set by setLimit.

Specified by:
clearLimit in interface LockFactory

noLockWait

static boolean noLockWait(int timeout,
                          CompatibilitySpace compat)
Check if we should not wait for locks, given the specified timeout and compatibility space. If the timeout is C_LockFactory.NO_WAIT or the LockOwner has the noWait flag set, we shouldn't wait for locks.

Parameters:
timeout - the specified timeout
compat - the compatibility space
Returns:
true if we shouldn't wait for locks, false otherwise

makeVirtualLockTable

public java.util.Enumeration makeVirtualLockTable()
Routines to support lock diagnostics VTIs for the benefit of VirtualLockTable

Specified by:
makeVirtualLockTable in interface LockFactory

init

public void init(boolean dbOnly,
                 java.util.Dictionary p)
Description copied from interface: PropertySetCallback
Initialize the properties for this callback. Called when addPropertySetNotification() is called with a non-null transaction controller. This allows code to set read its initial property values at boot time.

Code within an init() method should use the 3 argument PropertyUtil method getPropertyFromSet() to obtain a property's value.

Specified by:
init in interface PropertySetCallback
Parameters:
dbOnly - true if only per-database properties are to be looked at
p - the complete set of per-database properties.

getAndApply

private void getAndApply(boolean dbOnly,
                         java.util.Dictionary p,
                         java.lang.String key)

validate

public boolean validate(java.lang.String key,
                        java.io.Serializable value,
                        java.util.Dictionary p)
                 throws StandardException
Description copied from interface: PropertySetCallback
Validate a property change.

Specified by:
validate in interface PropertySetCallback
Parameters:
key - Property key for the property being set
value - proposed new value for the property being set or null if the property is being dropped.
p - Property set before the change. SettingProperty may read but must never change p.
Returns:
true if this object was interested in this property, false otherwise.
Throws:
StandardException - Oh well.

apply

public Serviceable apply(java.lang.String key,
                         java.io.Serializable value,
                         java.util.Dictionary p)
                  throws StandardException
Description copied from interface: PropertySetCallback
Apply a property change. Will only be called after validate has been called and only if validate returned true. If this method is called then the new value is the value to be used, ie. the property is not set in the overriding JVM system set.

Specified by:
apply in interface PropertySetCallback
Parameters:
key - Property key for the property being set
value - proposed new value for the property being set or null if the property is being dropped.
p - Property set before the change. SettingProperty may read but must never change p.
Returns:
post commit work for the property change.
Throws:
StandardException - Oh well.

map

public java.io.Serializable map(java.lang.String key,
                                java.io.Serializable value,
                                java.util.Dictionary p)
Description copied from interface: PropertySetCallback
Map a proposed new value for a property to an official value. Will only be called after apply() has been called.

Specified by:
map in interface PropertySetCallback
Parameters:
key - Property key for the property being set
value - proposed new value for the property being set or null if the property is being dropped.
p - Property set before the change. SettingProperty may read but must never change p.
Returns:
new value for the change

getWaitValue

private static int getWaitValue(java.lang.String value,
                                int defaultValue)

Built on Thu 2011-03-10 11:54:14+0000, from revision ???

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