org.apache.ojb.odmg.locking
Class InMemoryLockMapImpl

java.lang.Object
  extended byorg.apache.ojb.odmg.locking.InMemoryLockMapImpl
All Implemented Interfaces:
Configurable, LockMap

public class InMemoryLockMapImpl
extends java.lang.Object
implements LockMap

We use a HashMap and synchronize blocks of access for a get "check" then put operation. We cannot use the hashtable as you could check in one synchronized call then put in another while a different thread is doing the same thing.

Version:
$Id: InMemoryLockMapImpl.java,v 1.12 2004/01/17 16:57:34 thma Exp $
Author:
Matthew Baird update for use of Hashmap with synchronization. implemented timed out lock removal algo., Thomas Mahler original author.

Constructor Summary
InMemoryLockMapImpl()
           
 
Method Summary
 boolean addReader(TransactionImpl tx, java.lang.Object obj)
          Add a reader lock entry for transaction tx on object obj to the persistent storage.
(package private)  void addReaderInternal(LockEntry reader)
           
 void configure(Configuration pConfig)
          configure an object using the Configuration pConfig
 java.util.Collection getReaders(Identity oid)
           
 java.util.Collection getReaders(java.lang.Object obj)
          returns a collection of Reader LockEntries for object obj.
(package private)  int getSize()
           
 LockEntry getWriter(Identity oid)
           
 LockEntry getWriter(java.lang.Object obj)
          returns the LockEntry for the Writer of object obj.
(package private)  boolean hasReadLock(LockEntry entry)
           
 boolean hasReadLock(TransactionImpl tx, java.lang.Object obj)
          check if there is a reader lock entry for transaction tx on object obj in the persistent storage.
 void removeReader(TransactionImpl tx, java.lang.Object obj)
          remove a reader lock entry for transaction tx on object obj from the persistent storage.
(package private)  void removeReaderByLock(LockEntry lock)
           
 void removeWriter(LockEntry writer)
          remove a writer lock entry for transaction tx on object obj from the persistent storage.
 boolean setWriter(TransactionImpl tx, java.lang.Object obj)
          generate a writer lock entry for transaction tx on object obj and write it to the persistent storage.
(package private)  void setWriterByLock(LockEntry writer)
           
 boolean upgradeLock(LockEntry reader)
          upgrade a reader lock entry for transaction tx on object obj and write it to the persistent storage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InMemoryLockMapImpl

public InMemoryLockMapImpl()
Method Detail

getWriter

public LockEntry getWriter(java.lang.Object obj)
returns the LockEntry for the Writer of object obj. If now writer exists, null is returned.

Specified by:
getWriter in interface LockMap

getWriter

public LockEntry getWriter(Identity oid)

getReaders

public java.util.Collection getReaders(java.lang.Object obj)
returns a collection of Reader LockEntries for object obj. If no LockEntries could be found an empty Vector is returned.

Specified by:
getReaders in interface LockMap

getReaders

public java.util.Collection getReaders(Identity oid)

addReader

public boolean addReader(TransactionImpl tx,
                         java.lang.Object obj)
Add a reader lock entry for transaction tx on object obj to the persistent storage.

Specified by:
addReader in interface LockMap

addReaderInternal

void addReaderInternal(LockEntry reader)

removeReader

public void removeReader(TransactionImpl tx,
                         java.lang.Object obj)
remove a reader lock entry for transaction tx on object obj from the persistent storage.

Specified by:
removeReader in interface LockMap

removeReaderByLock

void removeReaderByLock(LockEntry lock)

removeWriter

public void removeWriter(LockEntry writer)
remove a writer lock entry for transaction tx on object obj from the persistent storage.

Specified by:
removeWriter in interface LockMap

upgradeLock

public boolean upgradeLock(LockEntry reader)
upgrade a reader lock entry for transaction tx on object obj and write it to the persistent storage.

Specified by:
upgradeLock in interface LockMap

setWriter

public boolean setWriter(TransactionImpl tx,
                         java.lang.Object obj)
generate a writer lock entry for transaction tx on object obj and write it to the persistent storage.

Specified by:
setWriter in interface LockMap

setWriterByLock

void setWriterByLock(LockEntry writer)

hasReadLock

public boolean hasReadLock(TransactionImpl tx,
                           java.lang.Object obj)
check if there is a reader lock entry for transaction tx on object obj in the persistent storage.

Specified by:
hasReadLock in interface LockMap

hasReadLock

boolean hasReadLock(LockEntry entry)

configure

public void configure(Configuration pConfig)
               throws ConfigurationException
Description copied from interface: Configurable
configure an object using the Configuration pConfig

Specified by:
configure in interface Configurable
Parameters:
pConfig - the Configuration object used to configure current instance
Throws:
ConfigurationException

getSize

int getSize()


Authors: Thomas Mahler and others. (C) 2000 - 2003 Apache Software Foundation
All rights reserved. Published under the Apache License.
http://db.apache.org/ojb
Version: 1.0.rc5, 2003-12-14