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>
affectedKeys
Holds all the locked keys that were acquired by the transaction allover the cluster.protected Map<Object,CacheEntry>
lookedUpEntries
protected List<org.infinispan.commands.write.WriteCommand>
modifications
protected int
topologyId
protected GlobalTransaction
tx
-
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 void
addAffectedKey(Object key)
void
addAllAffectedKeys(Collection<?> keys)
void
addBackupLockForKey(Object key)
void
addListener(CacheTransaction.TransactionCompletedListener listener)
void
addVersionRead(Object key, EntryVersion version)
Sets the version read for this key.boolean
areLocksReleased()
void
cleanupBackupLocks()
It cleans up the backup locks for this transaction.void
clearLockedKeys()
void
clearLookedUpEntries()
boolean
containsLockOrBackupLock(Object key)
Object
findAnyLockedOrBackupLocked(Collection<Object> keys)
void
forEachBackupLock(Consumer<Object> consumer)
Invokes theConsumer
with each backup lock.void
freezeModifications()
Prevent new modifications after prepare or commit started.Set<Object>
getAffectedKeys()
List<org.infinispan.commands.write.WriteCommand>
getAllModifications()
Returns all the modifications visible within the current transaction, including those using Flag#CACHE_MODE_LOCAL.Set<Object>
getBackupLockedKeys()
testing purpose only!long
getCreationTime()
GlobalTransaction
getGlobalTransaction()
Returns the transaction identifier.Set<Object>
getLockedKeys()
Map<Object,CacheEntry>
getLookedUpEntries()
List<org.infinispan.commands.write.WriteCommand>
getModifications()
Returns the modifications visible within the current transaction.CompletableFuture<Void>
getReleaseFutureForKey(Object key)
It returns aCompletableFuture
that completes when the lock for thekey
is released.Map<Object,CompletableFuture<Void>>
getReleaseFutureForKeys(Collection<Object> keys)
Same asCacheTransaction.getReleaseFutureForKey(Object)
but it returns a pair with the key and the future.Flag
getStateTransferFlag()
int
getTopologyId()
EntryVersionsMap
getUpdatedEntryVersions()
EntryVersionsMap
getVersionsRead()
Note: used in Repeatable Read + Write Skew + Clustering + Versioning.boolean
hasModification(Class<?> modificationClass)
Checks if a modification of the given class (or subclass) is present in this transaction.boolean
isFromStateTransfer()
boolean
isMarkedForRollback()
CacheEntry
lookupEntry(Object key)
void
markForRollback(boolean markForRollback)
void
notifyOnTransactionFinished()
boolean
ownsLock(Object key)
void
registerLockedKey(Object key)
void
removeBackupLock(Object key)
It cleans up the backup forkey
.void
removeBackupLocks(Collection<?> keys)
It cleans up the backup lock for thekeys
.void
removeLookedUpEntry(Object key)
void
setModifications(List<org.infinispan.commands.write.WriteCommand> modifications)
abstract void
setStateTransferFlag(Flag stateTransferFlag)
void
setUpdatedEntryVersions(EntryVersionsMap updatedEntryVersions)
boolean
waitForLockRelease(long lockAcquisitionTimeout)
Checks if this transaction holds a lock on the given key and then waits until the transaction completes or until the timeout expires and returnstrue
if the transaction is complete orfalse
otherwise.-
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
addReadKey, getLookedUpRemoteVersion, keyRead, putLookedUpEntries, putLookedUpEntry, putLookedUpRemoteVersion, replaceVersionRead
-
-
-
-
Field Detail
-
tx
protected final GlobalTransaction tx
-
modifications
protected volatile List<org.infinispan.commands.write.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:
isMarkedForRollback
in interfaceCacheTransaction
-
markForRollback
public void markForRollback(boolean markForRollback)
- Specified by:
markForRollback
in interfaceCacheTransaction
-
getGlobalTransaction
public GlobalTransaction getGlobalTransaction()
Description copied from interface:CacheTransaction
Returns the transaction identifier.- Specified by:
getGlobalTransaction
in interfaceCacheTransaction
-
getModifications
public final List<org.infinispan.commands.write.WriteCommand> getModifications()
Description copied from interface:CacheTransaction
Returns the modifications visible within the current transaction. Any modifications using Flag#CACHE_MODE_LOCAL are excluded. The returned list is never null.- Specified by:
getModifications
in interfaceCacheTransaction
-
getAllModifications
public final List<org.infinispan.commands.write.WriteCommand> getAllModifications()
Description copied from interface:CacheTransaction
Returns all the modifications visible within the current transaction, including those using Flag#CACHE_MODE_LOCAL. The returned list is never null.- Specified by:
getAllModifications
in interfaceCacheTransaction
-
setModifications
public final void setModifications(List<org.infinispan.commands.write.WriteCommand> modifications)
-
hasModification
public final boolean hasModification(Class<?> modificationClass)
Description copied from interface:CacheTransaction
Checks 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:
hasModification
in interfaceCacheTransaction
- Parameters:
modificationClass
- the modification type to look for- Returns:
- true if found, false otherwise
-
freezeModifications
public void freezeModifications()
Description copied from interface:CacheTransaction
Prevent new modifications after prepare or commit started.- Specified by:
freezeModifications
in interfaceCacheTransaction
-
getLookedUpEntries
public Map<Object,CacheEntry> getLookedUpEntries()
- Specified by:
getLookedUpEntries
in interfaceCacheTransaction
-
lookupEntry
public CacheEntry lookupEntry(Object key)
- Specified by:
lookupEntry
in interfaceCacheTransaction
-
removeLookedUpEntry
public void removeLookedUpEntry(Object key)
- Specified by:
removeLookedUpEntry
in interfaceCacheTransaction
-
clearLookedUpEntries
public void clearLookedUpEntries()
- Specified by:
clearLookedUpEntries
in interfaceCacheTransaction
-
ownsLock
public boolean ownsLock(Object key)
- Specified by:
ownsLock
in interfaceCacheTransaction
-
notifyOnTransactionFinished
public void notifyOnTransactionFinished()
- Specified by:
notifyOnTransactionFinished
in interfaceCacheTransaction
- See Also:
AbstractTxLockingInterceptor.checkPendingAndLockKey(InvocationContext, Object, long)
-
waitForLockRelease
public final boolean waitForLockRelease(long lockAcquisitionTimeout) throws InterruptedException
Description copied from interface:CacheTransaction
Checks if this transaction holds a lock on the given key and then waits until the transaction completes or until the timeout expires and returnstrue
if the transaction is complete orfalse
otherwise. If the key is not locked or if the transaction is already completed it returnstrue
immediately. This method is subject to spurious returns in a way similar toObject.wait()
. It can sometimes return before the specified time has elapsed and without guaranteeing that this transaction is complete. The caller is responsible to call the method again if transaction completion was not reached and the time budget was not spent.- Specified by:
waitForLockRelease
in interfaceCacheTransaction
- Throws:
InterruptedException
- See Also:
AbstractTxLockingInterceptor.checkPendingAndLockKey(InvocationContext, Object, long)
-
getTopologyId
public int getTopologyId()
- Specified by:
getTopologyId
in interfaceCacheTransaction
-
addBackupLockForKey
public void addBackupLockForKey(Object key)
- Specified by:
addBackupLockForKey
in interfaceCacheTransaction
-
registerLockedKey
public void registerLockedKey(Object key)
-
getLockedKeys
public Set<Object> getLockedKeys()
- Specified by:
getLockedKeys
in interfaceCacheTransaction
-
getBackupLockedKeys
public Set<Object> getBackupLockedKeys()
Description copied from interface:CacheTransaction
testing purpose only!- Specified by:
getBackupLockedKeys
in interfaceCacheTransaction
-
clearLockedKeys
public void clearLockedKeys()
- Specified by:
clearLockedKeys
in interfaceCacheTransaction
-
containsLockOrBackupLock
public boolean containsLockOrBackupLock(Object key)
- Specified by:
containsLockOrBackupLock
in interfaceCacheTransaction
-
findAnyLockedOrBackupLocked
public Object findAnyLockedOrBackupLocked(Collection<Object> keys)
- Specified by:
findAnyLockedOrBackupLocked
in interfaceCacheTransaction
-
areLocksReleased
public boolean areLocksReleased()
- Specified by:
areLocksReleased
in interfaceCacheTransaction
-
addAffectedKey
public void addAffectedKey(Object key)
-
addAllAffectedKeys
public void addAllAffectedKeys(Collection<?> keys)
-
getUpdatedEntryVersions
public EntryVersionsMap getUpdatedEntryVersions()
- Specified by:
getUpdatedEntryVersions
in interfaceCacheTransaction
-
setUpdatedEntryVersions
public void setUpdatedEntryVersions(EntryVersionsMap updatedEntryVersions)
- Specified by:
setUpdatedEntryVersions
in interfaceCacheTransaction
-
addVersionRead
public void addVersionRead(Object key, EntryVersion version)
Description copied from interface:CacheTransaction
Sets 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:
addVersionRead
in interfaceCacheTransaction
-
getVersionsRead
public EntryVersionsMap getVersionsRead()
Description copied from interface:CacheTransaction
Note: used in Repeatable Read + Write Skew + Clustering + Versioning.- Specified by:
getVersionsRead
in 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:
getCreationTime
in interfaceCacheTransaction
-
addListener
public final void addListener(CacheTransaction.TransactionCompletedListener listener)
- Specified by:
addListener
in interfaceCacheTransaction
-
getReleaseFutureForKey
public CompletableFuture<Void> getReleaseFutureForKey(Object key)
Description copied from interface:CacheTransaction
It returns aCompletableFuture
that completes when the lock for thekey
is released. If thekey
is not locked by this transaction, it returnsnull
.- Specified by:
getReleaseFutureForKey
in interfaceCacheTransaction
- Parameters:
key
- the key.- Returns:
- the
CompletableFuture
ornull
if the key is not locked by this transaction.
-
getReleaseFutureForKeys
public Map<Object,CompletableFuture<Void>> getReleaseFutureForKeys(Collection<Object> keys)
Description copied from interface:CacheTransaction
Same asCacheTransaction.getReleaseFutureForKey(Object)
but it returns a pair with the key and the future.- Specified by:
getReleaseFutureForKeys
in interfaceCacheTransaction
-
cleanupBackupLocks
public void cleanupBackupLocks()
Description copied from interface:CacheTransaction
It cleans up the backup locks for this transaction.- Specified by:
cleanupBackupLocks
in interfaceCacheTransaction
-
removeBackupLocks
public void removeBackupLocks(Collection<?> keys)
Description copied from interface:CacheTransaction
It cleans up the backup lock for thekeys
.- Specified by:
removeBackupLocks
in interfaceCacheTransaction
- Parameters:
keys
- The keys to clean up the backup lock.
-
removeBackupLock
public void removeBackupLock(Object key)
Description copied from interface:CacheTransaction
It cleans up the backup forkey
.- Specified by:
removeBackupLock
in interfaceCacheTransaction
- Parameters:
key
- The key to clean up the backup lock.
-
forEachBackupLock
public void forEachBackupLock(Consumer<Object> consumer)
Description copied from interface:CacheTransaction
Invokes theConsumer
with each backup lock.- Specified by:
forEachBackupLock
in interfaceCacheTransaction
- Parameters:
consumer
- The backup lockConsumer
-
-