A utility class for wrapping a {@link Serializable} object within a {@code ManagedObject} instance. This class is primarily intended to allow classthat does not implement {@code ManagedObject} to be persistently stored andaccessed through a {@code ManagedReference}.
The serialization costs for a class largely depend on the size of the objects that it references. The {@code ManagedReference} class allowsdevelopers the ability to create breaks in the serialization graphs where not all of the fields are deserialized when a class is deserialized. The {@code ManagedSerializable} class is intended to be used for wrapping largeserializable objects, such as collections, in order to break the serialization graph, thereby reducing the number of bytes read and written. Note that wrapping these types of objects does not guarantee a performance improvement.
Following is an example of where an existing class has been retrofitted to have {@code ManagedReference} references to its large fields, rather thanstandard references.
Before:
public class MyPlayerObj { String name; Collection< Item > inventory; MapArea currentLocation; public MyPlayerObj(...) { ... inventory = new ArrayList< Item >(); } ... public void findNearbyPlayers() { for (Player p : currentLocation.getPlayers()) ... } }
After: {@code}public class MyPlayerObj String name; ManagedReference< ManagedSerializable< Collection< Item >>> inventoryRef; ManagedReference< ManagedSerializable< MapArea >> currentLocationRef; public MyPlayerObj(...) { ... Collection< Item > inventory = new ArrayList< Item >(); inventoryRef = AppContext.getDataManager(). createReference( new ManagedSerializable< Collection< Item>>(inventory)); } ... public void findNearbyPlayers() { ManagedSerializable< MapArea > curLocWrapper = currentLocationRef.get(); MapArea currentLocation = curLocWrapper.get(); for (Player p : currentLocation.getPlayers()) ... } } }
Application developers are responsible for removing {@code ManagedSerializable} instances by calling {@link DataManager#removeObject DataManager.removeObject}. Developers should call {@link DataManager#markForUpdate DataManager.markForUpdate} or {@link ManagedReference#getForUpdate DataManager.getForUpdate} if the applicationmodifies objects wrapped by instances of this class.
@param < T> the type of the wrapped object