J avolution v3.7 (J2SE 1.5+)

javolution.realtime
Class StackReference<T>

java.lang.Object
  extended by javolution.realtime.RealtimeObject
      extended by javolution.realtime.StackReference<T>
All Implemented Interfaces:
Reference<T>, Realtime

public final class StackReference<T>
extends RealtimeObject
implements Reference<T>

This class encapsulates a reference allocated on the current stack when executing in PoolContext. The reachability level of a stack reference is the scope of the PoolContext in which it has been created.

Stack references are automatically cleared based upon their reachability level like any java.lang.ref.Reference. In other words, stack references are automatically cleared when exiting the PoolContext where they have been factory produced.

Stack references are typically used by functions having more than one return value to avoid creating new objects on the heap. For example:

     // Returns both the position and its status.
     public Coordinates getPosition(Reference<Status> status) {
         ...
     }
     ...
     StackReference<Status> status = StackReference.newInstance(); // On the stack.
     Coordinates position = getPosition(status);
     if (status.get() == ACCURATE) ...
See also ConcurrentContext for examples of StackReference usage.

Version:
3.4, July 3, 2005
Author:
Jean-Marie Dautelle

Nested Class Summary
 
Nested classes/interfaces inherited from class javolution.realtime.RealtimeObject
RealtimeObject.Factory<T extends RealtimeObject>
 
Nested classes/interfaces inherited from interface javolution.realtime.Realtime
Realtime.ObjectSpace
 
Method Summary
 T get()
          Returns the value this reference referes to.
static
<T> StackReference<T>
newInstance()
          Returns a new stack reference instance allocated on the current stack when executing in PoolContext.
 void set(T value)
          Sets the value this reference referes to.
 Text toText()
          Returns the text representation of the current value of this reference.
 
Methods inherited from class javolution.realtime.RealtimeObject
export, move, moveHeap, preserve, recycle, toString, unpreserve
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

newInstance

public static <T> StackReference<T> newInstance()
Returns a new stack reference instance allocated on the current stack when executing in PoolContext.

Returns:
a local reference object.

toText

public Text toText()
Returns the text representation of the current value of this reference.

Specified by:
toText in interface Realtime
Overrides:
toText in class RealtimeObject
Returns:
Text.valueOf(this.get())

get

public T get()
Description copied from interface: Reference
Returns the value this reference referes to.

Specified by:
get in interface Reference<T>
Returns:
the referent or null if not set.

set

public void set(T value)
Description copied from interface: Reference
Sets the value this reference referes to.

Specified by:
set in interface Reference<T>
Parameters:
value - the reference value.

J avolution v3.7 (J2SE 1.5+)

Copyright © 2006 Javolution.