More custom classloader support. We now have a proof-of-concept working so

it's unlikely that the rabbit hole will surprise us with further depth.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3269 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2004-12-10 02:54:26 +00:00
parent c92a922678
commit a6d7764e29
5 changed files with 87 additions and 30 deletions
@@ -1,5 +1,5 @@
//
// $Id: PresentsClient.java,v 1.69 2004/10/27 01:27:44 mdb Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -147,6 +147,19 @@ public class PresentsClient
return (conn == null) ? null : conn.getInetAddress();
}
/**
* Configures this client with a custom class loader that will be used
* when unserializing classes from the network.
*/
public void setClassLoader (ClassLoader loader)
{
_loader = loader;
Connection conn = getConnection();
if (conn != null) {
conn.setClassLoader(loader);
}
}
/**
* <em>Danger:</em> this method is not for general consumption. This
* changes the username of the client, but should only be done very
@@ -660,6 +673,11 @@ public class PresentsClient
// a connection rather than clearing one out)
if (_conn != null) {
_conn.setMessageHandler(this);
// configure any active custom class loader
if (_loader != null) {
_conn.setClassLoader(_loader);
}
}
// make a note that our network status changed
@@ -897,8 +915,7 @@ public class PresentsClient
protected Connection _conn;
protected ClientObject _clobj;
protected HashIntMap _subscrips = new HashIntMap();
protected static HashMap _disps = new HashMap();
protected ClassLoader _loader;
/** The time at which this client started their session. */
protected long _sessionStamp;
@@ -916,6 +933,9 @@ public class PresentsClient
protected int _messagesOut;
protected int _messagesDropped;
/** A mapping of message dispatchers. */
protected static HashMap _disps = new HashMap();
/** The amount of time after disconnection a user is allowed before
* their session is forcibly ended. */
protected static final long FLUSH_TIME = 7 * 60 * 1000L;
@@ -1,5 +1,5 @@
//
// $Id: Connection.java,v 1.20 2004/08/27 02:20:24 mdb Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -80,6 +80,17 @@ public abstract class Connection implements NetEventHandler
_handler = handler;
}
/**
* Configures this connection with a custom class loader.
*/
public void setClassLoader (ClassLoader loader)
{
_loader = loader;
if (_oin != null) {
_oin.setClassLoader(loader);
}
}
/**
* Returns the selection key associated with our socket channel.
*/
@@ -175,6 +186,9 @@ public abstract class Connection implements NetEventHandler
_fin = other._fin;
_oin = other._oin;
_oout = other._oout;
if (_loader != null) {
_oin.setClassLoader(_loader);
}
}
/**
@@ -242,6 +256,9 @@ public abstract class Connection implements NetEventHandler
if (_fin == null) {
_fin = new FramedInputStream();
_oin = new ObjectInputStream(_fin);
if (_loader != null) {
_oin.setClassLoader(_loader);
}
}
// there may be more than one frame in the buffer, so we keep
@@ -318,10 +335,10 @@ public abstract class Connection implements NetEventHandler
protected FramedInputStream _fin;
protected ObjectInputStream _oin;
protected ObjectOutputStream _oout;
protected MessageHandler _handler;
protected ClassLoader _loader;
/** The number of milliseconds beyond the ping interval that we allow
* a client's network connection to be idle before we forcibly