J avolution v3.7 (J2SE 1.5+)

javolution.realtime
Class RealtimeObject

java.lang.Object
  extended by javolution.realtime.RealtimeObject
All Implemented Interfaces:
Realtime
Direct Known Subclasses:
CharacterData, FastCollection, FastMap, StackReference, Text, TextBuilder

public abstract class RealtimeObject
extends java.lang.Object
implements Realtime

This class provides a default implementation of the Realtime interface.

Instances of this class should be created using the inner Factory class. For example:

     public class Foo extends RealtimeObject {
         static final Factory<Foo> FACTORY = new Factory<Foo>() {
             protected Foo create() {
                 return new Foo();
             }
         };
         protected Foo() {} // Default constructor for sub-classes. 
         public static Foo newInstance() { // Static factory method.
             return FACTORY.object();
         }
         
         // Optional. 
         public boolean move(ObjectSpace os) { ... }
     }

Instances of this class can be immutable. Instances allocated in a pool context must be exported (e.g. return value) or preserved (e.g. static instance) if referenced after exiting the pool context.

Version:
3.7, January 1, 2006
Author:
Jean-Marie Dautelle

Nested Class Summary
static class RealtimeObject.Factory<T extends RealtimeObject>
          This abstract class represents the factory responsible for the creation of RealtimeObject instances.
 
Nested classes/interfaces inherited from interface javolution.realtime.Realtime
Realtime.ObjectSpace
 
Constructor Summary
protected RealtimeObject()
          Default constructor.
 
Method Summary
<T> T
export()
          Exports this object and its local real-time associations out of the current pool context (equivalent to move (ObjectSpace.OUTER)).
 boolean move(Realtime.ObjectSpace os)
          Moves this real-time object to the specified object space.
<T> T
moveHeap()
          Moves this object and its real-time associations to the heap (equivalent to move(ObjectSpace.HEAP)).
<T> T
preserve()
          Prevents this object and its real-time associations to be recycled (equivalent to move(ObjectSpace.HOLD)).
protected  void recycle()
          Recycles this object and its internals only.
 java.lang.String toString()
          Returns the String representation of this object.
 Text toText()
          Returns the default textual representation of this realtime object.
<T> T
unpreserve()
          Allows this object and its real-time associations to be recycled if not preserved any more (equivalent to move(ObjectSpace.STACK)).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RealtimeObject

protected RealtimeObject()
Default constructor.

Method Detail

toString

public final java.lang.String toString()
Returns the String representation of this object. This method is final to ensure consistency with toText() (which is the method to override).

Overrides:
toString in class java.lang.Object
Returns:
toText().stringValue()

toText

public Text toText()
Returns the default textual representation of this realtime object.

Specified by:
toText in interface Realtime
Returns:
the textual representation of this object.

export

public final <T> T export()
Exports this object and its local real-time associations out of the current pool context (equivalent to move (ObjectSpace.OUTER)). This method affects only local objects allocated on the stack and has no effect on heap objects or objects allocated outside of the current pool context.

Note: To avoid pool depletion when exporting to outer pool, the object is actually exchanged with an outer pool object.

Returns:
this

moveHeap

public final <T> T moveHeap()
Moves this object and its real-time associations to the heap (equivalent to move(ObjectSpace.HEAP)).

Returns:
this

preserve

public final <T> T preserve()
Prevents this object and its real-time associations to be recycled (equivalent to move(ObjectSpace.HOLD)). This method increments this object preserved counter.

Returns:
this
See Also:
unpreserve()

unpreserve

public final <T> T unpreserve()
Allows this object and its real-time associations to be recycled if not preserved any more (equivalent to move(ObjectSpace.STACK)). This method decrements this object preserved counter.

Returns:
this
See Also:
preserve()

move

public boolean move(Realtime.ObjectSpace os)
Description copied from interface: Realtime
Moves this real-time object to the specified object space.

Specified by:
move in interface Realtime
Parameters:
os - the object space to move this real-time object to.
Returns:
true if the move has to be propagated to external real-time references; false otherwise.

recycle

protected void recycle()
Recycles this object and its internals only. This method should only be called when it can be asserted that this object is not going to be referenced anymore. This method affects only local objects and has no effect on heap objects or objects allocated outside of the current pool context. Unlike the move operations, recycling is limited to this object and its internals and has no effect on external variable members (real-time or not).


J avolution v3.7 (J2SE 1.5+)

Copyright © 2006 Javolution.