org.multiverse.stms.alpha.programmatic
Class AlphaProgrammaticReference<E>

java.lang.Object
  extended by org.multiverse.stms.alpha.mixins.DefaultTxObjectMixin
      extended by org.multiverse.stms.alpha.programmatic.AlphaProgrammaticReference<E>
All Implemented Interfaces:
org.multiverse.api.commitlock.CommitLock, org.multiverse.api.programmatic.ProgrammaticReference<E>, org.multiverse.MultiverseConstants, AlphaTransactionalObject

public final class AlphaProgrammaticReference<E>
extends DefaultTxObjectMixin
implements org.multiverse.api.programmatic.ProgrammaticReference<E>

A manual instrumented org.multiverse.transactional.TransactionalReference implementation. If this class is used,you don't need to worry about instrumentation/javaagents and stuff like this.

It is added to getClassMetadata the Akka project up and running, but probably will removed when the instrumentation is 100% up and running and this can be done compiletime instead of messing with javaagents.

Lifting on a transaction

All methods automatically lift on a transaction if one is available, but to reduce the need for extra object creation and unwanted ThreadLocal access, there also are methods available that have a Transaction as first argument.

TransactionFactory

All methods of this AlphaProgrammaticReference also have a version that accepts a TransactionFactory. TransactionFactories can be quite expensive to createReference, so it is best to createReference them up front and reuse them. TransactionFactories are threadsafe to use, so no worries about that as well.

Performance

The AlphaProgrammaticReference already has been heavily optimized and prevents unwanted creation of objects like Transactions or TransactionTemplates. If you really need more performance you should talk to me about adding instrumentation.

Relying on GlobalStmInstance

This Ref implementation can be used without depending on the GlobalStmInstance (so you could createReference a local one stm instance). If this is done, only the methods that rely on a Transaction or TransactionFactory should be used.

___ methods

If you use code completion on this class you will also find ___ methods. These methods are not for you unless you really know what you do. So ignore them.

TODO: The internal templates created here don't need to have lifecycle callbacks enabled.

Possible optimization for the alpha engine, instead of placing the lock, listener on the transactional object, place it on the tranlocal. This would remove the writeLock after commit because when the new tranlocal is written, the lock automatically is null.

The listener can also be read from the tranlocal so no need to

Author:
Peter Veentjer

Field Summary
 
Fields inherited from interface org.multiverse.MultiverseConstants
___SANITY_CHECKS_ENABLED
 
Constructor Summary
AlphaProgrammaticReference()
          Creates a new Ref with null as value.
AlphaProgrammaticReference(AlphaStm stm, E value)
           
AlphaProgrammaticReference(E value)
          Creates a new Ref with the provided value.
AlphaProgrammaticReference(org.multiverse.api.Transaction tx)
          Creates a new Ref using the provided transaction.
AlphaProgrammaticReference(org.multiverse.api.Transaction tx, E value)
           
 
Method Summary
 AlphaProgrammaticReferenceTranlocal<E> ___openUnconstructed()
          Creates a fresh AlphaTranlocal.
 boolean atomicCompareAndSet(E expected, E update)
           
 E atomicGet()
           
 boolean atomicIsNull()
           
 E atomicSet(E newValue)
           
static AlphaProgrammaticReference createUncommitted()
           
 E get()
           
 E get(org.multiverse.api.Transaction tx)
           
 E getOrAwait()
           
 E getOrAwait(org.multiverse.api.Transaction tx)
           
 E getOrAwait(org.multiverse.api.TransactionFactory txFactory)
           
 boolean isNull()
           
 boolean isNull(org.multiverse.api.Transaction tx)
           
 E set(E newValue)
           
 E set(org.multiverse.api.Transaction tx, E newValue)
           
 String toString()
           
 String toString(org.multiverse.api.Transaction tx)
           
 
Methods inherited from class org.multiverse.stms.alpha.mixins.DefaultTxObjectMixin
___getListeners, ___getLockOwner, ___load, ___load, ___openForCommutingOperation, ___registerRetryListener, ___releaseLock, ___storeInitial, ___storeUpdate, ___tryLock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AlphaProgrammaticReference

public AlphaProgrammaticReference()
Creates a new Ref with null as value. It has exactly the same AlphaProgrammaticReference(Object) with null as value.

This method relies on the ThreadLocalTransaction and GlobalStmInstance.


AlphaProgrammaticReference

public AlphaProgrammaticReference(E value)
Creates a new Ref with the provided value.

If there is no transaction active, the writeversion of the committed reference will be the same as the current version of the stm. Normally it increases after a commit to indicate that a change has been made. But for a transaction that only adds new transactional objects instead of modifying them this isn't needed. This reduces stress on the

This method relies on the ThreadLocalTransaction. If no transaction is found, it also relies on the GlobalStmInstance.

Parameters:
value - the value this Ref should have.

AlphaProgrammaticReference

public AlphaProgrammaticReference(org.multiverse.api.Transaction tx)
Creates a new Ref using the provided transaction.

This method does not rely on a ThreadLocalTransaction and GlobalStmInstance.

Parameters:
tx - the Transaction used
Throws:
IllegalThreadStateException - if the transaction was not in the correct state for creating this AlphaProgrammaticReference.

AlphaProgrammaticReference

public AlphaProgrammaticReference(AlphaStm stm,
                                  E value)

AlphaProgrammaticReference

public AlphaProgrammaticReference(org.multiverse.api.Transaction tx,
                                  E value)
Method Detail

createUncommitted

public static AlphaProgrammaticReference createUncommitted()

get

public E get()
Specified by:
get in interface org.multiverse.api.programmatic.ProgrammaticReference<E>

get

public E get(org.multiverse.api.Transaction tx)
Specified by:
get in interface org.multiverse.api.programmatic.ProgrammaticReference<E>

atomicGet

public E atomicGet()
Specified by:
atomicGet in interface org.multiverse.api.programmatic.ProgrammaticReference<E>

isNull

public boolean isNull()
Specified by:
isNull in interface org.multiverse.api.programmatic.ProgrammaticReference<E>

isNull

public boolean isNull(org.multiverse.api.Transaction tx)
Specified by:
isNull in interface org.multiverse.api.programmatic.ProgrammaticReference<E>

atomicIsNull

public boolean atomicIsNull()
Specified by:
atomicIsNull in interface org.multiverse.api.programmatic.ProgrammaticReference<E>

getOrAwait

public E getOrAwait()
Specified by:
getOrAwait in interface org.multiverse.api.programmatic.ProgrammaticReference<E>

getOrAwait

public E getOrAwait(org.multiverse.api.TransactionFactory txFactory)
Specified by:
getOrAwait in interface org.multiverse.api.programmatic.ProgrammaticReference<E>

getOrAwait

public E getOrAwait(org.multiverse.api.Transaction tx)
Specified by:
getOrAwait in interface org.multiverse.api.programmatic.ProgrammaticReference<E>

set

public E set(E newValue)
Specified by:
set in interface org.multiverse.api.programmatic.ProgrammaticReference<E>

set

public E set(org.multiverse.api.Transaction tx,
             E newValue)
Specified by:
set in interface org.multiverse.api.programmatic.ProgrammaticReference<E>

atomicSet

public E atomicSet(E newValue)
Specified by:
atomicSet in interface org.multiverse.api.programmatic.ProgrammaticReference<E>

atomicCompareAndSet

public boolean atomicCompareAndSet(E expected,
                                   E update)
Specified by:
atomicCompareAndSet in interface org.multiverse.api.programmatic.ProgrammaticReference<E>

toString

public String toString()
Overrides:
toString in class Object

toString

public String toString(org.multiverse.api.Transaction tx)
Specified by:
toString in interface org.multiverse.api.programmatic.ProgrammaticReference<E>

___openUnconstructed

public AlphaProgrammaticReferenceTranlocal<E> ___openUnconstructed()
Description copied from interface: AlphaTransactionalObject
Creates a fresh AlphaTranlocal. This can be used when a write on a tranlocal needs to be done, but no tranlocal has been created yet (so should be created in the constructor).

Specified by:
___openUnconstructed in interface AlphaTransactionalObject
Returns:
the created AlphaTranlocal.


Copyright © 2008-2010 Multiverse. All Rights Reserved.