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

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

public class BasicRef<E>
extends java.lang.Object
implements Ref<E>

Basic Ref implementation. In most cases this is the Ref implementation you want to use.

Author:
Peter Veentjer

Constructor Summary
BasicRef()
          Creates a BasicRef with a null reference.
BasicRef(E value)
          Creates a new BasicRef 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.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BasicRef

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


BasicRef

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

Parameters:
value - the reference to store in this BasicRef.
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 java.lang.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:
java.lang.InterruptedException - if the thread is interrupted while waiting on a reference to come available.

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.

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.

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 java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2008-2010 Multiverse. All Rights Reserved.