Added a NotStreamable annotation. Streamable objects that have fields annotated with NotStreamable will not have those fields sent over the wire, at least by the default readObject()/writeObject() Streamer methods.

Currently, Streamer will skip fields marked transient for the purposes of the default streaming implementation, but 'transient' is also used by the Java serialization mechanism, and there are instances where a field in a Serializable, Streamable object can't be streamed but should be serialized.

I have a bunch of code to check in related to the game server sending stat updates to the world server, but I'm going to hold off on those changes until I get the go-ahead from the powers that be that this is an acceptable solution to the problem.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5270 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Tom Conkling
2008-07-30 00:04:06 +00:00
parent 97e91dbb84
commit 7a1ede64af
2 changed files with 55 additions and 1 deletions
@@ -0,0 +1,36 @@
//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2007 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.io;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation specifies that the property or field is not Streamable.
*/
@Target(value=ElementType.FIELD)
@Retention(value=RetentionPolicy.RUNTIME)
public @interface NotStreamable
{
}
+19 -1
View File
@@ -32,9 +32,12 @@ import java.security.PrivilegedExceptionAction;
import java.security.PrivilegedActionException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.samskivert.util.ClassUtil;
import com.samskivert.util.Predicate;
import static com.threerings.NaryaLog.log;
@@ -456,7 +459,20 @@ public class Streamer
}
// reflect on all the object's fields
_fields = ClassUtil.getFields(target);
ArrayList<Field> fieldList = new ArrayList<Field>();
ClassUtil.getFields(target, fieldList);
// remove all NotStreamable fields from the list of fields
if (_isStreamableFieldPred == null) {
_isStreamableFieldPred = new Predicate<Field>() {
public boolean isMatch (Field obj) {
return (obj.getAnnotation(NotStreamable.class) == null);
}
};
}
_isStreamableFieldPred.filter(fieldList);
_fields = fieldList.toArray(new Field[fieldList.size()]);
int fcount = _fields.length;
// obtain field marshallers for all of our fields
@@ -505,6 +521,8 @@ public class Streamer
* class. */
protected Method _writer;
protected static Predicate<Field> _isStreamableFieldPred;
/** Contains the mapping from class names to configured streamer instances. */
protected static HashMap<Class, Streamer> _streamers;