public class OptimisticMapWrapper extends TransactionalMapWrapper
Map
interface. By using
a naive optimistic transaction control this wrapper has better isolation than TransactionalMapWrapper
, but
may also fail to commit.
startTransaction()
. Then perform the normal actions on the map and
finally either call commitTransaction()
to make your changes permanent or 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 TransactionalMapWrapper.put(Object, Object)
.
SERIALIZABLE
.
TransactionalMapWrapper
,
PessimisticMapWrapper
Modifier and Type | Class and Description |
---|---|
class |
OptimisticMapWrapper.CopyingTxContext |
TransactionalMapWrapper.HashEntry, TransactionalMapWrapper.TxContext
Modifier and Type | Field and Description |
---|---|
protected static int |
ACCESS_TIMEOUT |
protected Set |
activeTransactions |
protected static int |
COMMIT_TIMEOUT |
protected ReadWriteLock |
commitLock |
protected LoggerFacade |
logger |
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 |
---|
OptimisticMapWrapper(Map wrapped)
Creates a new optimistic transactional map wrapper.
|
OptimisticMapWrapper(Map wrapped,
MapFactory mapFactory,
SetFactory setFactory)
Creates a new optimistic transactional map wrapper.
|
OptimisticMapWrapper(Map wrapped,
MapFactory mapFactory,
SetFactory setFactory,
LoggerFacade logger)
Creates a new optimistic transactional map wrapper.
|
Modifier and Type | Method and Description |
---|---|
Object |
checkForConflicts() |
void |
commitTransaction()
Commits all changes made in the current transaction and deletes the association between the current thread
and the transaction.
|
void |
commitTransaction(boolean force) |
protected void |
copyChangesToConcurrentTransactions() |
void |
rollbackTransaction()
Discards all changes made in the current transaction and deletes the association between the current thread
and the transaction.
|
void |
startTransaction()
Starts a new transaction and associates it with the current thread.
|
clear, containsKey, containsValue, entrySet, get, getActiveTx, getTransactionState, isEmpty, isReadOnly, isTransactionMarkedForRollback, keySet, markTransactionForRollback, put, putAll, remove, resumeTransaction, setActiveTx, size, suspendTransaction, values
protected static final int COMMIT_TIMEOUT
protected static final int ACCESS_TIMEOUT
protected Set activeTransactions
protected LoggerFacade logger
protected ReadWriteLock commitLock
public OptimisticMapWrapper(Map wrapped)
HashMap
and HashSet
.wrapped
- map to be wrappedpublic OptimisticMapWrapper(Map wrapped, MapFactory mapFactory, SetFactory setFactory)
MapFactory
and SetFactory
.wrapped
- map to be wrappedmapFactory
- factory for temporary mapssetFactory
- factory for temporary setspublic OptimisticMapWrapper(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 void rollbackTransaction()
TransactionalMapWrapper
rollbackTransaction
in class TransactionalMapWrapper
TransactionalMapWrapper.startTransaction()
,
TransactionalMapWrapper.commitTransaction()
public void commitTransaction() throws ConflictException
TransactionalMapWrapper
commitTransaction
in class TransactionalMapWrapper
ConflictException
TransactionalMapWrapper.startTransaction()
,
TransactionalMapWrapper.rollbackTransaction()
public void commitTransaction(boolean force) throws ConflictException
ConflictException
public Object checkForConflicts()
protected void copyChangesToConcurrentTransactions()
Copyright © 2004-2013 The Apache Software Foundation. All Rights Reserved.