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

pack-priv abstract Class AbstractPool

extends Object
implements LockFactory
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.services.locks.LockFactory, org.apache.derby.iapi.services.property.PropertySetCallback
Known Direct Subclasses
org.apache.derby.impl.services.locks.ConcurrentPool
Imports
org.apache.derby.iapi.services.locks.CompatibilitySpace, .LockFactory, .C_LockFactory, .Lockable, .Limit, .LockOwner, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.services.property.PropertyUtil, org.apache.derby.iapi.services.daemon.Serviceable, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.util.Matchable, org.apache.derby.shared.common.reference.Property, .SQLState, java.io.Serializable, java.util.Dictionary, .Enumeration

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

Modifier and TypeField and Description
pack-priv int
deadlockMonitor

True if all deadlocks errors should be logged.

protected final LockTable
lockTable

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

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public boolean
anyoneBlocked()

Implements org.apache.derby.iapi.services.locks.LockFactory.anyoneBlocked.

Returns true if locks by anyone are blocking anyone else

public Serviceable
apply(String
Property key for the property being set
key
,
Serializable
proposed new value for the property being set or null if the property is being dropped.
value
,
Dictionary<K, V>
Property set before the change. SettingProperty may read but must never change p.
p
)

Implements org.apache.derby.iapi.services.property.PropertySetCallback.apply.

Apply a property change.

public boolean
areLocksHeld(CompatibilitySpace
A lock space
compatibilitySpace
,
Object
handle of group that objects were locked with.
group
)

Implements org.apache.derby.iapi.services.locks.LockFactory.areLocksHeld.

Return true if locks are held in this group and this space.

public boolean
areLocksHeld(CompatibilitySpace
A lock space
compatibilitySpace
)

Implements org.apache.derby.iapi.services.locks.LockFactory.areLocksHeld.

Return true if locks are held in this space MT - thread safe

public void
clearLimit(CompatibilitySpace
A lock space
compatibilitySpace
,
Object
A group
group
)

Implements org.apache.derby.iapi.services.locks.LockFactory.clearLimit.

Clear a limit set by setLimit.

public CompatibilitySpace

Returns:

an object which represents a compatibility space
createCompatibilitySpace
(LockOwner
the owner of the compatibility space
owner
)

Implements org.apache.derby.iapi.services.locks.LockFactory.createCompatibilitySpace.

Create an object which can be used as a compatibility space within this lock manager.

protected abstract LockTable

Returns:

an object implementing the LockTable interface
createLockTable
()

Create the lock table that contains the mapping from Lockables to locks.

private void
getAndApply(boolean dbOnly, Dictionary<K, V> p, String key)

public int
getWaitTimeout()

Implements org.apache.derby.iapi.services.locks.LockFactory.getWaitTimeout.

Get the lock timeout in milliseconds.

private static int
getWaitValue(String value, int defaultValue)

public void
init(boolean
true if only per-database properties are to be looked at
dbOnly
,
Dictionary<K, V>
the complete set of per-database properties.
p
)

Implements org.apache.derby.iapi.services.property.PropertySetCallback.init.

Initialize the properties for this callback.

public boolean
isLockHeld(CompatibilitySpace
A lock space
compatibilitySpace
,
Object
A group
group
,
Lockable
Something which can be locked
ref
,
Object
The kind of lock
qualifier
)

Implements org.apache.derby.iapi.services.locks.LockFactory.isLockHeld.

Check to see if a specific lock is held.

public boolean
lockObject(CompatibilitySpace
object defining compatibility space
compatibilitySpace
,
Object
handle of group, must be private to a thread.
group
,
Lockable
reference to object to be locked
ref
,
Object
A qualification of the request.
qualifier
,
int
the maximum time to wait in milliseconds, LockFactory.NO_WAIT means don't wait.
timeout
)

Implements org.apache.derby.iapi.services.locks.LockFactory.lockObject.

Lock a specific object with a timeout.

public Enumeration<E>
makeVirtualLockTable()

Implements org.apache.derby.iapi.services.locks.LockFactory.makeVirtualLockTable.

Routines to support lock diagnostics VTIs for the benefit of VirtualLockTable

public Serializable
map(String
Property key for the property being set
key
,
Serializable
proposed new value for the property being set or null if the property is being dropped.
value
,
Dictionary<K, V>
Property set before the change. SettingProperty may read but must never change p.
p
)

Implements org.apache.derby.iapi.services.property.PropertySetCallback.map.

Map a proposed new value for a property to an official value.

pack-priv static boolean

Returns:

true if we shouldn't wait for locks, false otherwise
noLockWait
(int
the specified timeout
timeout
,
CompatibilitySpace
the compatibility space
compat
)

Check if we should not wait for locks, given the specified timeout and compatibility space.

public void
setLimit(CompatibilitySpace
A lock space
compatibilitySpace
,
Object
A group
group
,
int
A limit for the group
limit
,
Limit
Code to call when the limit is reached
callback
)

Implements org.apache.derby.iapi.services.locks.LockFactory.setLimit.

Install a limit that is called when the size of the group exceeds the required limit.

public void
transfer(CompatibilitySpace
A lock space
compatibilitySpace
,
Object
The source group
oldGroup
,
Object
The target group
newGroup
)

Implements org.apache.derby.iapi.services.locks.LockFactory.transfer.

Transfer a set of locks from one group to another.

public int
unlock(CompatibilitySpace
object defining compatibility space
compatibilitySpace
,
Object
handle of group.
group
,
Lockable
Reference to object to be unlocked.
ref
,
Object
qualifier of lock to be unlocked
qualifier
)

Implements org.apache.derby.iapi.services.locks.LockFactory.unlock.

Unlock a specific object MT - thread safe

public void
unlockGroup(CompatibilitySpace
object defining compatibility space
compatibilitySpace
,
Object
handle of group that objects were locked with. If group is null then this call is equivilent to unlockAll().
group
)

Implements org.apache.derby.iapi.services.locks.LockFactory.unlockGroup.

Unlock a group of objects.

public void
unlockGroup(CompatibilitySpace
A lock space
compatibilitySpace
,
Object
A group
group
,
Matchable
The key
key
)

Implements org.apache.derby.iapi.services.locks.LockFactory.unlockGroup.

Unlock all locks on a group that match the passed in value.

public boolean
validate(String
Property key for the property being set
key
,
Serializable
proposed new value for the property being set or null if the property is being dropped.
value
,
Dictionary<K, V>
Property set before the change. SettingProperty may read but must never change p.
p
)

Implements org.apache.derby.iapi.services.property.PropertySetCallback.validate.

Validate a property change.

public boolean
zeroDurationlockObject(CompatibilitySpace
object defining compatibility space
compatibilitySpace
,
Lockable
reference to object to be locked
ref
,
Object
A qualification of the request.
qualifier
,
int
the maximum time to wait in milliseconds, LockFactory.NO_WAIT means don't wait.
timeout
)

Implements org.apache.derby.iapi.services.locks.LockFactory.zeroDurationlockObject.

Lock an object with zero duration within a compatibility space, waits up to timeout milli-seconds for the object to become unlocked.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

deadlockMonitorback to summary
pack-priv int deadlockMonitor

True if all deadlocks errors should be logged.

lockTableback to summary
protected final LockTable lockTable

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

Constructor Detail

AbstractPoolback to summary
protected AbstractPool()

Method Detail

anyoneBlockedback to summary
public boolean anyoneBlocked()

Implements org.apache.derby.iapi.services.locks.LockFactory.anyoneBlocked.

Returns true if locks by anyone are blocking anyone else

Returns:boolean

Doc from org.apache.derby.iapi.services.locks.LockFactory.anyoneBlocked.

true if someone is blocked

applyback to summary
public Serviceable apply(String key, Serializable value, Dictionary<K, V> p) throws StandardException

Implements org.apache.derby.iapi.services.property.PropertySetCallback.apply.

Doc from org.apache.derby.iapi.services.property.PropertySetCallback.apply.

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.

Parameters
key:String

Property key for the property being set

value:Serializable

proposed new value for the property being set or null if the property is being dropped.

p:Dictionary<K, V>

Property set before the change. SettingProperty may read but must never change p.

Returns:Serviceable

post commit work for the property change.

Exceptions
StandardException:
Oh well.
areLocksHeldback to summary
public boolean areLocksHeld(CompatibilitySpace compatibilitySpace, Object group)

Implements org.apache.derby.iapi.services.locks.LockFactory.areLocksHeld.

Return true if locks are held in this group and this space.
MT - thread safe

Parameters
compatibilitySpace:CompatibilitySpace

Doc from org.apache.derby.iapi.services.locks.LockFactory.areLocksHeld.

A lock space

group:Object

handle of group that objects were locked with.

Returns:boolean

Doc from org.apache.derby.iapi.services.locks.LockFactory.areLocksHeld.

true if locks matching the arguments are held

See Also
LockFactory#areLocksHeld
areLocksHeldback to summary
public boolean areLocksHeld(CompatibilitySpace compatibilitySpace)

Implements org.apache.derby.iapi.services.locks.LockFactory.areLocksHeld.

Return true if locks are held in this space
MT - thread safe

Parameters
compatibilitySpace:CompatibilitySpace

Doc from org.apache.derby.iapi.services.locks.LockFactory.areLocksHeld.

A lock space

Returns:boolean

Doc from org.apache.derby.iapi.services.locks.LockFactory.areLocksHeld.

true if locks matching the arguments are held

See Also
LockFactory#areLocksHeld
clearLimitback to summary
public void clearLimit(CompatibilitySpace compatibilitySpace, Object group)

Implements org.apache.derby.iapi.services.locks.LockFactory.clearLimit.

Clear a limit set by setLimit.

Parameters
compatibilitySpace:CompatibilitySpace

Doc from org.apache.derby.iapi.services.locks.LockFactory.clearLimit.

A lock space

group:Object

Doc from org.apache.derby.iapi.services.locks.LockFactory.clearLimit.

A group

createCompatibilitySpaceback to summary
public CompatibilitySpace createCompatibilitySpace(LockOwner owner)

Implements org.apache.derby.iapi.services.locks.LockFactory.createCompatibilitySpace.

Create an object which can be used as a compatibility space within this lock manager.

Parameters
owner:LockOwner

the owner of the compatibility space

Returns:CompatibilitySpace

an object which represents a compatibility space

createLockTableback to summary
protected abstract LockTable createLockTable()

Create the lock table that contains the mapping from Lockables to locks.

Returns:LockTable

an object implementing the LockTable interface

getAndApplyback to summary
private void getAndApply(boolean dbOnly, Dictionary<K, V> p, String key)
getWaitTimeoutback to summary
public int getWaitTimeout()

Implements org.apache.derby.iapi.services.locks.LockFactory.getWaitTimeout.

Get the lock timeout in milliseconds. A negative number means that there is no timeout.

Returns:int

Doc from org.apache.derby.iapi.services.locks.LockFactory.getWaitTimeout.

the lock timeout in milliseconds

getWaitValueback to summary
private static int getWaitValue(String value, int defaultValue)
initback to summary
public void init(boolean dbOnly, Dictionary<K, V> p)

Implements org.apache.derby.iapi.services.property.PropertySetCallback.init.

Doc from org.apache.derby.iapi.services.property.PropertySetCallback.init.

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.

Parameters
dbOnly:boolean

true if only per-database properties are to be looked at

p:Dictionary<K, V>

the complete set of per-database properties.

isLockHeldback to summary
public boolean isLockHeld(CompatibilitySpace compatibilitySpace, Object group, Lockable ref, Object qualifier)

Implements org.apache.derby.iapi.services.locks.LockFactory.isLockHeld.

Doc from org.apache.derby.iapi.services.locks.LockFactory.isLockHeld.

Check to see if a specific lock is held.

Parameters
compatibilitySpace:CompatibilitySpace

A lock space

group:Object

A group

ref:Lockable

Something which can be locked

qualifier:Object

The kind of lock

Returns:boolean

true if the indicated lock is held

lockObjectback to summary
public boolean lockObject(CompatibilitySpace compatibilitySpace, Object group, Lockable ref, Object qualifier, int timeout) throws StandardException

Implements org.apache.derby.iapi.services.locks.LockFactory.lockObject.

Lock a specific object with a timeout.
MT - thread safe

Parameters
compatibilitySpace:CompatibilitySpace

Doc from org.apache.derby.iapi.services.locks.LockFactory.lockObject.

object defining compatibility space

group:Object

Doc from org.apache.derby.iapi.services.locks.LockFactory.lockObject.

handle of group, must be private to a thread.

ref:Lockable

Doc from org.apache.derby.iapi.services.locks.LockFactory.lockObject.

reference to object to be locked

qualifier:Object

Doc from org.apache.derby.iapi.services.locks.LockFactory.lockObject.

A qualification of the request.

timeout:int

Doc from org.apache.derby.iapi.services.locks.LockFactory.lockObject.

the maximum time to wait in milliseconds, LockFactory.NO_WAIT means don't wait.

Returns:boolean

Doc from org.apache.derby.iapi.services.locks.LockFactory.lockObject.

true if the lock was obtained, false if timeout is equal to LockFactory.NO_WAIT and the lock could not be granted.

Exceptions
StandardException:
Standard Derby error policy
See Also
LockFactory#lockObject
makeVirtualLockTableback to summary
public Enumeration<E> makeVirtualLockTable()

Implements org.apache.derby.iapi.services.locks.LockFactory.makeVirtualLockTable.

Routines to support lock diagnostics VTIs for the benefit of VirtualLockTable

Returns:Enumeration<E>

Doc from org.apache.derby.iapi.services.locks.LockFactory.makeVirtualLockTable.

a virtual lock table

mapback to summary
public Serializable map(String key, Serializable value, Dictionary<K, V> p)

Implements org.apache.derby.iapi.services.property.PropertySetCallback.map.

Doc from org.apache.derby.iapi.services.property.PropertySetCallback.map.

Map a proposed new value for a property to an official value. Will only be called after apply() has been called.

Parameters
key:String

Property key for the property being set

value:Serializable

proposed new value for the property being set or null if the property is being dropped.

p:Dictionary<K, V>

Property set before the change. SettingProperty may read but must never change p.

Returns:Serializable

new value for the change

noLockWaitback to summary
pack-priv 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:int

the specified timeout

compat:CompatibilitySpace

the compatibility space

Returns:boolean

true if we shouldn't wait for locks, false otherwise

setLimitback to summary
public void setLimit(CompatibilitySpace compatibilitySpace, Object group, int limit, Limit callback)

Implements org.apache.derby.iapi.services.locks.LockFactory.setLimit.

Doc from org.apache.derby.iapi.services.locks.LockFactory.setLimit.

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.

Parameters
compatibilitySpace:CompatibilitySpace

A lock space

group:Object

A group

limit:int

A limit for the group

callback:Limit

Code to call when the limit is reached

transferback to summary
public void transfer(CompatibilitySpace compatibilitySpace, Object oldGroup, Object newGroup)

Implements org.apache.derby.iapi.services.locks.LockFactory.transfer.

Transfer a set of locks from one group to another.
MT - thread safe

Parameters
compatibilitySpace:CompatibilitySpace

Doc from org.apache.derby.iapi.services.locks.LockFactory.transfer.

A lock space

oldGroup:Object

Doc from org.apache.derby.iapi.services.locks.LockFactory.transfer.

The source group

newGroup:Object

Doc from org.apache.derby.iapi.services.locks.LockFactory.transfer.

The target group

See Also
LockFactory#transfer
unlockback to summary
public int unlock(CompatibilitySpace compatibilitySpace, Object group, Lockable ref, Object qualifier)

Implements org.apache.derby.iapi.services.locks.LockFactory.unlock.

Unlock a specific object
MT - thread safe

Parameters
compatibilitySpace:CompatibilitySpace

Doc from org.apache.derby.iapi.services.locks.LockFactory.unlock.

object defining compatibility space

group:Object

Doc from org.apache.derby.iapi.services.locks.LockFactory.unlock.

handle of group.

ref:Lockable

Doc from org.apache.derby.iapi.services.locks.LockFactory.unlock.

Reference to object to be unlocked.

qualifier:Object

Doc from org.apache.derby.iapi.services.locks.LockFactory.unlock.

qualifier of lock to be unlocked

Returns:int

Doc from org.apache.derby.iapi.services.locks.LockFactory.unlock.

number of locks released (one or zero).

See Also
LockFactory#unlock
unlockGroupback to summary
public void unlockGroup(CompatibilitySpace compatibilitySpace, Object group)

Implements org.apache.derby.iapi.services.locks.LockFactory.unlockGroup.

Unlock a group of objects.
MT - thread safe

Parameters
compatibilitySpace:CompatibilitySpace

Doc from org.apache.derby.iapi.services.locks.LockFactory.unlockGroup.

object defining compatibility space

group:Object

handle of group that objects were locked with. If group is null then this call is equivilent to unlockAll().

See Also
LockFactory#unlockGroup
unlockGroupback to summary
public void unlockGroup(CompatibilitySpace compatibilitySpace, Object group, Matchable key)

Implements org.apache.derby.iapi.services.locks.LockFactory.unlockGroup.

Doc from org.apache.derby.iapi.services.locks.LockFactory.unlockGroup.

Unlock all locks on a group that match the passed in value.

Parameters
compatibilitySpace:CompatibilitySpace

A lock space

group:Object

A group

key:Matchable

The key

validateback to summary
public boolean validate(String key, Serializable value, Dictionary<K, V> p) throws StandardException

Implements org.apache.derby.iapi.services.property.PropertySetCallback.validate.

Doc from org.apache.derby.iapi.services.property.PropertySetCallback.validate.

Validate a property change.

Parameters
key:String

Property key for the property being set

value:Serializable

proposed new value for the property being set or null if the property is being dropped.

p:Dictionary<K, V>

Property set before the change. SettingProperty may read but must never change p.

Returns:boolean

true if this object was interested in this property, false otherwise.

Exceptions
StandardException:
Oh well.
zeroDurationlockObjectback to summary
public boolean zeroDurationlockObject(CompatibilitySpace compatibilitySpace, Lockable ref, Object qualifier, int timeout) throws StandardException

Implements org.apache.derby.iapi.services.locks.LockFactory.zeroDurationlockObject.

Doc from org.apache.derby.iapi.services.locks.LockFactory.zeroDurationlockObject.

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.

Parameters
compatibilitySpace:CompatibilitySpace

object defining compatibility space

ref:Lockable

reference to object to be locked

qualifier:Object

A qualification of the request.

timeout:int

the maximum time to wait in milliseconds, LockFactory.NO_WAIT means don't wait.

Returns:boolean

true if the lock was obtained, false if timeout is equal to LockFactory.NO_WAIT and the lock could not be granted.

Exceptions
StandardException:
if a deadlock has occurred (message id will be LockFactory.Deadlock), or if the wait for the lock timed out (message id will be LockFactory.TimeOut), or if another thread interrupted this thread while it was waiting for the lock (this will be a StandardException with a nested InterruptedException, and the message id will be LockFactory.InterruptedExceptionId), or if any other error occurs when locking the object