Tweaks to allow serializing config attributes other than DSets.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6304 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Andrzej Kapolka
2010-11-25 00:03:52 +00:00
parent 8e5865995c
commit 902a4027ea
2 changed files with 20 additions and 12 deletions
@@ -38,7 +38,7 @@ import com.samskivert.util.StringUtil;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
import com.threerings.io.Streamable;
import com.threerings.io.Streamer;
import com.threerings.presents.dobj.AccessController;
import com.threerings.presents.dobj.AttributeChangeListener;
@@ -221,12 +221,7 @@ public abstract class ConfigRegistry
public void attributeChanged (AttributeChangedEvent event)
{
// mirror this configuration update to the persistent config
Object value = event.getValue();
if (value instanceof DSet<?>) {
serializeAttribute(event.getName());
} else {
updateValue(event.getName(), value);
}
updateValue(event.getName(), event.getValue());
}
protected void updateValue (String name, Object value)
@@ -254,6 +249,8 @@ public abstract class ConfigRegistry
setValue(key, (String[])value);
} else if (value instanceof long[]) {
setValue(key, (long[])value);
} else if (value == null || Streamer.isStreamable(value.getClass())) {
serializeAttribute(name);
} else {
log.info("Unable to flush config obj change", "cobj", object.getClass().getName(),
"key", key, "type", value.getClass().getName(), "value", value);
@@ -314,7 +311,7 @@ public abstract class ConfigRegistry
long[] defval = (long[])field.get(object);
field.set(object, getValue(key, defval));
} else if (Streamable.class.isAssignableFrom(type)) {
} else if (Streamer.isStreamable(type)) {
// don't freak out if the conf is blank.
String value = getValue(key, "");
if (StringUtil.isBlank(value)) {
@@ -363,7 +360,7 @@ public abstract class ConfigRegistry
return;
}
if (value instanceof Streamable) {
if (value == null || Streamer.isStreamable(value.getClass())) {
serialize(attributeName, key, value);
} else {
log.info("Unable to flush config obj change", "cobj", object.getClass().getName(),
+14 -3
View File
@@ -60,6 +60,9 @@ public class Streamer
*/
public synchronized static boolean isStreamable (Class<?> target)
{
// if we have not yet initialized ourselves, do so now
maybeInit();
while (true) {
// if we've got a streamer for it, it's good
if (_streamers.containsKey(target)) {
@@ -108,9 +111,7 @@ public class Streamer
throws IOException
{
// if we have not yet initialized ourselves, do so now
if (_streamers == null) {
_streamers = Maps.newHashMap(BasicStreamers.BSTREAMERS);
}
maybeInit();
Streamer stream = _streamers.get(target);
if (stream == null) {
@@ -487,6 +488,16 @@ public class Streamer
}
}
/**
* Initializes static state if necessary.
*/
protected synchronized static void maybeInit ()
{
if (_streamers == null) {
_streamers = Maps.newHashMap(BasicStreamers.BSTREAMERS);
}
}
/** Used to coerce the type system into quietude when reading enums from the wire. */
protected static enum EnumReader implements ByteEnum {
NOT_USED;