org.apache.ojb.broker.locking
Class CommonsOJBLockManager
java.lang.Object
org.apache.commons.transaction.locking.GenericLockManager
org.apache.ojb.broker.locking.CommonsOJBLockManager
- All Implemented Interfaces:
- org.apache.commons.transaction.locking.LockManager, org.apache.commons.transaction.locking.LockManager2
- public 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.2.1 2005/02/19 21:49:53 arminw Exp $
- Author:
- Armin Waibel
Fields inherited from class org.apache.commons.transaction.locking.GenericLockManager |
DEFAULT_CHECK_THRESHHOLD, DEFAULT_TIMEOUT |
Constructor Summary |
CommonsOJBLockManager(org.apache.commons.transaction.util.LoggerFacade logger,
long timeoutMSecs,
long checkThreshholdMSecs)
|
Method Summary |
org.apache.commons.transaction.locking.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,
org.apache.commons.transaction.util.LoggerFacade logger)
Creates GenericLock based
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 org.apache.commons.transaction.locking.GenericLockManager |
checkLock, getAll, getLevel, getLock, getLocks, hasLock, lock, lock, release, releaseAll, removeLock, startGlobalTimeout, toString |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
CommonsOJBLockManager
public CommonsOJBLockManager(org.apache.commons.transaction.util.LoggerFacade logger,
long timeoutMSecs,
long checkThreshholdMSecs)
throws java.lang.IllegalArgumentException
tryLock
public boolean tryLock(java.lang.Object ownerId,
java.lang.Object resourceId,
int targetLockLevel,
boolean reentrant)
- See Also:
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
lockresourceId
- the resource to get the level fortargetLockLevel
- the lock level to acquirereentrant
- true
if this request shall not be influenced by
other locks held by the same ownerisolationId
- 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 org.apache.commons.transaction.locking.LockException
- Throws:
org.apache.commons.transaction.locking.LockException
- See Also:
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 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
lockresourceId
- the resource to get the level fortargetLockLevel
- the lock level to acquirecompatibility
- MultiLevelLock2.COMPATIBILITY_NONE
if no additional compatibility is
desired (same as reentrant set to false) ,
MultiLevelLock2.COMPATIBILITY_REENTRANT
if lock level by the same
owner shall not affect compatibility (same as reentrant set to
true), or MultiLevelLock2.COMPATIBILITY_SUPPORT
if lock levels that
are the same as the desired shall not affect compatibility, or
finally MultiLevelLock2.COMPATIBILITY_REENTRANT_AND_SUPPORT
which is
a combination of reentrant and supportpreferred
- in case this lock request is incompatible with existing ones
and we wait, it shall be granted before other waiting requests
that are not preferredtimeoutMSecs
- specifies the maximum wait time in millisecondsisolationId
- 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(java.lang.Object resourceId)
- See Also:
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 onisolationId
- 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,
org.apache.commons.transaction.util.LoggerFacade logger)
- Creates
GenericLock
based
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