The rabbit hole goes deeper. Now we can configure the client with a custom

classloader to use when unserializing objects off the network. Also fixed
the way custom classloaders were used as Class.forName(class, true,
loader) seems to be the proper way to go to have caching work and whatnot.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3268 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2004-12-10 01:23:44 +00:00
parent f16beaa0a1
commit c92a922678
4 changed files with 49 additions and 5 deletions
@@ -1,5 +1,5 @@
//
// $Id: ObjectInputStream.java,v 1.4 2004/08/27 02:12:36 mdb Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -48,6 +48,15 @@ public class ObjectInputStream extends DataInputStream
super(source);
}
/**
* Customizes the class loader used to instnatiate objects read from
* the input stream.
*/
public void setClassLoader (ClassLoader loader)
{
_loader = loader;
}
/**
* Reads a {@link Streamable} instance or one of the supported object
* types from the input stream.
@@ -82,7 +91,7 @@ public class ObjectInputStream extends DataInputStream
// read in the class metadata, create a class mapping record
// for the class, and cache it
String cname = readUTF();
Class sclass = Class.forName(cname);
Class sclass = Class.forName(cname, true, _loader);
Streamer streamer = Streamer.getStreamer(sclass);
if (STREAM_DEBUG) {
Log.info(hashCode() + ": New class '" + cname + "'.");
@@ -209,6 +218,9 @@ public class ObjectInputStream extends DataInputStream
/** The streamer being used currently. */
protected Streamer _streamer;
/** The class loader we use to instantiate objects. */
protected ClassLoader _loader = getClass().getClassLoader();
/** Used to activate verbose debug logging. */
protected static final boolean STREAM_DEBUG = false;
}