org.multiverse.stms.alpha
Class AlphaTranlocal

java.lang.Object
  extended by org.multiverse.stms.alpha.AlphaTranlocal
All Implemented Interfaces:
org.multiverse.api.commitlock.CommitLock, org.multiverse.MultiverseConstants
Direct Known Subclasses:
AlphaProgrammaticLongTranlocal, AlphaProgrammaticReferenceTranlocal

public abstract class AlphaTranlocal
extends Object
implements org.multiverse.api.commitlock.CommitLock, org.multiverse.MultiverseConstants

The Tranlocal is the Transaction local content of a TransactionalObject, since the state from the TransactionalObject is removed. So for every TransactionalObject there are 1 or more Tranlocals (or zero when the TransactionalObject is being constructed).

Semantics of version: after the Tranlocal is committed, the version contains the write version. Before the commit it contains the current read version.

To support nested transactions there are partial rollbacks, each Tranlocal is able to make a snapshot of itself, so that it can be restored when a (nested) transaction rolls back.

Once the Tranlocal has been committed, the fields should only be read and not written. Since the publication (commit) introduces some happens before relation, the fields in this object will also lift on that happens before relation.

Author:
Peter Veentjer.

Field Summary
 AlphaTranlocal ___origin
           
 AlphaTransactionalObject ___transactionalObject
           
 long ___writeVersion
           
static long OPENED_FOR_COMMUTE
           
static long OPENED_FOR_COMMUTE_AND_DIRTY
           
static long OPENED_FOR_WRITE
           
static long OPENED_FOR_WRITE_AND_DIRTY
           
 
Fields inherited from interface org.multiverse.MultiverseConstants
___SANITY_CHECKS_ENABLED
 
Constructor Summary
AlphaTranlocal()
           
 
Method Summary
 org.multiverse.api.Transaction ___getLockOwner()
           
 void ___releaseLock(org.multiverse.api.Transaction expectedLockOwner)
           
 boolean ___tryLock(org.multiverse.api.Transaction lockOwner)
           
 boolean executeDirtyCheck()
          Checks if the tranlocal is dirty and caches the value

If the tranlocal is committed, false is returned and nothing is changed.

 AlphaTranlocal getOrigin()
          Returns the original committed AlphaTranlocal this AlphaTranlocal is a updatable version of.
 boolean getPrecalculatedIsDirty()
          Checks if the tranlocal is dirty by making use of a ___writeVersion that is changed by the executeDirtyCheck method.
 AlphaTransactionalObject getTransactionalObject()
          Returns the AlphaTransactionalObject that belongs to this AlphaTranlocal.
 long getWriteVersion()
           
 boolean hasReadConflict(org.multiverse.api.Transaction allowedLockOwner)
           
 boolean hasWriteConflict()
           
 boolean isCommitted()
           
 boolean isCommuting()
           
abstract  boolean isDirty()
          Checks if this Tranlocal should be committed.
 boolean isUncommitted()
           
 void lateFixation(AlphaTransaction tx)
           
abstract  AlphaTranlocal openForWrite()
          Returns a clone of this AlphaTranlocal to be used for updates.
 void prematureFixation(AlphaTransaction tx, AlphaTranlocal origin)
           
 void prepareForCommit(long writeVersion)
          Is called just before this tranlocal commits.
abstract  AlphaTranlocalSnapshot takeSnapshot()
          Creates the TranlocalSnapshot of the Tranlocal.
 String toDebugString()
          Debug representation of a TransactionalObject.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPENED_FOR_WRITE

public static final long OPENED_FOR_WRITE
See Also:
Constant Field Values

OPENED_FOR_WRITE_AND_DIRTY

public static final long OPENED_FOR_WRITE_AND_DIRTY
See Also:
Constant Field Values

OPENED_FOR_COMMUTE

public static final long OPENED_FOR_COMMUTE
See Also:
Constant Field Values

OPENED_FOR_COMMUTE_AND_DIRTY

public static final long OPENED_FOR_COMMUTE_AND_DIRTY
See Also:
Constant Field Values

___writeVersion

public long ___writeVersion

___origin

public AlphaTranlocal ___origin

___transactionalObject

public AlphaTransactionalObject ___transactionalObject
Constructor Detail

AlphaTranlocal

public AlphaTranlocal()
Method Detail

getTransactionalObject

public final AlphaTransactionalObject getTransactionalObject()
Returns the AlphaTransactionalObject that belongs to this AlphaTranlocal.

Returns:
the AlphaTransactionalObject that belongs to this AlphaTranlocal

getOrigin

public final AlphaTranlocal getOrigin()
Returns the original committed AlphaTranlocal this AlphaTranlocal is a updatable version of.

Returns:
the origin. Undefined after AlphaTranlocal is committed.

takeSnapshot

public abstract AlphaTranlocalSnapshot takeSnapshot()
Creates the TranlocalSnapshot of the Tranlocal. A snapshot should only be made if this Tranlocal is not committed.

Returns:
the snapshot.

openForWrite

public abstract AlphaTranlocal openForWrite()
Returns a clone of this AlphaTranlocal to be used for updates. This method only should be called on tranlocals that have committed (so have a ___writeVersion larger than 0). The implementation is free to check for this violation, but it isn't mandatory.

Returns:
the clone of this AlphaTranlocal that can be used for updates.

prepareForCommit

public final void prepareForCommit(long writeVersion)
Is called just before this tranlocal commits. It allows the Tranlocal to do needed cleanup.

An implementation needs to do at least 2 things:

  1. change committed to true
  2. set the version to the writeVersion

Detection if the writeVersion makes sense is not mandatory for the implementation.

Parameters:
writeVersion - the version of the commit. This is the version this tranlocal from now on will be known. It is never going to change anymore.

isDirty

public abstract boolean isDirty()
Checks if this Tranlocal should be committed.

Returns:
true if it should be committed, false otherwise.

executeDirtyCheck

public final boolean executeDirtyCheck()
Checks if the tranlocal is dirty and caches the value

If the tranlocal is committed, false is returned and nothing is changed.

If not is dirty (but also not committed) the ___writeVersion is set to 0 and false is returned.

If dirty (but also not committed) the ___writeVersion is set to -1.

Returns:

getPrecalculatedIsDirty

public final boolean getPrecalculatedIsDirty()
Checks if the tranlocal is dirty by making use of a ___writeVersion that is changed by the executeDirtyCheck method. If the tranlocal is committed, false will be returned.

Returns:
true if dirty, false otherwise.

isCommitted

public final boolean isCommitted()

isUncommitted

public final boolean isUncommitted()

isCommuting

public final boolean isCommuting()

prematureFixation

public void prematureFixation(AlphaTransaction tx,
                              AlphaTranlocal origin)

lateFixation

public void lateFixation(AlphaTransaction tx)

getWriteVersion

public final long getWriteVersion()

hasWriteConflict

public final boolean hasWriteConflict()

hasReadConflict

public final boolean hasReadConflict(org.multiverse.api.Transaction allowedLockOwner)

___getLockOwner

public final org.multiverse.api.Transaction ___getLockOwner()
Specified by:
___getLockOwner in interface org.multiverse.api.commitlock.CommitLock

___tryLock

public final boolean ___tryLock(org.multiverse.api.Transaction lockOwner)
Specified by:
___tryLock in interface org.multiverse.api.commitlock.CommitLock

___releaseLock

public final void ___releaseLock(org.multiverse.api.Transaction expectedLockOwner)
Specified by:
___releaseLock in interface org.multiverse.api.commitlock.CommitLock

toDebugString

public String toDebugString()
Debug representation of a TransactionalObject.

Returns:
the string representation of the atomicobject.


Copyright © 2008-2010 Multiverse. All Rights Reserved.