Package org.infinispan.transaction.impl
Class AbstractCacheTransaction
- java.lang.Object
-
- org.infinispan.transaction.impl.AbstractCacheTransaction
-
- All Implemented Interfaces:
CacheTransaction
- Direct Known Subclasses:
LocalTransaction,RemoteTransaction
public abstract class AbstractCacheTransaction extends Object implements CacheTransaction
Base class for local and remote transaction. Impl note: The aggregated modification list and lookedUpEntries are not instantiated here but in subclasses. This is done in order to take advantage of the fact that, for remote transactions we already know the size of the modifications list at creation time.- Since:
- 4.2
- Author:
- Mircea.Markus@jboss.com, Galder ZamarreƱo
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.infinispan.transaction.xa.CacheTransaction
CacheTransaction.TransactionCompletedListener
-
-
Field Summary
Fields Modifier and Type Field Description protected Set<Object>affectedKeysHolds all the locked keys that were acquired by the transaction allover the cluster.protected Map<Object,CacheEntry>lookedUpEntriesprotected List<WriteCommand>modificationsprotected inttopologyIdprotected GlobalTransactiontx
-
Constructor Summary
Constructors Constructor Description AbstractCacheTransaction(GlobalTransaction tx, int topologyId, long txCreationTime)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddAffectedKey(Object key)voidaddAllAffectedKeys(Collection<?> keys)voidaddBackupLockForKey(Object key)voidaddListener(CacheTransaction.TransactionCompletedListener listener)voidaddVersionRead(Object key, EntryVersion version)Sets the version read for this key.voidcleanupBackupLocks()It cleans up the backup locks for this transaction.voidclearLockedKeys()voidclearLookedUpEntries()voidforEachBackupLock(Consumer<Object> consumer)Invokes theConsumerwith each backup lock.voidforEachLock(Consumer<Object> consumer)Invokes theConsumerwith each lock.voidfreezeModifications()Prevent new modifications after prepare or commit started.Set<Object>getAffectedKeys()List<WriteCommand>getAllModifications()Returns all the modifications visible within the current transaction, including those using Flag#CACHE_MODE_LOCAL.Set<Object>getBackupLockedKeys()longgetCreationTime()GlobalTransactiongetGlobalTransaction()Returns the transaction identifier.Set<Object>getLockedKeys()Map<Object,CacheEntry>getLookedUpEntries()List<WriteCommand>getModifications()Returns the modifications visible within the current transaction.CompletableFuture<Void>getReleaseFutureForKey(Object key)It returns aCompletableFuturethat completes when the lock for thekeyis released.Map<Object,CompletableFuture<Void>>getReleaseFutureForKeys(Collection<Object> keys)Same asCacheTransaction.getReleaseFutureForKey(Object)but it returns a pair with the key and the future.FlaggetStateTransferFlag()intgetTopologyId()Map<Object,IncrementableEntryVersion>getUpdatedEntryVersions()Map<Object,IncrementableEntryVersion>getVersionsRead()Note: used in Repeatable Read + Write Skew + Clustering + Versioning.booleanhasModification(Class<?> modificationClass)Checks if a modification of the given class (or subclass) is present in this transaction.booleanisFromStateTransfer()booleanisMarkedForRollback()CacheEntrylookupEntry(Object key)voidmarkForRollback(boolean markForRollback)voidnotifyOnTransactionFinished()booleanownsLock(Object key)voidregisterLockedKey(Object key)voidremoveBackupLock(Object key)It cleans up the backup forkey.voidremoveBackupLocks(Collection<?> keys)It cleans up the backup lock for thekeys.voidremoveLookedUpEntry(Object key)voidsetModifications(List<WriteCommand> modifications)abstract voidsetStateTransferFlag(Flag stateTransferFlag)voidsetUpdatedEntryVersions(Map<Object,IncrementableEntryVersion> updatedEntryVersions)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.infinispan.transaction.xa.CacheTransaction
putLookedUpEntries, putLookedUpEntry
-
-
-
-
Field Detail
-
tx
protected final GlobalTransaction tx
-
modifications
protected volatile List<WriteCommand> modifications
-
lookedUpEntries
protected Map<Object,CacheEntry> lookedUpEntries
-
affectedKeys
protected Set<Object> affectedKeys
Holds all the locked keys that were acquired by the transaction allover the cluster.
-
topologyId
protected final int topologyId
-
-
Constructor Detail
-
AbstractCacheTransaction
public AbstractCacheTransaction(GlobalTransaction tx, int topologyId, long txCreationTime)
-
-
Method Detail
-
isMarkedForRollback
public final boolean isMarkedForRollback()
- Specified by:
isMarkedForRollbackin interfaceCacheTransaction
-
markForRollback
public void markForRollback(boolean markForRollback)
- Specified by:
markForRollbackin interfaceCacheTransaction
-
getGlobalTransaction
public GlobalTransaction getGlobalTransaction()
Description copied from interface:CacheTransactionReturns the transaction identifier.- Specified by:
getGlobalTransactionin interfaceCacheTransaction
-
getModifications
public final List<WriteCommand> getModifications()
Description copied from interface:CacheTransactionReturns the modifications visible within the current transaction. Any modifications using Flag#CACHE_MODE_LOCAL are excluded. The returned list is never null.- Specified by:
getModificationsin interfaceCacheTransaction
-
getAllModifications
public final List<WriteCommand> getAllModifications()
Description copied from interface:CacheTransactionReturns all the modifications visible within the current transaction, including those using Flag#CACHE_MODE_LOCAL. The returned list is never null.- Specified by:
getAllModificationsin interfaceCacheTransaction
-
setModifications
public final void setModifications(List<WriteCommand> modifications)
-
hasModification
public final boolean hasModification(Class<?> modificationClass)
Description copied from interface:CacheTransactionChecks if a modification of the given class (or subclass) is present in this transaction. Any modifications using Flag#CACHE_MODE_LOCAL are ignored.- Specified by:
hasModificationin interfaceCacheTransaction- Parameters:
modificationClass- the modification type to look for- Returns:
- true if found, false otherwise
-
freezeModifications
public void freezeModifications()
Description copied from interface:CacheTransactionPrevent new modifications after prepare or commit started.- Specified by:
freezeModificationsin interfaceCacheTransaction
-
getLookedUpEntries
public Map<Object,CacheEntry> getLookedUpEntries()
- Specified by:
getLookedUpEntriesin interfaceCacheTransaction
-
lookupEntry
public CacheEntry lookupEntry(Object key)
- Specified by:
lookupEntryin interfaceCacheTransaction
-
removeLookedUpEntry
public void removeLookedUpEntry(Object key)
- Specified by:
removeLookedUpEntryin interfaceCacheTransaction
-
clearLookedUpEntries
public void clearLookedUpEntries()
- Specified by:
clearLookedUpEntriesin interfaceCacheTransaction
-
ownsLock
public boolean ownsLock(Object key)
- Specified by:
ownsLockin interfaceCacheTransaction
-
notifyOnTransactionFinished
public void notifyOnTransactionFinished()
- Specified by:
notifyOnTransactionFinishedin interfaceCacheTransaction- See Also:
AbstractTxLockingInterceptor.checkPendingAndLockKey(TxInvocationContext, VisitableCommand, Object, long)
-
getTopologyId
public int getTopologyId()
- Specified by:
getTopologyIdin interfaceCacheTransaction
-
addBackupLockForKey
public void addBackupLockForKey(Object key)
- Specified by:
addBackupLockForKeyin interfaceCacheTransaction
-
registerLockedKey
public void registerLockedKey(Object key)
-
getLockedKeys
public Set<Object> getLockedKeys()
- Specified by:
getLockedKeysin interfaceCacheTransaction
-
clearLockedKeys
public void clearLockedKeys()
- Specified by:
clearLockedKeysin interfaceCacheTransaction
-
addAffectedKey
public void addAffectedKey(Object key)
-
addAllAffectedKeys
public void addAllAffectedKeys(Collection<?> keys)
-
getUpdatedEntryVersions
public Map<Object,IncrementableEntryVersion> getUpdatedEntryVersions()
- Specified by:
getUpdatedEntryVersionsin interfaceCacheTransaction
-
setUpdatedEntryVersions
public void setUpdatedEntryVersions(Map<Object,IncrementableEntryVersion> updatedEntryVersions)
- Specified by:
setUpdatedEntryVersionsin interfaceCacheTransaction
-
addVersionRead
public void addVersionRead(Object key, EntryVersion version)
Description copied from interface:CacheTransactionSets the version read for this key. The version is only set at the first time, i.e. multiple invocation of this method will not change the state. Note: used in Repeatable Read + Write Skew + Clustering + Versioning.- Specified by:
addVersionReadin interfaceCacheTransaction
-
getVersionsRead
public Map<Object,IncrementableEntryVersion> getVersionsRead()
Description copied from interface:CacheTransactionNote: used in Repeatable Read + Write Skew + Clustering + Versioning.- Specified by:
getVersionsReadin interfaceCacheTransaction- Returns:
- a non-null map between key and version. The map represents the version read for that key. If no version exists, the key has not been read.
-
isFromStateTransfer
public final boolean isFromStateTransfer()
-
getStateTransferFlag
public final Flag getStateTransferFlag()
-
setStateTransferFlag
public abstract void setStateTransferFlag(Flag stateTransferFlag)
-
getCreationTime
public long getCreationTime()
- Specified by:
getCreationTimein interfaceCacheTransaction
-
addListener
public final void addListener(CacheTransaction.TransactionCompletedListener listener)
- Specified by:
addListenerin interfaceCacheTransaction
-
getReleaseFutureForKey
public CompletableFuture<Void> getReleaseFutureForKey(Object key)
Description copied from interface:CacheTransactionIt returns aCompletableFuturethat completes when the lock for thekeyis released. If thekeyis not locked by this transaction, it returnsnull.- Specified by:
getReleaseFutureForKeyin interfaceCacheTransaction- Parameters:
key- the key.- Returns:
- the
CompletableFutureornullif the key is not locked by this transaction.
-
getReleaseFutureForKeys
public Map<Object,CompletableFuture<Void>> getReleaseFutureForKeys(Collection<Object> keys)
Description copied from interface:CacheTransactionSame asCacheTransaction.getReleaseFutureForKey(Object)but it returns a pair with the key and the future.- Specified by:
getReleaseFutureForKeysin interfaceCacheTransaction
-
cleanupBackupLocks
public void cleanupBackupLocks()
Description copied from interface:CacheTransactionIt cleans up the backup locks for this transaction.- Specified by:
cleanupBackupLocksin interfaceCacheTransaction
-
removeBackupLocks
public void removeBackupLocks(Collection<?> keys)
Description copied from interface:CacheTransactionIt cleans up the backup lock for thekeys.- Specified by:
removeBackupLocksin interfaceCacheTransaction- Parameters:
keys- The keys to clean up the backup lock.
-
removeBackupLock
public void removeBackupLock(Object key)
Description copied from interface:CacheTransactionIt cleans up the backup forkey.- Specified by:
removeBackupLockin interfaceCacheTransaction- Parameters:
key- The key to clean up the backup lock.
-
forEachLock
public void forEachLock(Consumer<Object> consumer)
Description copied from interface:CacheTransactionInvokes theConsumerwith each lock.- Specified by:
forEachLockin interfaceCacheTransaction- Parameters:
consumer- The backup lockConsumer
-
forEachBackupLock
public void forEachBackupLock(Consumer<Object> consumer)
Description copied from interface:CacheTransactionInvokes theConsumerwith each backup lock.- Specified by:
forEachBackupLockin interfaceCacheTransaction- Parameters:
consumer- The backup lockConsumer
-
-