org.multiverse.transactional
Class TransactionalAbaReference<E>

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

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

A TransactionalReference that doesn't suffer from the ABA problem. See the DefaultTransactionalReference for more information.

Author:
Peter Veentjer

Constructor Summary
TransactionalAbaReference()
          Creates a new TransactionalAbaReference with a null reference.
TransactionalAbaReference(E reference)
          Creates a new TransactionalAbaReference 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 newRef)
          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

TransactionalAbaReference

public TransactionalAbaReference()
Creates a new TransactionalAbaReference with a null reference.


TransactionalAbaReference

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

Parameters:
reference - the reference to store.
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.

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.

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.

set

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

Specified by:
set in interface TransactionalReference<E>
Parameters:
newRef - 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.