Improvements to Collection streaming support.
Any Collection can now be streamed. You can send Collections.emptyMap() back to a client, for example. (It will unstream as a HashMap on the other side.) This actually streams everything to the exact same bytes as before. Using specific classes is discouraged: ArrayList, StreamableArrayList... If a Streamer is created for a class that has a field of that type, a warning will be generated, urging you to change the field definition to the interface. Also: that setup is now deferred until needed, because in clyde/projectx there are a number of Streamable classes that have fields of specific classes, like ArrayIntSet for example, but don't use standard streaming to transmit them. In that case it's totally cool for them to have a more specific type. Since that setup is potentially deferred, one change may be observed for a class that uses custom readObject() and writeObject() methods but still calls defaultReadObject(). The field marshallers will now be configured a little later in the game than before. But, we're actually saving a bit of memory by not setting up those marshallers for streamable classes that never use them. Woo. Please let me know if this causes any space shuttle explosions or spikes the punch at your quinceanera. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6348 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -26,7 +26,6 @@ import java.lang.reflect.Method;
|
||||
import java.lang.reflect.ReflectPermission;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
@@ -117,10 +116,20 @@ public abstract class FieldMarshaller
|
||||
|
||||
// if we have an exact match, use that
|
||||
FieldMarshaller fm = _marshallers.get(ftype);
|
||||
if (fm == null) {
|
||||
Class<?> collClass = Streamer.getCollectionClass(ftype);
|
||||
if (collClass != null && !collClass.equals(ftype)) {
|
||||
log.warning("Specific field types are discouraged for Collections and Maps.",
|
||||
"class", field.getDeclaringClass(), "field", field.getName(),
|
||||
"type", ftype, "shouldBe", collClass);
|
||||
fm = _marshallers.get(collClass);
|
||||
}
|
||||
|
||||
// otherwise if the class is a pure interface or streamable, use the streamable marshaller
|
||||
if (fm == null && (ftype.isInterface() || Streamer.isStreamable(ftype))) {
|
||||
fm = _marshallers.get(Streamable.class);
|
||||
// otherwise if the class is a pure interface or streamable,
|
||||
// use the streamable marshaller
|
||||
if (fm == null && (ftype.isInterface() || Streamer.isStreamable(ftype))) {
|
||||
fm = _marshallers.get(Streamable.class);
|
||||
}
|
||||
}
|
||||
|
||||
return fm;
|
||||
@@ -395,7 +404,7 @@ public abstract class FieldMarshaller
|
||||
}
|
||||
|
||||
/** Contains a mapping from field type to field marshaller instance for that type. */
|
||||
protected static HashMap<Class<?>, FieldMarshaller> _marshallers;
|
||||
protected static Map<Class<?>, FieldMarshaller> _marshallers;
|
||||
|
||||
/** The field marshaller for pooled strings. */
|
||||
protected static FieldMarshaller _internMarshaller;
|
||||
|
||||
Reference in New Issue
Block a user