org.multiverse.transactional.refs
Class AbaRef<E>

java.lang.Object
  extended by org.multiverse.transactional.refs.AbaRef<E>
All Implemented Interfaces:
Ref<E>

public class AbaRef<E>
extends Object
implements Ref<E>

A Ref that doesn't suffer from the ABA problem. See the BasicRef for more information.

Author:
Peter Veentjer

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

Constructor Detail

AbaRef

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


AbaRef

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

Parameters:
value - the reference to store.
Method Detail

getOrAwait

public final E getOrAwait()
Description copied from interface: Ref
Gets the current non null value, or waits until a non null value comes 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 Ref<E>
Returns:
the current stored reference.

getOrAwaitInterruptibly

public final E getOrAwaitInterruptibly()
                                throws InterruptedException
Description copied from interface: Ref
Gets the current non null value, or waits until a non null value 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 Ref<E>
Returns:
the current stored reference.
Throws:
InterruptedException - if the thread is interrupted while waiting on a reference to come available.

get

public final E get()
Description copied from interface: Ref
Gets the current value stored in this reference.

Specified by:
get in interface Ref<E>
Returns:
the current value.

isNull

public final boolean isNull()
Description copied from interface: Ref
Checks if the value is null.

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

set

public final E set(E newValue)
Description copied from interface: Ref
Sets the new value value. The value is allowed to be null.

Specified by:
set in interface Ref<E>
Parameters:
newValue - the new value
Returns:
the previous value, which could be null.

clear

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

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

toString

public final String toString()
Overrides:
toString in class Object


Copyright © 2008-2010 Multiverse. All Rights Reserved.