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: Client.java,v 1.50 2004/10/18 21:40:24 mdb Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -188,6 +188,18 @@ public class Client
_version = version;
}
/**
* Configures the client with a custom class loader which will be used
* when reading objects off of the network.
*/
public void setClassLoader (ClassLoader loader)
{
_loader = loader;
if (_comm != null) {
_comm.setClassLoader(loader);
}
}
/**
* Returns the data associated with our authentication response. Users
* of the Presents system may wish to communicate authentication
@@ -352,6 +364,7 @@ public class Client
// otherwise create a new communicator instance and start it up.
// this will initiate the logon process
_comm = new Communicator(this);
_comm.setClassLoader(_loader);
_comm.logon();
// register an interval that we'll use to keep the clock synced
@@ -688,6 +701,10 @@ public class Client
/** The entity that manages our network communications. */
protected Communicator _comm;
/** A custom class loader used to load objects that come in over the
* network. */
protected ClassLoader _loader = getClass().getClassLoader();
/** General startup information provided by the server. */
protected BootstrapData _bstrap;
@@ -1,5 +1,5 @@
//
// $Id: Communicator.java,v 1.36 2004/10/21 23:36:27 mdb Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -162,6 +162,18 @@ public class Communicator
_msgq.append(msg);
}
/**
* Configures this communicator with a custom class loader to be used
* when reading and writing objects over the network.
*/
public void setClassLoader (ClassLoader loader)
{
_loader = loader;
if (_oin != null) {
_oin.setClassLoader(loader);
}
}
/**
* Callback called by the reader when the authentication process
* completes successfully. Here we extract the bootstrap information
@@ -439,6 +451,7 @@ public class Communicator
// create our object input and output streams
_oin = new ObjectInputStream(_fin);
_oin.setClassLoader(_loader);
_oout = new ObjectOutputStream(_fout);
}
@@ -600,6 +613,7 @@ public class Communicator
protected ObjectInputStream _oin;
protected ClientDObjectMgr _omgr;
protected ClassLoader _loader;
/** Used to control low-level message logging. */
protected static RuntimeAdjust.BooleanAdjust _logMessages =