com.sun.sgs.impl.util
Class AdaptiveField<T>

java.lang.Object
  extended by com.sun.sgs.impl.util.AdaptiveField<T>
Type Parameters:
T - the type of the referenced object
All Implemented Interfaces:
Serializable

public final class AdaptiveField<T>
extends Object
implements Serializable

An AdaptiveField is an abstraction over the traditional Java field that allows a field to be stored either locally (as a normal field would be) or remotely in the data store, while still allowing common operations as well as the ability to dynamically switch where the field's value is stored.

A ManagedObject will deserialize all of its non-transient fields, which at times is undesirable for latency (e.g. when the field is large, or will not be used). An AdaptiveField allow the developer finer control over whether a field needs to be included in the serialization graph by providing a common interface for interacting with the field regardless of how it is stored.

A local AdaptiveField has its value stored just like any other Java field. When a ManagedObject deserializes from the data store, the field will be included in its serialization graph. For this reason a ManagedObject cannot be stored in an AdaptiveField. If the developer wants to change the field so that it is stored in the data store, the AdaptiveField.makeManaged call can be used. This causes the field's value to no longer be deserialized when the containing ManagedObject is deserialized.

See Also:
ManagedReference, ManagedObject, Serialized Form

Constructor Summary
AdaptiveField(T value)
          Constructs this AdaptiveField as a local reference with the provided value.
AdaptiveField(T value, boolean isLocal)
          Constructs this AdaptiveField with the provided value, and stores it as specified.
 
Method Summary
 T get()
          Returns the value of the field.
 T getForUpdate()
          Returns the value of the field and if remotely stored, marks the value for update.
 boolean isLocal()
          Returns true if this field is stored as a local reference.
 void makeLocal()
          Move this field from being stored as a ManagedObject in the data store to being kept as a local reference.
 void makeManaged()
          Move this field from being a local Java reference to being stored as a ManagedObject in the data store.
 void markForUpdate()
          If this field is not stored locally, marks the field for update.
 void set(T value)
          Sets the value of this field.
 void set(T value, boolean isLocal)
          Sets the value of this field and updates its locality based on isLocal.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AdaptiveField

public AdaptiveField(T value)
Constructs this AdaptiveField as a local reference with the provided value.

Parameters:
value - the value of this field
Throws:
IllegalArgumentException - if the provided value is a ManagedObject

AdaptiveField

public AdaptiveField(T value,
                     boolean isLocal)
Constructs this AdaptiveField with the provided value, and stores it as specified.

Parameters:
value - the value of this field
isLocal - whether this field should be kept with a local reference or stored in the data store.
Throws:
IllegalArgumentException - if the provided value is a ManagedObject
Method Detail

get

public T get()
Returns the value of the field. Note that if the field is stored locally and changes, the caller should call DataManager.markForUpdate on the ManagedObject that contains this field since its state has been changed. The values of fields that are not local are cached after the initial call to the DataManager, so subsequent calls to get will act as if they are local.

Returns:
the value of the field

getForUpdate

public T getForUpdate()
Returns the value of the field and if remotely stored, marks the value for update. Note that if the field is stored locally and changes, the caller should call DataManager.markForUpdate on the ManagedObject that contains this field since its state has been changed.

Returns:
the value of the field

isLocal

public boolean isLocal()
Returns true if this field is stored as a local reference. Otherwise, the field is persisted with the DataManager and is excluded from the serialization graph of the object that contains this AdaptiveField.

Returns:
true if this field is stored as a local reference

makeLocal

public void makeLocal()
Move this field from being stored as a ManagedObject in the data store to being kept as a local reference. This field will now be included in the serialization graph of the object that contains this field.


makeManaged

public void makeManaged()
Move this field from being a local Java reference to being stored as a ManagedObject in the data store. This field will no longer be included in the serialization graph of the object that contains this field.


markForUpdate

public void markForUpdate()
If this field is not stored locally, marks the field for update.


set

public void set(T value)
Sets the value of this field.

Parameters:
value - the new value of the field

set

public void set(T value,
                boolean isLocal)
Sets the value of this field and updates its locality based on isLocal.

Parameters:
value - the new value of the field
isLocal - whether this field should be kept with a local reference or stored in the data store.

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved