org.apache.commons.transaction.memory
Class PessimisticMapWrapper
java.lang.Object
org.apache.commons.transaction.memory.TransactionalMapWrapper
org.apache.commons.transaction.memory.PessimisticMapWrapper
- All Implemented Interfaces:
- java.util.Map, javax.transaction.Status
public class PessimisticMapWrapper
- extends TransactionalMapWrapper
Wrapper that adds transactional control to all kinds of maps that implement the Map interface. By using
pessimistic transaction control (blocking locks) this wrapper has better isolation than TransactionalMapWrapper, but
also has less possible concurrency and may even deadlock. A commit, however, will never fail.
Start a transaction by calling startTransaction(). Then perform the normal actions on the map and
finally either call TransactionalMapWrapper.commitTransaction() to make your changes permanent or TransactionalMapWrapper.rollbackTransaction() to
undo them.
Caution: Do not modify values retrieved by TransactionalMapWrapper.get(Object) as this will circumvent the transactional mechanism.
Rather clone the value or copy it in a way you see fit and store it back using put(Object, Object).
Note: This wrapper guarantees isolation level SERIALIZABLE.
- Version:
- $Revision$
- See Also:
TransactionalMapWrapper,
OptimisticMapWrapper
| Nested classes/interfaces inherited from interface java.util.Map |
java.util.Map.Entry<K,V> |
| Fields inherited from interface javax.transaction.Status |
STATUS_ACTIVE, STATUS_COMMITTED, STATUS_COMMITTING, STATUS_MARKED_ROLLBACK, STATUS_NO_TRANSACTION, STATUS_PREPARED, STATUS_PREPARING, STATUS_ROLLEDBACK, STATUS_ROLLING_BACK, STATUS_UNKNOWN |
| Methods inherited from class org.apache.commons.transaction.memory.TransactionalMapWrapper |
clear, commitTransaction, containsKey, containsValue, get, getActiveTx, getTransactionState, isEmpty, isReadOnly, isTransactionMarkedForRollback, markTransactionForRollback, putAll, resumeTransaction, rollbackTransaction, setActiveTx, size, suspendTransaction |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface java.util.Map |
equals, hashCode |
READ
protected static final int READ
- See Also:
- Constant Field Values
WRITE
protected static final int WRITE
- See Also:
- Constant Field Values
GLOBAL_LOCK
protected static final java.lang.Object GLOBAL_LOCK
lockManager
protected ReadWriteLockManager lockManager
readTimeOut
protected long readTimeOut
PessimisticMapWrapper
public PessimisticMapWrapper(java.util.Map wrapped,
LoggerFacade logger)
- Creates a new pessimistic transactional map wrapper. Temporary maps and sets to store transactional
data will be instances of
HashMap and HashSet.
- Parameters:
wrapped - map to be wrappedlogger - generic logger used for all kinds of logging
PessimisticMapWrapper
public PessimisticMapWrapper(java.util.Map wrapped,
MapFactory mapFactory,
SetFactory setFactory,
LoggerFacade logger)
- Creates a new pessimistic transactional map wrapper. Temporary maps and sets to store transactional
data will be created and disposed using
MapFactory and SetFactory.
- Parameters:
wrapped - map to be wrappedmapFactory - factory for temporary mapssetFactory - factory for temporary setslogger - generic logger used for all kinds of logging
startTransaction
public void startTransaction()
- Description copied from class:
TransactionalMapWrapper
- Starts a new transaction and associates it with the current thread. All subsequent changes in the same
thread made to the map are invisible from other threads until
TransactionalMapWrapper.commitTransaction() is called.
Use TransactionalMapWrapper.rollbackTransaction() to discard your changes. After calling either method there will be
no transaction associated to the current thread any longer.
Caution: Be careful to finally call one of those methods,
as otherwise the transaction will lurk around for ever.
- Overrides:
startTransaction in class TransactionalMapWrapper
- See Also:
TransactionalMapWrapper.commitTransaction(),
TransactionalMapWrapper.rollbackTransaction()
values
public java.util.Collection values()
- Specified by:
values in interface java.util.Map- Overrides:
values in class TransactionalMapWrapper
- See Also:
Map.values()
entrySet
public java.util.Set entrySet()
- Specified by:
entrySet in interface java.util.Map- Overrides:
entrySet in class TransactionalMapWrapper
- See Also:
Map.entrySet()
keySet
public java.util.Set keySet()
- Specified by:
keySet in interface java.util.Map- Overrides:
keySet in class TransactionalMapWrapper
- See Also:
Map.keySet()
remove
public java.lang.Object remove(java.lang.Object key)
- Specified by:
remove in interface java.util.Map- Overrides:
remove in class TransactionalMapWrapper
- See Also:
Map.remove(java.lang.Object)
put
public java.lang.Object put(java.lang.Object key,
java.lang.Object value)
- Specified by:
put in interface java.util.Map- Overrides:
put in class TransactionalMapWrapper
- See Also:
Map.put(java.lang.Object, java.lang.Object)
assureWriteLock
protected void assureWriteLock(java.lang.Object key)
assureGlobalReadLock
protected void assureGlobalReadLock()
Copyright ? 2004 The Apache Software Foundation. All Rights Reserved.