Refactored communicator so that we can not do some things in the peer client

(which runs on the server) that we do in a normal client (which runs on a
user's computer). Eventually we'll make a custom Communicator for use on the
server that integrates with the ConnectionManager's polled socket I/O which
will be easier now that this bit of factoring has been done.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4835 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2007-10-01 23:44:31 +00:00
parent 120d641dea
commit ab632ffe83
4 changed files with 773 additions and 615 deletions
@@ -379,7 +379,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 = createCommunicator();
_comm.setClassLoader(_loader);
_comm.logon();
@@ -491,7 +491,9 @@ public class Client
*/
protected void gotBootstrap (BootstrapData data, DObjectManager omgr)
{
log.fine("Got bootstrap " + data + ".");
if (debugLogMessages()) {
log.info("Got bootstrap " + data + ".");
}
// keep these around for interested parties
_bstrap = data;
@@ -521,6 +523,14 @@ public class Client
// nothing by default
}
/**
* Creates the communicator that this client will use to send and receive messages.
*/
protected Communicator createCommunicator ()
{
return new ClientCommunicator(this);
}
/**
* Called every five seconds; ensures that we ping the server if we haven't communicated in a
* long while and periodically resyncs the client and server clock deltas.
@@ -536,7 +546,9 @@ public class Client
if (_dcalc != null) {
// if our current calculator is done, clear it out
if (_dcalc.isDone()) {
log.fine("Time offset from server: " + _serverDelta + "ms.");
if (debugLogMessages()) {
log.info("Time offset from server: " + _serverDelta + "ms.");
}
_dcalc = null;
} else if (_dcalc.shouldSendPing()) {
// otherwise, send another ping
@@ -692,6 +704,17 @@ public class Client
}
}
/**
* Whether or not to log low-level debug messages. This is used by the communicator as well
* which may be running on the server as a peer client, so we want to avoid constructing log
* messages when we're not logging and thus need to use this pattern rather than just
* <code>log.fine</code>.
*/
protected boolean debugLogMessages ()
{
return false;
}
/**
* Used to notify client observers of events.
*/