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 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,v 1.1 2007-08-24 22:17:41 ewestfal Exp $

Nested Class Summary
(package private)  class LockManagerInMemoryImpl.LockEntry
          A lock entry encapsulates locking information.
(package private) static class LockManagerInMemoryImpl.ObjectLocks
           
 
Field Summary
private static long CLEANUP_FREQUENCY
           
private  LockIsolationManager lockStrategyManager
           
private  HashMap locktable
          MBAIRD: a LinkedHashMap returns objects in the order you put them in, while still maintaining an O(1) lookup like a normal hashmap.
private  long lockTimeout
           
private  Logger log
           
private  long m_lastCleanupAt
           
private static int MAX_LOCKS_TO_CLEAN
           
private  long timeoutCounterRead
           
private  long timeoutCounterWrite
           
 
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
private  boolean addReaderIfPossibleInternal(LockManagerInMemoryImpl.LockEntry reader, boolean allowMultipleReader, boolean allowReaderWhenWriteLock)
           
private  void checkTimedOutLocks()
           
 long getBlockTimeout()
          NOOP
 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(Object key, Object resourceId)
          Checks if there is a read lock for owner key on resource object.
private  boolean hasReadLockInternal(Object resourceId, Object key)
           
 boolean hasUpgrade(Object key, Object resourceId)
          Checks if there is a upgrade lock for lock key on resource object.
 boolean hasWrite(Object key, Object resourceId)
          Checks if there is a write lock for lock key on resource object.
private  boolean hasWriteLockInternal(Object resourceId, Object key)
           
 int lockedObjects()
           
 boolean readLock(Object key, Object resourceId, int isolationLevel)
          Acquires a readlock for lock key on resource object.
 boolean releaseLock(Object key, Object resourceId)
          Releases a lock for lock key on resource object.
 void releaseLocks(Object key)
          Release all resource locks hold by the specified owner key.
private  void releaseLocksInternal(Object key)
           
 boolean removeReader(Object key, Object resourceId)
          Remove an read lock.
private  void removeTimedOutLocks(long timeout)
          removes all timed out lock entries from the persistent storage.
 boolean removeWriter(Object key, Object resourceId)
          Remove an write lock.
 void setBlockTimeout(long timeout)
          NOOP
 void setLockTimeout(long timeout)
          Set the lock timeout value in milliseconds.
private  boolean setWriterIfPossibleInternal(LockManagerInMemoryImpl.LockEntry writer, boolean allowReaders)
           
 boolean upgradeLock(Object key, Object resourceId, int isolationLevel)
          Acquire an upgrade lock.
 boolean writeLock(Object key, Object resourceId, int isolationLevel)
          Acquires a write lock for lock key on resource object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private Logger log

CLEANUP_FREQUENCY

private static long CLEANUP_FREQUENCY

MAX_LOCKS_TO_CLEAN

private static int MAX_LOCKS_TO_CLEAN

locktable

private HashMap locktable
MBAIRD: a LinkedHashMap returns objects in the order you put them in, while still maintaining an O(1) lookup like a normal hashmap. We can then use this to get the oldest entries very quickly, makes cleanup a breeze.


lockStrategyManager

private LockIsolationManager lockStrategyManager

m_lastCleanupAt

private long m_lastCleanupAt

lockTimeout

private long lockTimeout

timeoutCounterRead

private long timeoutCounterRead

timeoutCounterWrite

private long timeoutCounterWrite
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 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(Object key,
                        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.

addReaderIfPossibleInternal

private boolean addReaderIfPossibleInternal(LockManagerInMemoryImpl.LockEntry reader,
                                            boolean allowMultipleReader,
                                            boolean allowReaderWhenWriteLock)

removeReader

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


removeWriter

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


releaseLock

public boolean releaseLock(Object key,
                           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(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)

releaseLocksInternal

private void releaseLocksInternal(Object key)

writeLock

public boolean writeLock(Object key,
                         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.

setWriterIfPossibleInternal

private boolean setWriterIfPossibleInternal(LockManagerInMemoryImpl.LockEntry writer,
                                            boolean allowReaders)

upgradeLock

public boolean upgradeLock(Object key,
                           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(Object key,
                        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)

hasWriteLockInternal

private boolean hasWriteLockInternal(Object resourceId,
                                     Object key)

hasUpgrade

public boolean hasUpgrade(Object key,
                          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(Object key,
                       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)

hasReadLockInternal

private boolean hasReadLockInternal(Object resourceId,
                                    Object key)

lockedObjects

public int lockedObjects()

checkTimedOutLocks

private void checkTimedOutLocks()

removeTimedOutLocks

private void removeTimedOutLocks(long timeout)
removes all timed out lock entries from the persistent storage. The timeout value can be set in the OJB properties file.



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