public abstract class AbstractCacheTransaction extends Object implements CacheTransaction
CacheTransaction.TransactionCompletedListener
Modifier and Type | Field and Description |
---|---|
protected Set<Object> |
affectedKeys
Holds all the locked keys that were acquired by the transaction allover the cluster.
|
protected boolean |
hasLocalOnlyModifications |
protected Equivalence<Object> |
keyEquivalence
Equivalence function to compare keys that are stored in temporary
collections used in the cache transaction to keep track of locked keys,
looked up keys...etc.
|
protected Map<Object,CacheEntry> |
lookedUpEntries |
protected List<WriteCommand> |
modifications |
protected int |
topologyId |
protected GlobalTransaction |
tx |
Constructor and Description |
---|
AbstractCacheTransaction(GlobalTransaction tx,
int topologyId,
Equivalence<Object> keyEquivalence,
long txCreationTime) |
Modifier and Type | Method and Description |
---|---|
void |
addAffectedKey(Object key) |
void |
addAllAffectedKeys(Collection<?> keys) |
void |
addBackupLockForKey(Object key) |
void |
addListener(CacheTransaction.TransactionCompletedListener listener) |
void |
addReadKey(Object key) |
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 |
freezeModifications()
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() |
long |
getCreationTime() |
GlobalTransaction |
getGlobalTransaction()
Returns the transaction identifier.
|
Set<Object> |
getLockedKeys() |
Map<Object,CacheEntry> |
getLookedUpEntries() |
EntryVersion |
getLookedUpRemoteVersion(Object key) |
List<WriteCommand> |
getModifications()
Returns the modifications visible within the current transaction.
|
CompletableFuture<Void> |
getReleaseFutureForKey(Object key)
It returns a
CompletableFuture that completes when the lock for the key is released. |
KeyValuePair<Object,CompletableFuture<Void>> |
getReleaseFutureForKeys(Collection<Object> keys)
Same as
CacheTransaction.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.
|
protected void |
internalSetStateTransferFlag(Flag stateTransferFlag) |
boolean |
isFromStateTransfer() |
boolean |
isMarkedForRollback() |
boolean |
keyRead(Object key) |
CacheEntry |
lookupEntry(Object key) |
void |
markForRollback(boolean markForRollback) |
void |
notifyOnTransactionFinished() |
boolean |
ownsLock(Object key) |
void |
putLookedUpRemoteVersion(Object key,
EntryVersion version) |
void |
registerLockedKey(Object key) |
void |
removeLookedUpEntry(Object key) |
void |
replaceVersionRead(Object key,
EntryVersion version)
Sets the version read fr this key, replacing the old version if it exists, i.e each invocation updates the version
of the key.
|
void |
setModifications(List<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 returns
true if the transaction is complete or false otherwise. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
putLookedUpEntries, putLookedUpEntry
protected final GlobalTransaction tx
protected volatile boolean hasLocalOnlyModifications
protected volatile List<WriteCommand> modifications
protected Map<Object,CacheEntry> lookedUpEntries
protected Set<Object> affectedKeys
protected final int topologyId
protected final Equivalence<Object> keyEquivalence
public AbstractCacheTransaction(GlobalTransaction tx, int topologyId, Equivalence<Object> keyEquivalence, long txCreationTime)
public final boolean isMarkedForRollback()
isMarkedForRollback
in interface CacheTransaction
public void markForRollback(boolean markForRollback)
markForRollback
in interface CacheTransaction
public GlobalTransaction getGlobalTransaction()
CacheTransaction
getGlobalTransaction
in interface CacheTransaction
public final List<WriteCommand> getModifications()
CacheTransaction
getModifications
in interface CacheTransaction
public final List<WriteCommand> getAllModifications()
CacheTransaction
getAllModifications
in interface CacheTransaction
public final void setModifications(List<WriteCommand> modifications)
public final boolean hasModification(Class<?> modificationClass)
CacheTransaction
hasModification
in interface CacheTransaction
modificationClass
- the modification type to look forpublic void freezeModifications()
CacheTransaction
freezeModifications
in interface CacheTransaction
public Map<Object,CacheEntry> getLookedUpEntries()
getLookedUpEntries
in interface CacheTransaction
public CacheEntry lookupEntry(Object key)
lookupEntry
in interface CacheTransaction
public void removeLookedUpEntry(Object key)
removeLookedUpEntry
in interface CacheTransaction
public void clearLookedUpEntries()
clearLookedUpEntries
in interface CacheTransaction
public boolean ownsLock(Object key)
ownsLock
in interface CacheTransaction
public void notifyOnTransactionFinished()
notifyOnTransactionFinished
in interface CacheTransaction
AbstractTxLockingInterceptor.checkPendingAndLockKey(InvocationContext, Object, long)
public final boolean waitForLockRelease(long lockAcquisitionTimeout) throws InterruptedException
CacheTransaction
true
if the transaction is complete or false
otherwise.
If the key is not locked or if the transaction is already completed it returns true
immediately.
This method is subject to spurious returns in a way similar to Object.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.waitForLockRelease
in interface CacheTransaction
InterruptedException
AbstractTxLockingInterceptor.checkPendingAndLockKey(InvocationContext, Object, long)
public int getTopologyId()
getTopologyId
in interface CacheTransaction
public void addBackupLockForKey(Object key)
addBackupLockForKey
in interface CacheTransaction
public void registerLockedKey(Object key)
public Set<Object> getLockedKeys()
getLockedKeys
in interface CacheTransaction
public Set<Object> getBackupLockedKeys()
getBackupLockedKeys
in interface CacheTransaction
public void clearLockedKeys()
clearLockedKeys
in interface CacheTransaction
public boolean containsLockOrBackupLock(Object key)
containsLockOrBackupLock
in interface CacheTransaction
public Object findAnyLockedOrBackupLocked(Collection<Object> keys)
findAnyLockedOrBackupLocked
in interface CacheTransaction
public boolean areLocksReleased()
areLocksReleased
in interface CacheTransaction
public void addAffectedKey(Object key)
public void addAllAffectedKeys(Collection<?> keys)
public EntryVersionsMap getUpdatedEntryVersions()
getUpdatedEntryVersions
in interface CacheTransaction
public void setUpdatedEntryVersions(EntryVersionsMap updatedEntryVersions)
setUpdatedEntryVersions
in interface CacheTransaction
public EntryVersion getLookedUpRemoteVersion(Object key)
getLookedUpRemoteVersion
in interface CacheTransaction
public void putLookedUpRemoteVersion(Object key, EntryVersion version)
putLookedUpRemoteVersion
in interface CacheTransaction
public void addReadKey(Object key)
addReadKey
in interface CacheTransaction
public boolean keyRead(Object key)
keyRead
in interface CacheTransaction
public void addVersionRead(Object key, EntryVersion version)
CacheTransaction
addVersionRead
in interface CacheTransaction
public void replaceVersionRead(Object key, EntryVersion version)
CacheTransaction
replaceVersionRead
in interface CacheTransaction
public EntryVersionsMap getVersionsRead()
CacheTransaction
getVersionsRead
in interface CacheTransaction
public final boolean isFromStateTransfer()
public final Flag getStateTransferFlag()
public abstract void setStateTransferFlag(Flag stateTransferFlag)
protected final void internalSetStateTransferFlag(Flag stateTransferFlag)
public long getCreationTime()
getCreationTime
in interface CacheTransaction
public final void addListener(CacheTransaction.TransactionCompletedListener listener)
addListener
in interface CacheTransaction
public CompletableFuture<Void> getReleaseFutureForKey(Object key)
CacheTransaction
CompletableFuture
that completes when the lock for the key
is released.
If the key
is not locked by this transaction, it returns null
.getReleaseFutureForKey
in interface CacheTransaction
key
- the key.CompletableFuture
or null
if the key is not locked by this transaction.public KeyValuePair<Object,CompletableFuture<Void>> getReleaseFutureForKeys(Collection<Object> keys)
CacheTransaction
CacheTransaction.getReleaseFutureForKey(Object)
but it returns a pair with the key and the future.getReleaseFutureForKeys
in interface CacheTransaction
public void cleanupBackupLocks()
CacheTransaction
cleanupBackupLocks
in interface CacheTransaction
Copyright © 2017 JBoss, a division of Red Hat. All rights reserved.