org.apache.ojb.broker.locking
Class CommonsOJBLockManager

java.lang.Object
  extended by org.apache.commons.transaction.locking.GenericLockManager
      extended by org.apache.ojb.broker.locking.CommonsOJBLockManager
All Implemented Interfaces:
org.apache.commons.transaction.locking.LockManager, org.apache.commons.transaction.locking.LockManager2
Direct Known Subclasses:
LockManagerCommonsImpl.OJBLockManager

 class CommonsOJBLockManager
extends org.apache.commons.transaction.locking.GenericLockManager

Extension of GenericLockManager to support all locking isolation level defined in OJB locking api and a provider of specific GenericLock implementation classes representing the isolation levels specified in LockManager, like IsolationLevels.IL_READ_COMMITTED, ... .

The specific lock classes will be returned on call of createIsolationLevel(Object, Object, org.apache.commons.transaction.util.LoggerFacade) dependend on the specified isolation level.

Version:
$Id: CommonsOJBLockManager.java,v 1.1 2007-08-24 22:17:41 ewestfal Exp $
Author:
Armin Waibel

Nested Class Summary
(package private) static class CommonsOJBLockManager.OJBLock
          Abstract base class to implement the different GenericLock extension classes representing the OJB isolation levels (e.g.
(package private) static class CommonsOJBLockManager.ReadCommitedLock
          Implementation of isolation level IsolationLevels.IL_READ_COMMITTED.
(package private) static class CommonsOJBLockManager.ReadUncommittedLock
          Implementation of isolation level IsolationLevels.IL_READ_UNCOMMITTED.
(package private) static class CommonsOJBLockManager.RepeadableReadsLock
          Implementation of isolation level IsolationLevels.IL_REPEATABLE_READ.
(package private) static class CommonsOJBLockManager.SerializeableLock
          Implementation of isolation level IsolationLevels.IL_SERIALIZABLE.
 
Field Summary
(package private) static int COMMON_READ_LOCK
           
(package private) static int COMMON_UPGRADE_LOCK
           
(package private) static int COMMON_WRITE_LOCK
           
 
Fields inherited from class org.apache.commons.transaction.locking.GenericLockManager
checkThreshhold, DEFAULT_CHECK_THRESHHOLD, DEFAULT_TIMEOUT, effectiveGlobalTimeouts, globalLocks, globalOwners, globalTimeoutMSecs, logger, maxLockLevel, timedOutOwners
 
Constructor Summary
CommonsOJBLockManager(org.apache.commons.transaction.util.LoggerFacade logger, long timeoutMSecs, long checkThreshholdMSecs)
           
 
Method Summary
 org.apache.commons.transaction.locking.MultiLevelLock atomicGetOrCreateLock(Object resourceId)
           
 CommonsOJBLockManager.OJBLock atomicGetOrCreateLock(Object resourceId, Object isolationId)
          Either gets an existing lock on the specified resource or creates one if none exists.
 CommonsOJBLockManager.OJBLock createIsolationLevel(Object resourceId, Object isolationId, org.apache.commons.transaction.util.LoggerFacade logger)
          Creates GenericLock based MultiLevelLock2 instances dependend on the specified isolation identity object.
protected  org.apache.commons.transaction.locking.GenericLock createLock(Object resourceId)
           
protected  org.apache.commons.transaction.locking.GenericLock createLock(Object resourceId, Object isolationId)
           
 void lock(Object ownerId, Object resourceId, int targetLockLevel, int compatibility, boolean preferred, long timeoutMSecs)
           
 void lock(Object ownerId, Object resourceId, int targetLockLevel, int compatibility, boolean preferred, long timeoutMSecs, Object isolationId)
          Most flexible way to acquire a lock on a resource.
(package private)  int mapLockLevelDependendOnIsolationLevel(Integer isolationId, int lockLevel)
          Helper method to map the specified common lock level (e.g like COMMON_READ_LOCK, #COMMON_UPGRADE_LOCK, ...) based on the isolation level to the internal used lock level value by the MultiLevelLock2 implementation.
 boolean tryLock(Object ownerId, Object resourceId, int targetLockLevel, boolean reentrant)
           
 boolean tryLock(Object ownerId, Object resourceId, int targetLockLevel, boolean reentrant, Object isolationId)
          Tries to acquire a lock on a resource.
 
Methods inherited from class org.apache.commons.transaction.locking.GenericLockManager
addOwner, checkLock, doLock, getAll, getLevel, getLock, getLocks, getNextGlobalConflictTimeout, hasLock, lock, lock, release, releaseAll, releaseAllNoTimeOutReset, releaseTimedOutOwners, removeLock, removeOwner, startGlobalTimeout, timeOut, timeoutCheck, toString, wouldDeadlock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

COMMON_READ_LOCK

static final int COMMON_READ_LOCK
See Also:
Constant Field Values

COMMON_WRITE_LOCK

static final int COMMON_WRITE_LOCK
See Also:
Constant Field Values

COMMON_UPGRADE_LOCK

static final int COMMON_UPGRADE_LOCK
See Also:
Constant Field Values
Constructor Detail

CommonsOJBLockManager

public CommonsOJBLockManager(org.apache.commons.transaction.util.LoggerFacade logger,
                             long timeoutMSecs,
                             long checkThreshholdMSecs)
                      throws IllegalArgumentException
Throws:
IllegalArgumentException
Method Detail

tryLock

public boolean tryLock(Object ownerId,
                       Object resourceId,
                       int targetLockLevel,
                       boolean reentrant)
Specified by:
tryLock in interface org.apache.commons.transaction.locking.LockManager2
Overrides:
tryLock in class org.apache.commons.transaction.locking.GenericLockManager
See Also:
GenericLockManager.tryLock(Object, Object, int, boolean)

tryLock

public boolean tryLock(Object ownerId,
                       Object resourceId,
                       int targetLockLevel,
                       boolean reentrant,
                       Object isolationId)
Tries to acquire a lock on a resource.

This method does not block, but immediatly returns. If a lock is not available false will be returned.

Parameters:
ownerId - a unique id identifying the entity that wants to acquire this lock
resourceId - the resource to get the level for
targetLockLevel - the lock level to acquire
reentrant - true if this request shall not be influenced by other locks held by the same owner
isolationId - the isolation level identity key. See CommonsOJBLockManager.
Returns:
true if the lock has been acquired, false otherwise

lock

public void lock(Object ownerId,
                 Object resourceId,
                 int targetLockLevel,
                 int compatibility,
                 boolean preferred,
                 long timeoutMSecs)
          throws org.apache.commons.transaction.locking.LockException
Specified by:
lock in interface org.apache.commons.transaction.locking.LockManager2
Overrides:
lock in class org.apache.commons.transaction.locking.GenericLockManager
Throws:
org.apache.commons.transaction.locking.LockException
See Also:
GenericLockManager.lock(Object, Object, int, int, boolean, long)

lock

public void lock(Object ownerId,
                 Object resourceId,
                 int targetLockLevel,
                 int compatibility,
                 boolean preferred,
                 long timeoutMSecs,
                 Object isolationId)
          throws org.apache.commons.transaction.locking.LockException
Most flexible way to acquire a lock on a resource.

This method blocks and waits for the lock in case it is not avaiable. If there is a timeout or a deadlock or the thread is interrupted a LockException is thrown.

Parameters:
ownerId - a unique id identifying the entity that wants to acquire this lock
resourceId - the resource to get the level for
targetLockLevel - the lock level to acquire
compatibility - MultiLevelLock2.COMPATIBILITY_NONEif no additional compatibility is desired (same as reentrant set to false) , MultiLevelLock2.COMPATIBILITY_REENTRANTif lock level by the same owner shall not affect compatibility (same as reentrant set to true), or MultiLevelLock2.COMPATIBILITY_SUPPORTif lock levels that are the same as the desired shall not affect compatibility, or finally MultiLevelLock2.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 - specifies the maximum wait time in milliseconds
isolationId - the isolation level identity key. See CommonsOJBLockManager.
Throws:
org.apache.commons.transaction.locking.LockException - will be thrown when the lock can not be acquired

atomicGetOrCreateLock

public org.apache.commons.transaction.locking.MultiLevelLock atomicGetOrCreateLock(Object resourceId)
Specified by:
atomicGetOrCreateLock in interface org.apache.commons.transaction.locking.LockManager
Overrides:
atomicGetOrCreateLock in class org.apache.commons.transaction.locking.GenericLockManager
See Also:
GenericLockManager.atomicGetOrCreateLock(Object)

atomicGetOrCreateLock

public CommonsOJBLockManager.OJBLock atomicGetOrCreateLock(Object resourceId,
                                                           Object isolationId)
Either gets an existing lock on the specified resource or creates one if none exists. This methods guarantees to do this atomically.

Parameters:
resourceId - the resource to get or create the lock on
isolationId - the isolation level identity key. See CommonsOJBLockManager.
Returns:
the lock for the specified resource

createLock

protected org.apache.commons.transaction.locking.GenericLock createLock(Object resourceId)
Overrides:
createLock in class org.apache.commons.transaction.locking.GenericLockManager
See Also:
GenericLockManager.createLock(Object)

createLock

protected org.apache.commons.transaction.locking.GenericLock createLock(Object resourceId,
                                                                        Object isolationId)

createIsolationLevel

public CommonsOJBLockManager.OJBLock createIsolationLevel(Object resourceId,
                                                          Object isolationId,
                                                          org.apache.commons.transaction.util.LoggerFacade logger)
Creates GenericLock based MultiLevelLock2 instances dependend on the specified isolation identity object.


mapLockLevelDependendOnIsolationLevel

int mapLockLevelDependendOnIsolationLevel(Integer isolationId,
                                          int lockLevel)
Helper method to map the specified common lock level (e.g like COMMON_READ_LOCK, #COMMON_UPGRADE_LOCK, ...) based on the isolation level to the internal used lock level value by the MultiLevelLock2 implementation.

Parameters:
isolationId -
lockLevel -
Returns:


Copyright © 2007-2012 The Kuali Foundation. All Rights Reserved.