org.apache.ojb.broker.locking
Class LockManagerCommonsImpl

java.lang.Object
  extended by org.apache.ojb.broker.locking.LockManagerCommonsImpl
All Implemented Interfaces:
IsolationLevels, LockManager

public class LockManagerCommonsImpl
extends java.lang.Object
implements LockManager

A LockManager implementation based on apache's commons-transaction locking part.

The timeout of locks is currently (OJB 1.0.2) not supported, maybe in further versions.

Version:
$Id: LockManagerCommonsImpl.java 365232 2005-12-21 22:36:07Z tomdz $
Author:
Armin Waibel

Field Summary
 
Fields inherited from interface org.apache.ojb.broker.locking.LockManager
DEFAULT_BLOCK_TIMEOUT, DEFAULT_LOCK_TIMEOUT
 
Fields inherited from interface org.apache.ojb.broker.locking.IsolationLevels
IL_DEFAULT, IL_NONE, IL_OPTIMISTIC, IL_READ_COMMITTED, IL_READ_UNCOMMITTED, IL_REPEATABLE_READ, IL_SERIALIZABLE, LITERAL_IL_NONE, LITERAL_IL_OPTIMISTIC, LITERAL_IL_READ_COMMITTED, LITERAL_IL_READ_UNCOMMITTED, LITERAL_IL_REPEATABLE_READ, LITERAL_IL_SERIALIZABLE
 
Constructor Summary
LockManagerCommonsImpl()
           
 
Method Summary
 long getBlockTimeout()
          The maximal time to wait for acquire a lock.
 java.lang.String getLockInfo()
          Returns info about the used lock manager implementation and the state of the lock manager.
 long getLockTimeout()
          Get the current used lock timeout value in milliseconds.
 boolean hasRead(java.lang.Object key, java.lang.Object resourceId)
          Checks if there is a read lock for owner key on resource object.
 boolean hasUpgrade(java.lang.Object key, java.lang.Object resourceId)
          Checks if there is a upgrade lock for lock key on resource object.
 boolean hasWrite(java.lang.Object key, java.lang.Object resourceId)
          Checks if there is a write lock for lock key on resource object.
 boolean readLock(java.lang.Object key, java.lang.Object resourceId, int isolationLevel)
          Acquires a readlock for lock key on resource object.
 boolean releaseLock(java.lang.Object key, java.lang.Object resourceId)
          Releases a lock for lock key on resource object.
 void releaseLocks(java.lang.Object key)
          Release all resource locks hold by the specified owner key.
 void setBlockTimeout(long blockTimeout)
          Set the maximal time to wait for acquire a lock in milliseconds.
 void setLockTimeout(long timeout)
          Set the lock timeout value in milliseconds.
 boolean upgradeLock(java.lang.Object key, java.lang.Object resourceId, int isolationLevel)
          Acquire an upgrade lock.
 boolean writeLock(java.lang.Object key, java.lang.Object resourceId, int isolationLevel)
          Acquires a write lock for lock key on resource object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LockManagerCommonsImpl

public LockManagerCommonsImpl()
Method Detail

getLockTimeout

public long getLockTimeout()
Description copied from interface: LockManager
Get the current used lock timeout value in milliseconds.

Specified by:
getLockTimeout in interface LockManager
Returns:
Current used locking timeout value in ms.

setLockTimeout

public void setLockTimeout(long timeout)
Description copied from interface: LockManager
Set the lock timeout value in milliseconds. If timeout was set to -1 the never will never timeout.

Specified by:
setLockTimeout in interface LockManager
Parameters:
timeout - The lock timeout in ms of acquired read/write/upgrade locks.

getBlockTimeout

public long getBlockTimeout()
Description copied from interface: LockManager
The maximal time to wait for acquire a lock.

Specified by:
getBlockTimeout in interface LockManager
Returns:

setBlockTimeout

public void setBlockTimeout(long blockTimeout)
Description copied from interface: LockManager
Set the maximal time to wait for acquire a lock in milliseconds. All so called non-blocking implementation will ignore this setting.

Specified by:
setBlockTimeout in interface LockManager
Parameters:
blockTimeout - The time to wait for acquire a lock.

getLockInfo

public java.lang.String getLockInfo()
Description copied from interface: LockManager
Returns info about the used lock manager implementation and the state of the lock manager.

Specified by:
getLockInfo in interface LockManager

readLock

public boolean readLock(java.lang.Object key,
                        java.lang.Object resourceId,
                        int isolationLevel)
Description copied from interface: LockManager
Acquires a readlock for lock key on resource object. Returns true if successful, else false.

Specified by:
readLock in interface LockManager
Parameters:
key - The owner key of the lock.
resourceId - The resource to lock.
isolationLevel - The isolation level of the lock.
Returns:
True if the lock was successfully acquired.

writeLock

public boolean writeLock(java.lang.Object key,
                         java.lang.Object resourceId,
                         int isolationLevel)
Description copied from interface: LockManager
Acquires a write lock for lock key on resource object. Returns true if successful, else false.

Specified by:
writeLock in interface LockManager
Parameters:
key - The owner key of the lock.
resourceId - The resource to lock.
isolationLevel - The isolation level of the lock.
Returns:
True if the lock was successfully acquired.

upgradeLock

public boolean upgradeLock(java.lang.Object key,
                           java.lang.Object resourceId,
                           int isolationLevel)
Description copied from interface: LockManager
Acquire an upgrade lock. (Current implementations always acquire a write lock instead).

Specified by:
upgradeLock in interface LockManager
Parameters:
key - The owner key of the lock.
resourceId - The resource to lock.
isolationLevel - The isolation level of the lock.
Returns:
True if the lock was successfully acquired.

releaseLock

public boolean releaseLock(java.lang.Object key,
                           java.lang.Object resourceId)
Description copied from interface: LockManager
Releases a lock for lock key on resource object. Returns true if successful, else false.

Specified by:
releaseLock in interface LockManager
Parameters:
key - The owner key of the lock.
resourceId - The resource to release.
Returns:
True if the lock was successfully released.

releaseLocks

public void releaseLocks(java.lang.Object key)
Description copied from interface: LockManager
Release all resource locks hold by the specified owner key.

Specified by:
releaseLocks in interface LockManager
Parameters:
key - The owner key to release all associated locks.

hasRead

public boolean hasRead(java.lang.Object key,
                       java.lang.Object resourceId)
Description copied from interface: LockManager
Checks if there is a read lock for owner key on resource object. Returns true if so, else false.

Specified by:
hasRead in interface LockManager
Parameters:
key - The owner key of the lock.
resourceId - The resource to check.
Returns:
True if the lock exists.

hasWrite

public boolean hasWrite(java.lang.Object key,
                        java.lang.Object resourceId)
Description copied from interface: LockManager
Checks if there is a write lock for lock key on resource object. Returns true if so, else false.

Specified by:
hasWrite in interface LockManager
Parameters:
key - The owner key of the lock.
resourceId - The resource to check.
Returns:
True if the lock exists.

hasUpgrade

public boolean hasUpgrade(java.lang.Object key,
                          java.lang.Object resourceId)
Description copied from interface: LockManager
Checks if there is a upgrade lock for lock key on resource object. Returns true if so, else false.

Specified by:
hasUpgrade in interface LockManager
Parameters:
key - The owner key of the lock.
resourceId - The resource to check.
Returns:
True if the lock exists.


(C) 2002 - 2006 Apache Software Foundation
All rights reserved. Published under the Apache License 2.0.
http://db.apache.org/ojb
Version: 1.0.4, 2005-12-30