org.multiverse.stms.alpha.transactions.update
Class ArrayUpdateAlphaTransaction

java.lang.Object
  extended by org.multiverse.stms.AbstractTransaction<C,S>
      extended by org.multiverse.stms.alpha.transactions.AbstractAlphaTransaction<UpdateConfiguration,org.multiverse.stms.AbstractTransactionSnapshot>
          extended by org.multiverse.stms.alpha.transactions.update.AbstractUpdateAlphaTransaction
              extended by org.multiverse.stms.alpha.transactions.update.ArrayUpdateAlphaTransaction
All Implemented Interfaces:
org.multiverse.api.Transaction, org.multiverse.MultiverseConstants, AlphaTransaction

public final class ArrayUpdateAlphaTransaction
extends AbstractUpdateAlphaTransaction

A AbstractUpdateAlphaTransaction where the tranlocals are stored in an array. An array is faster for very small collection than a MapUpdateAlphaTransaction.

Author:
Peter Veentjer

Field Summary
 
Fields inherited from class org.multiverse.stms.alpha.transactions.update.AbstractUpdateAlphaTransaction
updateTransactionStatus
 
Fields inherited from class org.multiverse.stms.AbstractTransaction
config
 
Fields inherited from interface org.multiverse.MultiverseConstants
___SANITY_CHECKS_ENABLED
 
Constructor Summary
ArrayUpdateAlphaTransaction(UpdateConfiguration config, int size)
           
 
Method Summary
protected  void attach(AlphaTranlocal tranlocal)
          Attaches the tranlocal to this Transaction.
protected  void dodoClear()
           
protected  boolean dodoRegisterRetryLatch(org.multiverse.api.latches.Latch latch, long wakeupVersion)
           
 AlphaTranlocal doOpenForCommutingWrite(AlphaTransactionalObject txObject)
           
protected  AlphaTranlocal doOpenForWrite(AlphaTransactionalObject txObject)
           
protected  void doReleaseWriteLocksForFailure()
          Releases all the locks on the transactional objects of the attached tranlocals that have been acquired.
protected  void doReleaseWriteLocksForSuccess(long writeVersion)
          Releases the locks on the tranlocal objects of the attached tranlocals with the given writeVersion.
protected  AlphaTranlocal findAttached(AlphaTransactionalObject txObject)
          Finds the tranlocal for the given transactional object in the set of attached tranlocals.
protected  boolean hasReadConflict()
          Checks if the reads don't have conflicts.
protected  boolean hasWriteConflict()
          Checks if attached updated-items have a conflict.
protected  boolean isDirty()
          Returns the state of the attached tranlocals.
protected  org.multiverse.api.Listeners[] makeChangesPermanent(long writeVersion)
          Writes the tranlocals that need to be written to their transactional objects.
protected  boolean tryWriteLocks(org.multiverse.api.commitlock.CommitLockFilter commitLockFilter)
          Locks the writeset.
 
Methods inherited from class org.multiverse.stms.alpha.transactions.update.AbstractUpdateAlphaTransaction
doAbortPrepared, doClear, doOpenForConstruction, doOpenForRead, doOpenForWritePreviousCommittedAndAttach, doPrepare, doReleaseWriteLockForSuccess, doReleaseWriteSetLocksForFailure, hasReadConflict, hasWriteConflict, isDirty, makeChangesPermanent, makePermanent
 
Methods inherited from class org.multiverse.stms.alpha.transactions.AbstractAlphaTransaction
doRegisterRetryLatch, load, openForCommutingWrite, openForConstruction, openForRead, openForWrite
 
Methods inherited from class org.multiverse.stms.AbstractTransaction
abort, commit, doAbortActive, doInit, endOr, endOrAndStartElse, getAttempt, getConfiguration, getReadVersion, getRemainingTimeoutNs, getSnapshot, getStatus, init, prepare, registerLifecycleListener, registerRetryLatch, restart, setAttempt, setRemainingTimeoutNs, startOr, storeSnapshot, takeSnapshot
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.multiverse.api.Transaction
abort, commit, getAttempt, getConfiguration, getReadVersion, getRemainingTimeoutNs, getStatus, prepare, registerLifecycleListener, registerRetryLatch, restart, setAttempt, setRemainingTimeoutNs
 

Constructor Detail

ArrayUpdateAlphaTransaction

public ArrayUpdateAlphaTransaction(UpdateConfiguration config,
                                   int size)
Method Detail

dodoClear

protected void dodoClear()
Specified by:
dodoClear in class AbstractUpdateAlphaTransaction

isDirty

protected boolean isDirty()
Description copied from class: AbstractUpdateAlphaTransaction
Returns the state of the attached tranlocals. This information is needed for the transaction to decide what to do (write changes etc). It is important that the implementation should not stop after it finds one element that is dirty, it should check all attached objects. This is because the isDirty flag on each tranlocal needs to be cached for later use.

Specified by:
isDirty in class AbstractUpdateAlphaTransaction
Returns:
the AttachedState.

doOpenForCommutingWrite

public AlphaTranlocal doOpenForCommutingWrite(AlphaTransactionalObject txObject)
Overrides:
doOpenForCommutingWrite in class AbstractUpdateAlphaTransaction

doOpenForWrite

protected AlphaTranlocal doOpenForWrite(AlphaTransactionalObject txObject)
Overrides:
doOpenForWrite in class AbstractUpdateAlphaTransaction

attach

protected void attach(AlphaTranlocal tranlocal)
Description copied from class: AbstractUpdateAlphaTransaction
Attaches the tranlocal to this Transaction. The tranlocal will never be null and this call is only made when no read for the transactional object of the readonly has been made. It is important that an implementation doesn't ignore this call.

Specified by:
attach in class AbstractUpdateAlphaTransaction
Parameters:
tranlocal - the opened AlphaTranlocal to attach.

findAttached

protected AlphaTranlocal findAttached(AlphaTransactionalObject txObject)
Description copied from class: AbstractUpdateAlphaTransaction
Finds the tranlocal for the given transactional object in the set of attached tranlocals.

Specified by:
findAttached in class AbstractUpdateAlphaTransaction
Parameters:
txObject - the transactional object to find the tranlocal for.
Returns:
the found tranlocal. If no tranlocal was found in the set of attached tranlocals, null is returned.

hasWriteConflict

protected boolean hasWriteConflict()
Description copied from class: AbstractUpdateAlphaTransaction
Checks if attached updated-items have a conflict. Call is made after the locks on the updates have been acquired. A conflict means that a new version of the tranlocal (that itself is a update) already is stored in in the transactional object.

Specified by:
hasWriteConflict in class AbstractUpdateAlphaTransaction
Returns:
true if at least 1 attached tranlocal has a conflict.

hasReadConflict

protected boolean hasReadConflict()
Description copied from class: AbstractUpdateAlphaTransaction
Checks if the reads don't have conflicts. The writes are neglected because they will be checked with the hasWriteConflict.

Specified by:
hasReadConflict in class AbstractUpdateAlphaTransaction
Returns:
true if there are conflict, false otherwise.

dodoRegisterRetryLatch

protected boolean dodoRegisterRetryLatch(org.multiverse.api.latches.Latch latch,
                                         long wakeupVersion)
Specified by:
dodoRegisterRetryLatch in class AbstractAlphaTransaction<UpdateConfiguration,org.multiverse.stms.AbstractTransactionSnapshot>

tryWriteLocks

protected boolean tryWriteLocks(org.multiverse.api.commitlock.CommitLockFilter commitLockFilter)
Description copied from class: AbstractUpdateAlphaTransaction
Locks the writeset. If the locks could not be obtained, false is returned.

todo: in the future the dirty check could be added. If something is an update, but not dirty there is no need to lock it under certain conditions (it causes the aba problem).

Specified by:
tryWriteLocks in class AbstractUpdateAlphaTransaction
Returns:
true if the writeset was locked successfully, false otherwise.

doReleaseWriteLocksForFailure

protected void doReleaseWriteLocksForFailure()
Description copied from class: AbstractUpdateAlphaTransaction
Releases all the locks on the transactional objects of the attached tranlocals that have been acquired. This call is made when the commit was not a success (so the writeversion still isn't set).

It is important that this call doesn't fail, because else it could leave transactional objects locked forever.

Specified by:
doReleaseWriteLocksForFailure in class AbstractUpdateAlphaTransaction

doReleaseWriteLocksForSuccess

protected void doReleaseWriteLocksForSuccess(long writeVersion)
Description copied from class: AbstractUpdateAlphaTransaction
Releases the locks on the tranlocal objects of the attached tranlocals with the given writeVersion. This call is made when the commit was a success.

It is important that this call doesn't fail, because else it could leave transactional objects locked forever.

Specified by:
doReleaseWriteLocksForSuccess in class AbstractUpdateAlphaTransaction
Parameters:
writeVersion - the writeVersion of the tranlocals to release.

makeChangesPermanent

protected org.multiverse.api.Listeners[] makeChangesPermanent(long writeVersion)
Description copied from class: AbstractUpdateAlphaTransaction
Writes the tranlocals that need to be written to their transactional objects.

It is important that a store always completes. If it doesn't it could cause partially committed transactions.

Specified by:
makeChangesPermanent in class AbstractUpdateAlphaTransaction
Parameters:
writeVersion - the version of the commit.
Returns:
the array of listeners that need to be notified of the write (array is allowed to be null to prevent object creation).


Copyright © 2008-2010 Multiverse. All Rights Reserved.