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:
- Map, 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: 1.1 $
- See Also:
TransactionalMapWrapper
,
OptimisticMapWrapper
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 |
READ
protected static final int READ
- See Also:
- Constant Field Values
WRITE
protected static final int WRITE
- See Also:
- Constant Field Values
GLOBAL_LOCK_NAME
protected static final String GLOBAL_LOCK_NAME
- See Also:
- Constant Field Values
lockManager
protected LockManager lockManager
globalLock
protected MultiLevelLock globalLock
readTimeOut
protected long readTimeOut
PessimisticMapWrapper
public PessimisticMapWrapper(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 wrapped
PessimisticMapWrapper
public PessimisticMapWrapper(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 sets
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 Collection values()
- Specified by:
values
in interface Map
- Overrides:
values
in class TransactionalMapWrapper
- See Also:
Map.values()
entrySet
public Set entrySet()
- Specified by:
entrySet
in interface Map
- Overrides:
entrySet
in class TransactionalMapWrapper
- See Also:
Map.entrySet()
keySet
public Set keySet()
- Specified by:
keySet
in interface Map
- Overrides:
keySet
in class TransactionalMapWrapper
- See Also:
Map.keySet()
remove
public Object remove(Object key)
- Specified by:
remove
in interface Map
- Overrides:
remove
in class TransactionalMapWrapper
- See Also:
Map.remove(java.lang.Object)
put
public Object put(Object key,
Object value)
- Specified by:
put
in interface Map
- Overrides:
put
in class TransactionalMapWrapper
- See Also:
Map.put(java.lang.Object, java.lang.Object)
assureWriteLock
protected void assureWriteLock(Object key)
assureGlobalLock
protected void assureGlobalLock(int level)
Copyright © 2004 The Apache Software Foundation. All Rights Reserved.