public class PessimisticMapWrapper extends TransactionalMapWrapper
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.
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.
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)
.
SERIALIZABLE
.TransactionalMapWrapper
,
OptimisticMapWrapper
Modifier and Type | Class and Description |
---|---|
class |
PessimisticMapWrapper.LockingTxContext |
TransactionalMapWrapper.HashEntry, TransactionalMapWrapper.TxContext
Modifier and Type | Field and Description |
---|---|
protected static Object |
GLOBAL_LOCK |
protected ReadWriteLockManager |
lockManager |
protected static int |
READ |
protected long |
readTimeOut |
protected static int |
WRITE |
mapFactory, setFactory, wrapped
STATUS_ACTIVE, STATUS_COMMITTED, STATUS_COMMITTING, STATUS_MARKED_ROLLBACK, STATUS_NO_TRANSACTION, STATUS_PREPARED, STATUS_PREPARING, STATUS_ROLLEDBACK, STATUS_ROLLING_BACK, STATUS_UNKNOWN
Constructor and Description |
---|
PessimisticMapWrapper(Map wrapped,
LoggerFacade logger)
Creates a new pessimistic transactional map wrapper.
|
PessimisticMapWrapper(Map wrapped,
MapFactory mapFactory,
SetFactory setFactory,
LoggerFacade logger)
Creates a new pessimistic transactional map wrapper.
|
Modifier and Type | Method and Description |
---|---|
protected void |
assureGlobalReadLock() |
protected void |
assureWriteLock(Object key) |
Set |
entrySet() |
Set |
keySet() |
Object |
put(Object key,
Object value) |
Object |
remove(Object key) |
void |
startTransaction()
Starts a new transaction and associates it with the current thread.
|
Collection |
values() |
clear, commitTransaction, containsKey, containsValue, get, getActiveTx, getTransactionState, isEmpty, isReadOnly, isTransactionMarkedForRollback, markTransactionForRollback, putAll, resumeTransaction, rollbackTransaction, setActiveTx, size, suspendTransaction
protected static final int READ
protected static final int WRITE
protected static final Object GLOBAL_LOCK
protected ReadWriteLockManager lockManager
protected long readTimeOut
public PessimisticMapWrapper(Map wrapped, LoggerFacade logger)
HashMap
and HashSet
.wrapped
- map to be wrappedlogger
- generic logger used for all kinds of loggingpublic PessimisticMapWrapper(Map wrapped, MapFactory mapFactory, SetFactory setFactory, LoggerFacade logger)
MapFactory
and SetFactory
.wrapped
- map to be wrappedmapFactory
- factory for temporary mapssetFactory
- factory for temporary setslogger
- generic logger used for all kinds of loggingpublic void startTransaction()
TransactionalMapWrapper
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.
startTransaction
in class TransactionalMapWrapper
TransactionalMapWrapper.commitTransaction()
,
TransactionalMapWrapper.rollbackTransaction()
public Collection values()
values
in interface Map
values
in class TransactionalMapWrapper
Map.values()
public Set entrySet()
entrySet
in interface Map
entrySet
in class TransactionalMapWrapper
Map.entrySet()
public Set keySet()
keySet
in interface Map
keySet
in class TransactionalMapWrapper
Map.keySet()
public Object remove(Object key)
remove
in interface Map
remove
in class TransactionalMapWrapper
Map.remove(java.lang.Object)
public Object put(Object key, Object value)
put
in interface Map
put
in class TransactionalMapWrapper
Map.put(java.lang.Object, java.lang.Object)
protected void assureWriteLock(Object key)
protected void assureGlobalReadLock()
Copyright © 2004-2013 The Apache Software Foundation. All Rights Reserved.