org.apache.ojb.broker.locking
Class LockManagerInMemoryImpl

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

public class LockManagerInMemoryImpl
extends java.lang.Object
implements LockManager

This implementation of the LockManager interface supports a simple, fast, non-blocking pessimistic locking for single JVM applications.

Version:
$Id: LockManagerInMemoryImpl.java 365232 2005-12-21 22:36:07Z tomdz $

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
LockManagerInMemoryImpl()
           
 
Method Summary
 long getBlockTimeout()
          NOOP
 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.
 int lockedObjects()
           
 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.
 boolean removeReader(java.lang.Object key, java.lang.Object resourceId)
          Remove an read lock.
 boolean removeWriter(java.lang.Object key, java.lang.Object resourceId)
          Remove an write lock.
 void setBlockTimeout(long timeout)
          NOOP
 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

LockManagerInMemoryImpl

public LockManagerInMemoryImpl()
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()
NOOP

Specified by:
getBlockTimeout in interface LockManager
Returns:
Always '0'

setBlockTimeout

public void setBlockTimeout(long timeout)
NOOP

Specified by:
setBlockTimeout in interface LockManager
Parameters:
timeout - 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.

removeReader

public boolean removeReader(java.lang.Object key,
                            java.lang.Object resourceId)
Remove an read lock.


removeWriter

public boolean removeWriter(java.lang.Object key,
                            java.lang.Object resourceId)
Remove an write lock.


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.
See Also:
LockManager.releaseLocks(Object)

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.

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.
See Also:
LockManager.hasWrite(Object, Object)

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.

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.
See Also:
LockManager.hasRead(Object, Object)

lockedObjects

public int lockedObjects()


(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