org.apache.ojb.broker.locking
Class CommonsOJBLockManager

java.lang.Object
  extended byGenericLockManager
      extended byorg.apache.ojb.broker.locking.CommonsOJBLockManager

public class CommonsOJBLockManager
extends GenericLockManager

Extension of org.apache.commons.transaction.locking.GenericLockManager to support all locking isolation level defined in OJB locking api and a provider of specific org.apache.commons.transaction.locking.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.2.1 2005/02/19 21:49:53 arminw Exp $
Author:
Armin Waibel
See Also:
Serialized Form

Constructor Summary
CommonsOJBLockManager(LoggerFacade logger, long timeoutMSecs, long checkThreshholdMSecs)
           
 
Method Summary
 MultiLevelLock atomicGetOrCreateLock(java.lang.Object resourceId)
           
 org.apache.ojb.broker.locking.CommonsOJBLockManager.OJBLock atomicGetOrCreateLock(java.lang.Object resourceId, java.lang.Object isolationId)
          Either gets an existing lock on the specified resource or creates one if none exists.
 org.apache.ojb.broker.locking.CommonsOJBLockManager.OJBLock createIsolationLevel(java.lang.Object resourceId, java.lang.Object isolationId, LoggerFacade logger)
          Creates org.apache.commons.transaction.locking.GenericLock based org.apache.commons.transaction.locking.MultiLevelLock2 instances dependend on the specified isolation identity object.
 void lock(java.lang.Object ownerId, java.lang.Object resourceId, int targetLockLevel, int compatibility, boolean preferred, long timeoutMSecs)
           
 void lock(java.lang.Object ownerId, java.lang.Object resourceId, int targetLockLevel, int compatibility, boolean preferred, long timeoutMSecs, java.lang.Object isolationId)
          Most flexible way to acquire a lock on a resource.
 boolean tryLock(java.lang.Object ownerId, java.lang.Object resourceId, int targetLockLevel, boolean reentrant)
           
 boolean tryLock(java.lang.Object ownerId, java.lang.Object resourceId, int targetLockLevel, boolean reentrant, java.lang.Object isolationId)
          Tries to acquire a lock on a resource.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommonsOJBLockManager

public CommonsOJBLockManager(LoggerFacade logger,
                             long timeoutMSecs,
                             long checkThreshholdMSecs)
                      throws java.lang.IllegalArgumentException
Method Detail

tryLock

public boolean tryLock(java.lang.Object ownerId,
                       java.lang.Object resourceId,
                       int targetLockLevel,
                       boolean reentrant)
See Also:
org.apache.commons.transaction.locking.GenericLockManager#tryLock(Object, Object, int, boolean)

tryLock

public boolean tryLock(java.lang.Object ownerId,
                       java.lang.Object resourceId,
                       int targetLockLevel,
                       boolean reentrant,
                       java.lang.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(java.lang.Object ownerId,
                 java.lang.Object resourceId,
                 int targetLockLevel,
                 int compatibility,
                 boolean preferred,
                 long timeoutMSecs)
          throws LockException
Throws:
LockException
See Also:
org.apache.commons.transaction.locking.GenericLockManager#lock(Object, Object, int, int, boolean, long)

lock

public void lock(java.lang.Object ownerId,
                 java.lang.Object resourceId,
                 int targetLockLevel,
                 int compatibility,
                 boolean preferred,
                 long timeoutMSecs,
                 java.lang.Object isolationId)
          throws 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 - GenericLock#COMPATIBILITY_NONEif no additional compatibility is desired (same as reentrant set to false) , GenericLock#COMPATIBILITY_REENTRANTif lock level by the same owner shall not affect compatibility (same as reentrant set to true), or GenericLock#COMPATIBILITY_SUPPORTif lock levels that are the same as the desired shall not affect compatibility, or finally GenericLock#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:
LockException - will be thrown when the lock can not be acquired

atomicGetOrCreateLock

public MultiLevelLock atomicGetOrCreateLock(java.lang.Object resourceId)
See Also:
org.apache.commons.transaction.locking.GenericLockManager#atomicGetOrCreateLock(Object)

atomicGetOrCreateLock

public org.apache.ojb.broker.locking.CommonsOJBLockManager.OJBLock atomicGetOrCreateLock(java.lang.Object resourceId,
                                                                                         java.lang.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

createIsolationLevel

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



(C) 2002 - 2004 Apache Software Foundation
All rights reserved. Published under the Apache License 2.0.
http://db.apache.org/ojb
Version: 1.0.3, 2005-04-2