Class SimpleValidator
- All Implemented Interfaces:
TransactionMap.Validator
- Since:
- Coherence 2.3
- Author:
- gg 2003.12.19
-
Nested Class Summary
Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter
-
Field Summary
Modifier and TypeFieldDescriptionprotected Map
The map that holds version objects for enlisted resources. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected Comparable
calculateVersion
(Object oValue) Generate the Comparable version indicator for a given resource value.void
enlist
(TransactionMap mapTx, Object oKey) Enlist the resource with the specified transaction.Retrive the next Validator.Obtain a map that holds the version objects for resources enlisted into a transaction.void
setNextValidator
(TransactionMap.Validator validator) Set the next Validator.void
validate
(TransactionMap mapTx, Set setInsert, Set setUpdate, Set setDelete, Set setRead, Set setPhantom) Validate that the content of the TransactionMap is "fit" to be committed into the base map.protected void
validateInsert
(TransactionMap mapTx, Set setKey) Validate the set of the inserts.protected void
validateValue
(TransactionMap mapTx, Set setKey) Validate the set of the read values.protected void
validateVersion
(TransactionMap mapTx, Set setKey) Validate the set of the updates or deletes.Methods inherited from class com.tangosol.util.Base
azzert, azzert, azzert, azzertFailed, breakLines, breakLines, capitalize, checkNotEmpty, checkNotNull, checkRange, computeSafeWaitTime, decimalValue, dup, dup, ensureBigDecimal, ensureClassLoader, ensureRuntimeException, ensureRuntimeException, equals, equalsDeep, err, err, err, err, err, escape, formatDateTime, getCallerStackFrame, getCommonMonitor, getCommonMonitor, getCommonMonitor, getContextClassLoader, getContextClassLoader, getDeepMessage, getErr, getLastSafeTimeMillis, getLog, getMaxDecDigits, getMaxHexDigits, getOriginalException, getOut, getProcessRandom, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mergeArray, mergeBooleanArray, mergeByteArray, mergeCharArray, mergeDoubleArray, mergeFloatArray, mergeIntArray, mergeLongArray, mod, mod, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, randomize, randomize, randomize, randomize, read, read, read, read, read, read, read, replace, setErr, setLog, setLogEcho, setOut, sleep, toBandwidthString, toBandwidthString, toCharEscape, toCrc, toCrc, toCrc, toCrc, toCrc, toDecString, toDelimitedString, toDelimitedString, toDelimitedString, toDelimitedString, toHex, toHex, toHexDump, toHexEscape, toHexEscape, toHexEscape, toHexEscape, toHexString, toMemorySizeString, toMemorySizeString, toQuotedCharEscape, toQuotedStringEscape, toSqlString, toString, toString, toStringEscape, toUnicodeEscape, trace, trace, trace, trace, trace, trace, trace, trace, trace, truncateString, truncateString, wait
-
Field Details
-
m_mapVersion
The map that holds version objects for enlisted resources.
-
-
Constructor Details
-
SimpleValidator
public SimpleValidator()Default constructor.
-
-
Method Details
-
getVersionMap
Obtain a map that holds the version objects for resources enlisted into a transaction.- Returns:
- the versions map
-
enlist
Enlist the resource with the specified transaction.This method is invoked for all resources that are "used" by the transaction immediately before the resource value is copied into the local map. If the resource value implements the
Versionable
interface, the corresponding version indicator will be placed into the version map; otherwise the value's hashCode will be used.It is this method's responsibility to call a next Validator in the validation chain.
- Specified by:
enlist
in interfaceTransactionMap.Validator
- Parameters:
mapTx
- the TransactionMap to enlist the resource withoKey
- the resource key to be enlisted with the transaction
-
validate
public void validate(TransactionMap mapTx, Set setInsert, Set setUpdate, Set setDelete, Set setRead, Set setPhantom) throws ConcurrentModificationException Validate that the content of the TransactionMap is "fit" to be committed into the base map.This method is invoked during "prepare" phase after all the resources involved in this transaction are successfully locked at the base map. The Validator is expected to retrieve the "old" and "new" values (using
map.get(oKey)
,map.getBaseMap().get(oKey)
) and use the information gathered during "enlist" calls to make the determination whether or not commit should be allowed to proceed.To force a roll back it should throw an exception indicating the reason this transaction cannot be committed. When that happens, the sets are expected to hold just the keys of the "offending" resources.
It is this method's responsibility to call a next Validator in the validation chain (i.e.
getNextValidator().validate(map, setI, setU, setD, setR, setF);
)- Specified by:
validate
in interfaceTransactionMap.Validator
- Parameters:
mapTx
- the TransactionMap that is being preparedsetInsert
- the set of inserted resourcessetUpdate
- the set of updated resourcessetDelete
- the set of deleted resourcessetRead
- the set of read resources. It is always empty for TRANSACTION_GET_COMMITTED isolation level.setPhantom
- the set of phantom resources, that is resources that were added to the base map, but were not known to the transaction. This set can be not empty only for TRANSACTION_GET_SERIALIZED isolation level.- Throws:
ConcurrentModificationException
- if the validator detects an unresolveable conflict between the resources
-
getNextValidator
Retrive the next Validator.- Specified by:
getNextValidator
in interfaceTransactionMap.Validator
- Returns:
- the next Validator
-
setNextValidator
Set the next Validator.- Specified by:
setNextValidator
in interfaceTransactionMap.Validator
- Parameters:
validator
- the Validator to be added
-
validateInsert
Validate the set of the inserts.If the inserts do not exist in the base map (as they should not), remove them from the specified key set, so only keys corresponding to the conflicting inserts are left in the key set.
- Parameters:
mapTx
- the TransactionMapsetKey
- the key set of inserted resources- Throws:
ConcurrentModificationException
- if conflicts are detected
-
validateVersion
Validate the set of the updates or deletes.If the version of an updated or removed resource matches to the version stored off in the version map at the time when the resource was enlisted, remove it from the specified key set, so only keys corresponding to the conflicting updates, removes or reads are left in the key set.
- Parameters:
mapTx
- the TransactionMapsetKey
- the key set of updated or removed resources- Throws:
ConcurrentModificationException
- if conflicts are detected
-
validateValue
Validate the set of the read values.If the values that were read during transaction are equal to the values as they exist in the base map, remove them from the specified key set, so only keys corresponding to the conflicting reads are left in the set.
Note: this can occur only for repeatable or serializable isolation level.
- Parameters:
mapTx
- the TransactionMapsetKey
- the key set of read resources- Throws:
ConcurrentModificationException
- if conflicts are detected
-
calculateVersion
Generate the Comparable version indicator for a given resource value.If the value implements the
Versionable
interface, the corresponding version indicator is returned; otherwise the value's hashCode is used.- Returns:
- a Comparable version indicator
-