org.apache.commons.transaction.locking
Interface MultiLevelLock2

All Superinterfaces:
MultiLevelLock
All Known Implementing Classes:
GenericLock, ReadWriteLock, ReadWriteUpgradeLock

public interface MultiLevelLock2
extends MultiLevelLock

Extended multi level lock. Compared to basic MultiLevelLock allows for more flexible locking including preference and more compatibility modes.

Since:
1.1
Version:
$Revision$
See Also:
LockManager2, MultiLevelLock, GenericLock

Field Summary
static int COMPATIBILITY_NONE
          Compatibility mode: none reentrant.
static int COMPATIBILITY_REENTRANT
          Compatibility mode: reentrant.
static int COMPATIBILITY_REENTRANT_AND_SUPPORT
          Compatibility mode: reentrant and supporting.
static int COMPATIBILITY_SUPPORT
          Compatibility mode: supporting.
 
Method Summary
 boolean acquire(Object ownerId, int targetLockLevel, boolean wait, int compatibility, boolean preferred, long timeoutMSecs)
          Tries to acquire a certain lock level on this lock.
 boolean has(Object ownerId, int lockLevel)
          Tests if a certain lock level is owned by an owner.
 boolean test(Object ownerId, int targetLockLevel, int compatibility)
          Tests if a certain lock level could be acquired.
 
Methods inherited from interface org.apache.commons.transaction.locking.MultiLevelLock
acquire, getLockLevel, release
 

Field Detail

COMPATIBILITY_NONE

static final int COMPATIBILITY_NONE
Compatibility mode: none reentrant. Lock level by the same owner shall affect compatibility.

See Also:
Constant Field Values

COMPATIBILITY_REENTRANT

static final int COMPATIBILITY_REENTRANT
Compatibility mode: reentrant. Lock level by the same owner shall not affect compatibility.

See Also:
Constant Field Values

COMPATIBILITY_SUPPORT

static final int COMPATIBILITY_SUPPORT
Compatibility mode: supporting. Lock levels that are the same as the desired shall not affect compatibility, but lock level held by the same owner shall.

See Also:
Constant Field Values

COMPATIBILITY_REENTRANT_AND_SUPPORT

static final int COMPATIBILITY_REENTRANT_AND_SUPPORT
Compatibility mode: reentrant and supporting. Lock levels that are the same as the desired and lock levels held by the same owner shall not affect compatibility.

See Also:
Constant Field Values
Method Detail

has

boolean has(Object ownerId,
            int lockLevel)
Tests if a certain lock level is owned by an owner.

Parameters:
ownerId - a unique id identifying the entity that wants to check a certain lock level on this lock
lockLevel - the lock level to test
Returns:
true if the lock could be acquired at the time this method was called

test

boolean test(Object ownerId,
             int targetLockLevel,
             int compatibility)
Tests if a certain lock level could be acquired. This method tests only and does not actually acquire the lock.

Parameters:
ownerId - a unique id identifying the entity that wants to test a certain lock level on this lock
targetLockLevel - the lock level to acquire
compatibility - COMPATIBILITY_NONEif no additional compatibility is desired (same as reentrant set to false) , COMPATIBILITY_REENTRANTif lock level by the same owner shall not affect compatibility (same as reentrant set to true), or COMPATIBILITY_SUPPORTif lock levels that are the same as the desired shall not affect compatibility, or finally COMPATIBILITY_REENTRANT_AND_SUPPORTwhich is a combination of reentrant and support
Returns:
true if the lock could be acquired at the time this method was called

acquire

boolean acquire(Object ownerId,
                int targetLockLevel,
                boolean wait,
                int compatibility,
                boolean preferred,
                long timeoutMSecs)
                throws InterruptedException
Tries to acquire a certain lock level on this lock. Does the same as MultiLevelLock.acquire(java.lang.Object, int, boolean, boolean, long) except that it allows for different compatibility settings. There is an additional compatibility mode COMPATIBILITY_SUPPORTthat allows equal lock levels not to interfere with each other. This is like an additional shared compatibility and useful when you only want to make sure not to interfer with lowe levels, but are fine with the same.

Parameters:
ownerId - a unique id identifying the entity that wants to acquire a certain lock level on this lock
targetLockLevel - the lock level to acquire
wait - true if this method shall block when the desired lock level can not be acquired
compatibility - COMPATIBILITY_NONEif no additional compatibility is desired (same as reentrant set to false) , COMPATIBILITY_REENTRANTif lock level by the same owner shall not affect compatibility (same as reentrant set to true), or COMPATIBILITY_SUPPORTif lock levels that are the same as the desired shall not affect compatibility, or finally COMPATIBILITY_REENTRANT_AND_SUPPORTwhich is a combination of reentrant and support
preferred - in case this lock request is incompatible with existing ones and we wait, it shall be granted before other waiting requests that are not preferred
timeoutMSecs - if blocking is enabled by the wait parameter this specifies the maximum wait time in milliseconds
Returns:
true if the lock actually was acquired
Throws:
InterruptedException - when the thread waiting on this method is interrupted


Copyright © 2004 The Apache Software Foundation. All Rights Reserved.