Top Description Methods
org.apache.derby.iapi.services.locks

public Interface LockFactory

extends PropertySetCallback
Known Direct Implementers
org.apache.derby.impl.services.locks.AbstractPool
Imports
org.apache.derby.iapi.util.Matchable, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.services.property.PropertySetCallback, java.util.Enumeration

Generic locking of objects. Enables deadlock detection.
MT - Mutable - Container Object - Thread Safe

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if someone is blocked
anyoneBlocked
()

Returns true if locks held by anyone are blocking anyone else

public boolean

Returns:

true if locks matching the arguments are held
areLocksHeld
(CompatibilitySpace
A lock space
compatibilitySpace
,
Object
handle of group that objects were locked with.
group
)

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

public boolean

Returns:

true if locks matching the arguments are held
areLocksHeld
(CompatibilitySpace
A lock space
compatibilitySpace
)

Return true if locks are held in this compatibility space.

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

Clear a limit set by setLimit.

public CompatibilitySpace

Returns:

an object which represents a compatibility space
createCompatibilitySpace
(LockOwner
the owner of the compatibility space (typically a transaction object). Might be null.
owner
)

Create an object which can be used as a compatibility space.

public int

Returns:

the lock timeout in milliseconds
getWaitTimeout
()

Get the lock timeout in milliseconds.

public boolean

Returns:

true if the indicated lock is held
isLockHeld
(CompatibilitySpace
A lock space
compatibilitySpace
,
Object
A group
group
,
Lockable
Something which can be locked
ref
,
Object
The kind of lock
qualifier
)

Check to see if a specific lock is held.

public boolean

Returns:

true if the lock was obtained, false if timeout is equal to LockFactory.NO_WAIT and the lock could not be granted.
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
)

Lock an object within a compatibility space and associate the lock with a group object, waits up to timeout milli-seconds for the object to become unlocked.

public Enumeration<E>

Returns:

a virtual lock table
makeVirtualLockTable
()

Make a virtual lock table for diagnostics.

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
)

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
)

Transfer a set of locks from one group to another.

public int

Returns:

number of locks released (one or zero).
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
)

Unlock a single lock on a single object held within this compatibility space and locked with the supplied qualifier.

public void
unlockGroup(CompatibilitySpace
object defining compatibility space
compatibilitySpace
,
Object
handle of group that objects were locked with.
group
)

Unlock all locks in a group.

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

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

public boolean

Returns:

true if the lock was obtained, false if timeout is equal to LockFactory.NO_WAIT and the lock could not be granted.
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
)

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

Inherited from org.apache.derby.iapi.services.property.PropertySetCallback:
applyinitmapvalidate

Method Detail

anyoneBlockedback to summary
public boolean anyoneBlocked()

Returns true if locks held by anyone are blocking anyone else

Returns:boolean

true if someone is blocked

areLocksHeldback to summary
public boolean areLocksHeld(CompatibilitySpace compatibilitySpace, Object group)

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

Parameters
compatibilitySpace:CompatibilitySpace

A lock space

group:Object

handle of group that objects were locked with.

Returns:boolean

true if locks matching the arguments are held

areLocksHeldback to summary
public boolean areLocksHeld(CompatibilitySpace compatibilitySpace)

Return true if locks are held in this compatibility space.

Parameters
compatibilitySpace:CompatibilitySpace

A lock space

Returns:boolean

true if locks matching the arguments are held

clearLimitback to summary
public void clearLimit(CompatibilitySpace compatibilitySpace, Object group)

Clear a limit set by setLimit.

Parameters
compatibilitySpace:CompatibilitySpace

A lock space

group:Object

A group

createCompatibilitySpaceback to summary
public CompatibilitySpace createCompatibilitySpace(LockOwner owner)

Create an object which can be used as a compatibility space. A compatibility space object can only be used in the LockFactory that created it.

Parameters
owner:LockOwner

the owner of the compatibility space (typically a transaction object). Might be null.

Returns:CompatibilitySpace

an object which represents a compatibility space

getWaitTimeoutback to summary
public int getWaitTimeout()

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

Returns:int

the lock timeout in milliseconds

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

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

Lock an object within a compatibility space and associate the lock with a group object, 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.

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

group:Object

handle of group, must be private to a thread.

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
makeVirtualLockTableback to summary
public Enumeration<E> makeVirtualLockTable()

Make a virtual lock table for diagnostics.

Returns:Enumeration<E>

a virtual lock table

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

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

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

Transfer a set of locks from one group to another.

Parameters
compatibilitySpace:CompatibilitySpace

A lock space

oldGroup:Object

The source group

newGroup:Object

The target group

unlockback to summary
public int unlock(CompatibilitySpace compatibilitySpace, Object group, Lockable ref, Object qualifier)

Unlock a single lock on a single object held within this compatibility space and locked with the supplied qualifier.

Parameters
compatibilitySpace:CompatibilitySpace

object defining compatibility space

group:Object

handle of group.

ref:Lockable

Reference to object to be unlocked.

qualifier:Object

qualifier of lock to be unlocked

Returns:int

number of locks released (one or zero).

unlockGroupback to summary
public void unlockGroup(CompatibilitySpace compatibilitySpace, Object group)

Unlock all locks in a group.

Parameters
compatibilitySpace:CompatibilitySpace

object defining compatibility space

group:Object

handle of group that objects were locked with.

unlockGroupback to summary
public void unlockGroup(CompatibilitySpace compatibilitySpace, Object group, Matchable key)

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

zeroDurationlockObjectback to summary
public boolean zeroDurationlockObject(CompatibilitySpace compatibilitySpace, Lockable ref, Object qualifier, int timeout) throws StandardException

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