K - key typeV - value type.public abstract class TransactionalMapParticipant<K,V> extends Object implements TransactionalMap<K,V>, TransactionParticipant
TransactionalMap.
This class provides the basic functionality required by transactional map participants and provides methods for defining operations specific to individual isolation levels.
| Modifier and Type | Field and Description |
|---|---|
protected ConsistentMap<K,V> |
backingMap |
protected Set<K> |
deleteSet |
protected Version |
lock |
protected Transaction<MapUpdate<K,V>> |
transaction |
protected Map<K,V> |
writeCache |
| Modifier | Constructor and Description |
|---|---|
protected |
TransactionalMapParticipant(ConsistentMap<K,V> backingMap,
Transaction<MapUpdate<K,V>> transaction) |
| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<Void> |
commit()
Attempts to execute the commit phase for previously prepared transaction.
|
boolean |
containsKey(K key)
Returns true if this map contains a mapping for the specified key.
|
V |
get(K key)
Returns the value to which the specified key is mapped, or null if this
map contains no mapping for the key.
|
protected List<MapUpdate<K,V>> |
log(Version lockVersion)
Returns a list of updates performed within this map partition.
|
CompletableFuture<Boolean> |
prepare()
Executes the prepare phase.
|
CompletableFuture<Boolean> |
prepareAndCommit()
Executes the prepare and commit phases atomically.
|
V |
put(K key,
V value)
Associates the specified value with the specified key in this map (optional operation).
|
V |
putIfAbsent(K key,
V value)
If the specified key is not already associated with a value
associates it with the given value and returns null, else returns the current value.
|
protected abstract V |
read(K key)
Executes a get operation based on the transaction isolation level.
|
protected abstract Stream<MapUpdate<K,V>> |
records(Version lockVersion)
Returns a stream of updates performed within this map partition.
|
V |
remove(K key)
Removes the mapping for a key from this map if it is present (optional operation).
|
boolean |
remove(K key,
V value)
Removes the entry for the specified key only if it is currently
mapped to the specified value.
|
boolean |
replace(K key,
V oldValue,
V newValue)
Replaces the entry for the specified key only if currently mapped
to the specified value.
|
CompletableFuture<Void> |
rollback()
Attempts to execute the rollback phase for previously prepared transaction.
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waithasPendingUpdatesprotected final ConsistentMap<K,V> backingMap
protected final Transaction<MapUpdate<K,V>> transaction
protected volatile Version lock
protected TransactionalMapParticipant(ConsistentMap<K,V> backingMap, Transaction<MapUpdate<K,V>> transaction)
public V get(K key)
TransactionalMapget in interface TransactionalMap<K,V>key - the key whose associated value is to be returnedprotected abstract V read(K key)
key - the key to look uppublic boolean containsKey(K key)
TransactionalMapcontainsKey in interface TransactionalMap<K,V>key - key whose presence in this map to be testedpublic V put(K key, V value)
TransactionalMapput in interface TransactionalMap<K,V>key - key with which the specified value is to be associatedvalue - value to be associated with the specified keypublic V remove(K key)
TransactionalMapremove in interface TransactionalMap<K,V>key - key whose value is to be removed from the mappublic boolean remove(K key, V value)
TransactionalMapremove in interface TransactionalMap<K,V>key - key with which the specified value is associatedvalue - value expected to be associated with the specified keypublic boolean replace(K key, V oldValue, V newValue)
TransactionalMapreplace in interface TransactionalMap<K,V>key - key with which the specified value is associatedoldValue - value expected to be associated with the specified keynewValue - value to be associated with the specified keypublic V putIfAbsent(K key, V value)
TransactionalMapputIfAbsent in interface TransactionalMap<K,V>key - key with which the specified value is to be associatedvalue - value to be associated with the specified keypublic CompletableFuture<Boolean> prepare()
TransactionParticipantprepare in interface TransactionParticipanttrue is successful; false otherwisepublic CompletableFuture<Void> commit()
TransactionParticipantcommit in interface TransactionParticipantpublic CompletableFuture<Boolean> prepareAndCommit()
TransactionParticipantprepareAndCommit in interface TransactionParticipanttrue is successful; false otherwisepublic CompletableFuture<Void> rollback()
TransactionParticipantrollback in interface TransactionParticipantprotected List<MapUpdate<K,V>> log(Version lockVersion)
lockVersion - the global transaction lock versionprotected abstract Stream<MapUpdate<K,V>> records(Version lockVersion)
lockVersion - the global transaction lock version