|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.sgs.app.util.ManagedSerializable<T>
T
- the type of the wrapped objectpublic class ManagedSerializable<T>
A utility class for wrapping a Serializable
object within a ManagedObject
instance. This class is primarily intended to allow class
that does not implement ManagedObject
to be persistently stored and
accessed through a ManagedReference
.
The serialization costs for a class largely depend on the size of the
objects that it references. The ManagedReference
class allows
developers the ability to create breaks in the serialization graphs where
not all of the fields are deserialized when a class is deserialized. The
ManagedSerializable
class is intended to be used for wrapping large
serializable 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 ManagedReference
references to its large fields, rather than
standard 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:
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 ManagedSerializable
instances by calling DataManager.removeObject
. Developers should call DataManager.markForUpdate
or DataManager.getForUpdate
if the application
modifies objects wrapped by instances of this class.
Constructor Summary | |
---|---|
ManagedSerializable(T object)
Constructs an instance of this class that wraps the specified object, which must not implement ManagedObject , but must either
implement Serializable or be null . |
Method Summary | |
---|---|
boolean |
equals(Object o)
Returns true if o is a ManagedSerializable that
wraps an object that is equal to the object wrapped by this instance. |
T |
get()
Returns the object wrapped by this instance, which may be null . |
int |
hashCode()
|
void |
set(T object)
Replaces the object wrapped by this instance with the specified object, which must not implement ManagedObject , but must either
implement Serializable or be null . |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ManagedSerializable(T object)
ManagedObject
, but must either
implement Serializable
or be null
.
object
- the object to wrap
IllegalArgumentException
- if object
is an instance of
ManagedObject
, or if object
is not null
and does not implement Serializable
Method Detail |
---|
public boolean equals(Object o)
true
if o
is a ManagedSerializable
that
wraps an object that is equal to the object wrapped by this instance.
equals
in class Object
o
- the object to compared for equality with this instance
true
if o
is a ManagedSerializable
that
wraps an object equal to the object wrapped by this instancepublic T get()
null
.
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
public void set(T object)
ManagedObject
, but must either
implement Serializable
or be null
.
object
- the new object to wrap
IllegalArgumentException
- if object
is an instance of
ManagedObject
, or if object
is not null
and does not implement Serializable
|
Project Darkstar, Version 0.9.9.6 2009-05-08 15:39:40 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |