From 902a4027eac7d4ea5148bd8d0cda7da16dca0dcf Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 25 Nov 2010 00:03:52 +0000 Subject: [PATCH] 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 --- .../threerings/admin/server/ConfigRegistry.java | 15 ++++++--------- src/main/java/com/threerings/io/Streamer.java | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/threerings/admin/server/ConfigRegistry.java b/src/main/java/com/threerings/admin/server/ConfigRegistry.java index 7a1389825..e117c985c 100644 --- a/src/main/java/com/threerings/admin/server/ConfigRegistry.java +++ b/src/main/java/com/threerings/admin/server/ConfigRegistry.java @@ -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(), diff --git a/src/main/java/com/threerings/io/Streamer.java b/src/main/java/com/threerings/io/Streamer.java index 38cf60e55..f6ef1706e 100644 --- a/src/main/java/com/threerings/io/Streamer.java +++ b/src/main/java/com/threerings/io/Streamer.java @@ -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;