org.multiverse.transactional
Class DefaultTransactionalReference<E>

java.lang.Object
  extended by org.multiverse.transactional.DefaultTransactionalReference<E>
All Implemented Interfaces:
TransactionalReference<E>

public final class DefaultTransactionalReference<E>
extends Object
implements TransactionalReference<E>

Default TransactionalReference. Changes on primitives are atomic and consistent, but not completely because a transaction could suffer from the ABA problem between transactions. See the TransactionalAbaReference to solve this problem.

It depends on the STM implementation if the ABA problem can occur btw. If the readset also is included in the conflict detection, then the ABA problem can't occur.

Author:
Peter Veentjer

Constructor Summary
DefaultTransactionalReference()
          Creates a DefaultTransactionalReference with a null reference.
DefaultTransactionalReference(E value)
          Creates a new DefaultTransactionalReference with the provided reference.
 
Method Summary
 E clear()
          Clears the ref and returns the old value of the ref (could be null).
 E get()
          Gets the current stored ref, or null if no ref is stored.
 E getOrAwait()
          Gets the current stored ref, or waits until a non null reference becomes available.
 E getOrAwaitInterruptibly()
          Gets the current stored reference, or waits until a non null references becomes available or until it is is Interrupted.
 boolean isNull()
          Checks if the ref is null.
 E set(E newValue)
          Sets the current ref.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultTransactionalReference

public DefaultTransactionalReference()
Creates a DefaultTransactionalReference with a null reference.


DefaultTransactionalReference

public DefaultTransactionalReference(E value)
Creates a new DefaultTransactionalReference with the provided reference. This reference is allowed to be null.

Parameters:
value - the reference to store in this DefaultTransactionalReference.
Method Detail

getOrAwait

public E getOrAwait()
Description copied from interface: TransactionalReference
Gets the current stored ref, or waits until a non null reference becomes available. So you will always get a non null ref.

This call is not interruptible, unless the enclosing transaction is configured as interruptible.

Specified by:
getOrAwait in interface TransactionalReference<E>
Returns:
the current stored reference.

getOrAwaitInterruptibly

public E getOrAwaitInterruptibly()
                          throws InterruptedException
Description copied from interface: TransactionalReference
Gets the current stored reference, or waits until a non null references becomes available or until it is is Interrupted.

This call is interruptible, unless the enclosing transaction isn't configured as interruptible.

Specified by:
getOrAwaitInterruptibly in interface TransactionalReference<E>
Returns:
the current stored reference.
Throws:
InterruptedException - if the thread is interrupted while waiting on a reference to come available.

isNull

public boolean isNull()
Description copied from interface: TransactionalReference
Checks if the ref is null.

Specified by:
isNull in interface TransactionalReference<E>
Returns:
true if the ref is null, false otherwise.

get

public E get()
Description copied from interface: TransactionalReference
Gets the current stored ref, or null if no ref is stored.

Specified by:
get in interface TransactionalReference<E>
Returns:
the current stored ref, or null if no ref is stored.

set

public E set(E newValue)
Description copied from interface: TransactionalReference
Sets the current ref. The ref is allowed to be null.

Specified by:
set in interface TransactionalReference<E>
Parameters:
newValue - the ref to set.
Returns:
the previous ref, which could be null.

clear

public E clear()
Description copied from interface: TransactionalReference
Clears the ref and returns the old value of the ref (could be null).

Specified by:
clear in interface TransactionalReference<E>
Returns:
the old value.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2008-2010 Multiverse. All Rights Reserved.