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

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
All Implemented Interfaces:
org.multiverse.api.Transaction, org.multiverse.MultiverseConstants, AlphaTransaction
Direct Known Subclasses:
ArrayUpdateAlphaTransaction, MapUpdateAlphaTransaction, MonoUpdateAlphaTransaction

public abstract class AbstractUpdateAlphaTransaction
extends AbstractAlphaTransaction<UpdateConfiguration,org.multiverse.stms.AbstractTransactionSnapshot>

An abstract AlphaTransaction that provides all the pluming logic for update transactions.

Author:
Peter Veentjer.

Field Summary
protected  UpdateTransactionStatus updateTransactionStatus
           
 
Fields inherited from class org.multiverse.stms.AbstractTransaction
config
 
Fields inherited from interface org.multiverse.MultiverseConstants
___SANITY_CHECKS_ENABLED
 
Constructor Summary
AbstractUpdateAlphaTransaction(UpdateConfiguration config)
           
 
Method Summary
protected abstract  void attach(AlphaTranlocal opened)
          Attaches the tranlocal to this Transaction.
protected  void doAbortPrepared()
           
protected  void doClear()
           
protected abstract  void dodoClear()
           
protected  AlphaTranlocal doOpenForCommutingWrite(AlphaTransactionalObject txObject)
           
 AlphaTranlocal doOpenForConstruction(AlphaTransactionalObject txObject)
           
protected  AlphaTranlocal doOpenForRead(AlphaTransactionalObject txObject)
           
protected  AlphaTranlocal doOpenForWrite(AlphaTransactionalObject txObject)
           
protected  AlphaTranlocal doOpenForWritePreviousCommittedAndAttach(AlphaTransactionalObject txObject)
           
protected  void doPrepare()
           
protected  void doReleaseWriteLockForSuccess(AlphaTranlocal tranlocal, long writeVersion)
           
protected abstract  void doReleaseWriteLocksForFailure()
          Releases all the locks on the transactional objects of the attached tranlocals that have been acquired.
protected abstract  void doReleaseWriteLocksForSuccess(long writeVersion)
          Releases the locks on the tranlocal objects of the attached tranlocals with the given writeVersion.
protected  void doReleaseWriteSetLocksForFailure(AlphaTranlocal tranlocal)
           
protected abstract  AlphaTranlocal findAttached(AlphaTransactionalObject txObject)
          Finds the tranlocal for the given transactional object in the set of attached tranlocals.
protected abstract  boolean hasReadConflict()
          Checks if the reads don't have conflicts.
protected  boolean hasReadConflict(AlphaTranlocal attached)
           
protected abstract  boolean hasWriteConflict()
          Checks if attached updated-items have a conflict.
protected  boolean hasWriteConflict(AlphaTranlocal tranlocal)
           
protected abstract  boolean isDirty()
          Returns the state of the attached tranlocals.
protected  boolean isDirty(AlphaTranlocal attached)
           
protected  void makeChangesPermanent()
           
protected abstract  org.multiverse.api.Listeners[] makeChangesPermanent(long writeVersion)
          Writes the tranlocals that need to be written to their transactional objects.
protected  org.multiverse.api.Listeners makePermanent(AlphaTranlocal tranlocal, long writeVersion)
           
protected abstract  boolean tryWriteLocks(org.multiverse.api.commitlock.CommitLockFilter commitLockFilter)
          Locks the writeset.
 
Methods inherited from class org.multiverse.stms.alpha.transactions.AbstractAlphaTransaction
dodoRegisterRetryLatch, 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
 

Field Detail

updateTransactionStatus

protected UpdateTransactionStatus updateTransactionStatus
Constructor Detail

AbstractUpdateAlphaTransaction

public AbstractUpdateAlphaTransaction(UpdateConfiguration config)
Method Detail

doClear

protected final void doClear()
Overrides:
doClear in class org.multiverse.stms.AbstractTransaction<UpdateConfiguration,org.multiverse.stms.AbstractTransactionSnapshot>

dodoClear

protected abstract void dodoClear()

attach

protected abstract void attach(AlphaTranlocal opened)
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.

Parameters:
opened - the opened AlphaTranlocal to attach.

findAttached

protected abstract AlphaTranlocal findAttached(AlphaTransactionalObject txObject)
Finds the tranlocal for the given transactional object in the set of attached tranlocals.

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.

doOpenForRead

protected final AlphaTranlocal doOpenForRead(AlphaTransactionalObject txObject)
Overrides:
doOpenForRead in class AbstractAlphaTransaction<UpdateConfiguration,org.multiverse.stms.AbstractTransactionSnapshot>

doOpenForWrite

protected AlphaTranlocal doOpenForWrite(AlphaTransactionalObject txObject)
Overrides:
doOpenForWrite in class AbstractAlphaTransaction<UpdateConfiguration,org.multiverse.stms.AbstractTransactionSnapshot>

doOpenForWritePreviousCommittedAndAttach

protected final AlphaTranlocal doOpenForWritePreviousCommittedAndAttach(AlphaTransactionalObject txObject)

doOpenForCommutingWrite

protected AlphaTranlocal doOpenForCommutingWrite(AlphaTransactionalObject txObject)
Overrides:
doOpenForCommutingWrite in class AbstractAlphaTransaction<UpdateConfiguration,org.multiverse.stms.AbstractTransactionSnapshot>

doOpenForConstruction

public final AlphaTranlocal doOpenForConstruction(AlphaTransactionalObject txObject)
Overrides:
doOpenForConstruction in class AbstractAlphaTransaction<UpdateConfiguration,org.multiverse.stms.AbstractTransactionSnapshot>

doPrepare

protected final void doPrepare()
Overrides:
doPrepare in class org.multiverse.stms.AbstractTransaction<UpdateConfiguration,org.multiverse.stms.AbstractTransactionSnapshot>

isDirty

protected abstract boolean isDirty()
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.

Returns:
the AttachedState.

isDirty

protected final boolean isDirty(AlphaTranlocal attached)

hasWriteConflict

protected abstract boolean hasWriteConflict()
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.

Returns:
true if at least 1 attached tranlocal has a conflict.

hasWriteConflict

protected final boolean hasWriteConflict(AlphaTranlocal tranlocal)

hasReadConflict

protected abstract boolean hasReadConflict()
Checks if the reads don't have conflicts. The writes are neglected because they will be checked with the hasWriteConflict.

Returns:
true if there are conflict, false otherwise.

hasReadConflict

protected final boolean hasReadConflict(AlphaTranlocal attached)

tryWriteLocks

protected abstract boolean tryWriteLocks(org.multiverse.api.commitlock.CommitLockFilter commitLockFilter)
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).

Returns:
true if the writeset was locked successfully, false otherwise.

doReleaseWriteLocksForFailure

protected abstract void doReleaseWriteLocksForFailure()
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.


doReleaseWriteSetLocksForFailure

protected final void doReleaseWriteSetLocksForFailure(AlphaTranlocal tranlocal)

doReleaseWriteLocksForSuccess

protected abstract void doReleaseWriteLocksForSuccess(long writeVersion)
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.

Parameters:
writeVersion - the writeVersion of the tranlocals to release.

doReleaseWriteLockForSuccess

protected final void doReleaseWriteLockForSuccess(AlphaTranlocal tranlocal,
                                                  long writeVersion)

makeChangesPermanent

protected abstract org.multiverse.api.Listeners[] makeChangesPermanent(long writeVersion)
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.

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).

makePermanent

protected final org.multiverse.api.Listeners makePermanent(AlphaTranlocal tranlocal,
                                                           long writeVersion)

doAbortPrepared

protected void doAbortPrepared()
Overrides:
doAbortPrepared in class org.multiverse.stms.AbstractTransaction<UpdateConfiguration,org.multiverse.stms.AbstractTransactionSnapshot>

makeChangesPermanent

protected void makeChangesPermanent()
Overrides:
makeChangesPermanent in class org.multiverse.stms.AbstractTransaction<UpdateConfiguration,org.multiverse.stms.AbstractTransactionSnapshot>


Copyright © 2008-2010 Multiverse. All Rights Reserved.