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:
@@ -38,7 +38,7 @@ import com.samskivert.util.StringUtil;
|
|||||||
|
|
||||||
import com.threerings.io.ObjectInputStream;
|
import com.threerings.io.ObjectInputStream;
|
||||||
import com.threerings.io.ObjectOutputStream;
|
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.AccessController;
|
||||||
import com.threerings.presents.dobj.AttributeChangeListener;
|
import com.threerings.presents.dobj.AttributeChangeListener;
|
||||||
@@ -221,12 +221,7 @@ public abstract class ConfigRegistry
|
|||||||
public void attributeChanged (AttributeChangedEvent event)
|
public void attributeChanged (AttributeChangedEvent event)
|
||||||
{
|
{
|
||||||
// mirror this configuration update to the persistent config
|
// mirror this configuration update to the persistent config
|
||||||
Object value = event.getValue();
|
updateValue(event.getName(), event.getValue());
|
||||||
if (value instanceof DSet<?>) {
|
|
||||||
serializeAttribute(event.getName());
|
|
||||||
} else {
|
|
||||||
updateValue(event.getName(), value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateValue (String name, Object value)
|
protected void updateValue (String name, Object value)
|
||||||
@@ -254,6 +249,8 @@ public abstract class ConfigRegistry
|
|||||||
setValue(key, (String[])value);
|
setValue(key, (String[])value);
|
||||||
} else if (value instanceof long[]) {
|
} else if (value instanceof long[]) {
|
||||||
setValue(key, (long[])value);
|
setValue(key, (long[])value);
|
||||||
|
} else if (value == null || Streamer.isStreamable(value.getClass())) {
|
||||||
|
serializeAttribute(name);
|
||||||
} else {
|
} else {
|
||||||
log.info("Unable to flush config obj change", "cobj", object.getClass().getName(),
|
log.info("Unable to flush config obj change", "cobj", object.getClass().getName(),
|
||||||
"key", key, "type", value.getClass().getName(), "value", value);
|
"key", key, "type", value.getClass().getName(), "value", value);
|
||||||
@@ -314,7 +311,7 @@ public abstract class ConfigRegistry
|
|||||||
long[] defval = (long[])field.get(object);
|
long[] defval = (long[])field.get(object);
|
||||||
field.set(object, getValue(key, defval));
|
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.
|
// don't freak out if the conf is blank.
|
||||||
String value = getValue(key, "");
|
String value = getValue(key, "");
|
||||||
if (StringUtil.isBlank(value)) {
|
if (StringUtil.isBlank(value)) {
|
||||||
@@ -363,7 +360,7 @@ public abstract class ConfigRegistry
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value instanceof Streamable) {
|
if (value == null || Streamer.isStreamable(value.getClass())) {
|
||||||
serialize(attributeName, key, value);
|
serialize(attributeName, key, value);
|
||||||
} else {
|
} else {
|
||||||
log.info("Unable to flush config obj change", "cobj", object.getClass().getName(),
|
log.info("Unable to flush config obj change", "cobj", object.getClass().getName(),
|
||||||
|
|||||||
@@ -60,6 +60,9 @@ public class Streamer
|
|||||||
*/
|
*/
|
||||||
public synchronized static boolean isStreamable (Class<?> target)
|
public synchronized static boolean isStreamable (Class<?> target)
|
||||||
{
|
{
|
||||||
|
// if we have not yet initialized ourselves, do so now
|
||||||
|
maybeInit();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// if we've got a streamer for it, it's good
|
// if we've got a streamer for it, it's good
|
||||||
if (_streamers.containsKey(target)) {
|
if (_streamers.containsKey(target)) {
|
||||||
@@ -108,9 +111,7 @@ public class Streamer
|
|||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
// if we have not yet initialized ourselves, do so now
|
// if we have not yet initialized ourselves, do so now
|
||||||
if (_streamers == null) {
|
maybeInit();
|
||||||
_streamers = Maps.newHashMap(BasicStreamers.BSTREAMERS);
|
|
||||||
}
|
|
||||||
|
|
||||||
Streamer stream = _streamers.get(target);
|
Streamer stream = _streamers.get(target);
|
||||||
if (stream == null) {
|
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. */
|
/** Used to coerce the type system into quietude when reading enums from the wire. */
|
||||||
protected static enum EnumReader implements ByteEnum {
|
protected static enum EnumReader implements ByteEnum {
|
||||||
NOT_USED;
|
NOT_USED;
|
||||||
|
|||||||
Reference in New Issue
Block a user