Infinispan Distribution 5.2.6.Final-redhat-2

org.infinispan.transaction
Class AbstractCacheTransaction

java.lang.Object
  extended by org.infinispan.transaction.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

Field Summary
protected  Set<Object> affectedKeys
          Holds all the locked keys that were acquired by the transaction allover the cluster.
protected  Set<Object> backupKeyLocks
          Holds all the locks for which the local node is a secondary data owner.
protected  boolean hasLocalOnlyModifications
           
protected  Set<Object> lockedKeys
          Holds all the keys that were actually locked on the local node.
protected  HashMap<Object,CacheEntry> lookedUpEntries
           
protected  List<WriteCommand> modifications
           
protected  int topologyId
           
protected  GlobalTransaction tx
           
 
Constructor Summary
AbstractCacheTransaction(GlobalTransaction tx, int topologyId)
           
 
Method Summary
 void addAffectedKey(Object key)
           
 void addAllAffectedKeys(Collection<Object> keys)
           
 void addBackupLockForKey(Object key)
           
 void addReadKey(Object key)
           
 void clearLockedKeys()
           
 void clearLookedUpEntries()
           
 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()
           
 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.
 int getTopologyId()
           
 EntryVersionsMap getUpdatedEntryVersions()
           
 boolean hasModification(Class<?> modificationClass)
          Checks if a modification of the given class (or subclass) is present in this transaction.
 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 setModifications(List<WriteCommand> modifications)
           
 void setUpdatedEntryVersions(EntryVersionsMap updatedEntryVersions)
           
 boolean waitForLockRelease(Object key, 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.
 
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

hasLocalOnlyModifications

protected volatile boolean hasLocalOnlyModifications

modifications

protected volatile List<WriteCommand> modifications

lookedUpEntries

protected HashMap<Object,CacheEntry> lookedUpEntries

affectedKeys

protected Set<Object> affectedKeys
Holds all the locked keys that were acquired by the transaction allover the cluster.


lockedKeys

protected volatile Set<Object> lockedKeys
Holds all the keys that were actually locked on the local node.


backupKeyLocks

protected volatile Set<Object> backupKeyLocks
Holds all the locks for which the local node is a secondary data owner.


topologyId

protected final int topologyId
Constructor Detail

AbstractCacheTransaction

public AbstractCacheTransaction(GlobalTransaction tx,
                                int topologyId)
Method Detail

isMarkedForRollback

public final boolean isMarkedForRollback()
Specified by:
isMarkedForRollback in interface CacheTransaction

markForRollback

public void markForRollback(boolean markForRollback)
Specified by:
markForRollback in interface CacheTransaction

getGlobalTransaction

public GlobalTransaction getGlobalTransaction()
Description copied from interface: CacheTransaction
Returns the transaction identifier.

Specified by:
getGlobalTransaction in interface CacheTransaction

getModifications

public final List<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 interface CacheTransaction

getAllModifications

public final List<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 interface CacheTransaction

setModifications

public final void setModifications(List<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 interface CacheTransaction
Parameters:
modificationClass - the modification type to look for
Returns:
true if found, false otherwise

getLookedUpEntries

public Map<Object,CacheEntry> getLookedUpEntries()
Specified by:
getLookedUpEntries in interface CacheTransaction

lookupEntry

public CacheEntry lookupEntry(Object key)
Specified by:
lookupEntry in interface CacheTransaction

removeLookedUpEntry

public void removeLookedUpEntry(Object key)
Specified by:
removeLookedUpEntry in interface CacheTransaction

clearLookedUpEntries

public void clearLookedUpEntries()
Specified by:
clearLookedUpEntries in interface CacheTransaction

ownsLock

public boolean ownsLock(Object key)
Specified by:
ownsLock in interface CacheTransaction

notifyOnTransactionFinished

public void notifyOnTransactionFinished()
Specified by:
notifyOnTransactionFinished in interface CacheTransaction
See Also:
org.infinispan.interceptors.locking.AbstractTxLockingInterceptor#lockKeyAndCheckOwnership(org.infinispan.context.InvocationContext, Object)

waitForLockRelease

public boolean waitForLockRelease(Object key,
                                  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 returns 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.

Specified by:
waitForLockRelease in interface CacheTransaction
Throws:
InterruptedException
See Also:
org.infinispan.interceptors.locking.AbstractTxLockingInterceptor#lockKeyAndCheckOwnership(org.infinispan.context.InvocationContext, Object)

getTopologyId

public int getTopologyId()
Specified by:
getTopologyId in interface CacheTransaction

addBackupLockForKey

public void addBackupLockForKey(Object key)
Specified by:
addBackupLockForKey in interface CacheTransaction

registerLockedKey

public void registerLockedKey(Object key)

getLockedKeys

public Set<Object> getLockedKeys()
Specified by:
getLockedKeys in interface CacheTransaction

getBackupLockedKeys

public Set<Object> getBackupLockedKeys()
Specified by:
getBackupLockedKeys in interface CacheTransaction

clearLockedKeys

public void clearLockedKeys()
Specified by:
clearLockedKeys in interface CacheTransaction

getAffectedKeys

public Set<Object> getAffectedKeys()

addAffectedKey

public void addAffectedKey(Object key)

addAllAffectedKeys

public void addAllAffectedKeys(Collection<Object> keys)

getUpdatedEntryVersions

public EntryVersionsMap getUpdatedEntryVersions()
Specified by:
getUpdatedEntryVersions in interface CacheTransaction

setUpdatedEntryVersions

public void setUpdatedEntryVersions(EntryVersionsMap updatedEntryVersions)
Specified by:
setUpdatedEntryVersions in interface CacheTransaction

getLookedUpRemoteVersion

public EntryVersion getLookedUpRemoteVersion(Object key)
Specified by:
getLookedUpRemoteVersion in interface CacheTransaction

putLookedUpRemoteVersion

public void putLookedUpRemoteVersion(Object key,
                                     EntryVersion version)
Specified by:
putLookedUpRemoteVersion in interface CacheTransaction

addReadKey

public void addReadKey(Object key)
Specified by:
addReadKey in interface CacheTransaction

keyRead

public boolean keyRead(Object key)
Specified by:
keyRead in interface CacheTransaction

Infinispan Distribution 5.2.6.Final-redhat-2

Copyright © 2013 JBoss, a division of Red Hat. All Rights Reserved.