org.apache.commons.transaction.memory
Class PessimisticTxMap<K,V>

java.lang.Object
  extended by org.apache.commons.transaction.AbstractTransactionalResourceManager<BasicTxMap.MapTxContext>
      extended by org.apache.commons.transaction.memory.BasicTxMap<K,V>
          extended by org.apache.commons.transaction.memory.PessimisticTxMap<K,V>
All Implemented Interfaces:
Map<K,V>, ManageableResourceManager, TxMap<K,V>, TransactionalResourceManager

public class PessimisticTxMap<K,V>
extends BasicTxMap<K,V>
implements TxMap<K,V>

Map featuring transactional control.

By using pessimistic transaction control (blocking locks) this wrapper has better isolation than BasicTxMap, but also has less possible concurrency and may even deadlock. A commit, however, will never fail.

Caution:Some operations that would require global locks (e.g. size() or clear() or not properly isolated as this implementation does not support global locks.

This implementation wraps a map of type ConcurrentHashMap.

This implementation is thread-safe.

See Also:
BasicTxMap, OptimisticTxMap, ConcurrentHashMap

Nested Class Summary
 class PessimisticTxMap.LockingTxContext
           
 
Nested classes/interfaces inherited from class org.apache.commons.transaction.memory.BasicTxMap
BasicTxMap.HashEntry, BasicTxMap.MapTxContext
 
Nested classes/interfaces inherited from class org.apache.commons.transaction.AbstractTransactionalResourceManager
AbstractTransactionalResourceManager.AbstractTxContext
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
 
Fields inherited from class org.apache.commons.transaction.memory.BasicTxMap
wrapped
 
Fields inherited from class org.apache.commons.transaction.AbstractTransactionalResourceManager
activeTx
 
Constructor Summary
PessimisticTxMap(String name)
           
PessimisticTxMap(String name, LockManager<Object,Object> lm)
           
 
Method Summary
protected  void assureWriteLock(Object key)
           
 boolean commitCanFail()
          Checks whether a tried commit could possibly fail because of logical reasons.
protected  PessimisticTxMap.LockingTxContext createContext()
           
 Set entrySet()
           
 Set keySet()
           
 V put(K key, V value)
           
 V remove(Object key)
           
 Collection values()
           
 
Methods inherited from class org.apache.commons.transaction.memory.BasicTxMap
clear, containsKey, containsValue, get, getActiveTx, getWrappedMap, isEmpty, putAll, size
 
Methods inherited from class org.apache.commons.transaction.AbstractTransactionalResourceManager
commitTransaction, forgetTransaction, getCheckedActiveTx, getLm, getName, isPartofComplexTransaction, isReadOnly, isRollbackOnly, joinTransaction, prepareTransaction, rollbackTransaction, setActiveTx, setLm, setName, startTransaction
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.commons.transaction.memory.TxMap
getWrappedMap
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, equals, get, hashCode, isEmpty, putAll, size
 
Methods inherited from interface org.apache.commons.transaction.ManageableResourceManager
forgetTransaction, isReadOnly, isRollbackOnly, joinTransaction, prepareTransaction
 
Methods inherited from interface org.apache.commons.transaction.TransactionalResourceManager
commitTransaction, rollbackTransaction, startTransaction
 

Constructor Detail

PessimisticTxMap

public PessimisticTxMap(String name)

PessimisticTxMap

public PessimisticTxMap(String name,
                        LockManager<Object,Object> lm)
Method Detail

values

public Collection values()
Specified by:
values in interface Map<K,V>
Overrides:
values in class BasicTxMap<K,V>
See Also:
Map.values()

entrySet

public Set entrySet()
Specified by:
entrySet in interface Map<K,V>
Overrides:
entrySet in class BasicTxMap<K,V>
See Also:
Map.entrySet()

keySet

public Set keySet()
Specified by:
keySet in interface Map<K,V>
Overrides:
keySet in class BasicTxMap<K,V>
See Also:
Map.keySet()

remove

public V remove(Object key)
Specified by:
remove in interface Map<K,V>
Overrides:
remove in class BasicTxMap<K,V>
See Also:
Map.remove(java.lang.Object)

put

public V put(K key,
             V value)
Specified by:
put in interface Map<K,V>
Overrides:
put in class BasicTxMap<K,V>
See Also:
Map.put(java.lang.Object, java.lang.Object)

assureWriteLock

protected void assureWriteLock(Object key)

createContext

protected PessimisticTxMap.LockingTxContext createContext()
Overrides:
createContext in class BasicTxMap<K,V>

commitCanFail

public boolean commitCanFail()
Description copied from interface: ManageableResourceManager
Checks whether a tried commit could possibly fail because of logical reasons.

Specified by:
commitCanFail in interface ManageableResourceManager
Overrides:
commitCanFail in class BasicTxMap<K,V>
Returns:
true if a commit could fail


Copyright © 2004-2007 The Apache Software Foundation. All Rights Reserved.