Created ServerCommunicator which does all I/O using the ConnectionManager's

polled socket system. This much more cleanly and efficiently integrates peer
(and other server to server) connections into the normal server I/O framework
and should also eliminate for good the annoying server hangs that result when
our old blocking client I/O threads got their pants wedged.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5510 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2008-11-07 00:27:07 +00:00
parent b81ccde75b
commit 89f02fc728
16 changed files with 777 additions and 594 deletions
@@ -21,6 +21,9 @@
package com.threerings.presents.client;
import com.threerings.presents.net.AuthResponse;
import com.threerings.presents.net.AuthResponseData;
import com.threerings.presents.net.Message;
import com.threerings.presents.net.UpstreamMessage;
/**
@@ -66,7 +69,70 @@ public abstract class Communicator
/**
* Returns the time at which we last sent a packet to the server.
*/
public abstract long getLastWrite ();
public long getLastWrite ()
{
return _lastWrite;
}
/**
* Makes a note of the time at which we last communicated with the server.
*/
protected synchronized void updateWriteStamp ()
{
_lastWrite = System.currentTimeMillis();
}
/**
* Subclasses must call this method when they receive the authentication response.
*/
protected void gotAuthResponse (AuthResponse rsp)
throws LogonException
{
AuthResponseData data = rsp.getData();
if (!data.code.equals(AuthResponseData.SUCCESS)) {
throw new LogonException(data.code);
}
logonSucceeded(data);
}
/**
* Called when the authentication process completes successfully. Derived classes can override
* this method and complete any initialization that need wait for authentication success.
*/
protected synchronized void logonSucceeded (AuthResponseData data)
{
// create our distributed object manager
_omgr = new ClientDObjectMgr(this, _client);
// fill the auth data into the client's local field so that it can be requested by external
// entities
_client._authData = data;
// wait for the bootstrap notification before we claim that we're actually logged on
}
/**
* Callback called by the reader thread when it has parsed a new message from the socket and
* wishes to have it processed.
*/
protected void processMessage (Message msg)
{
// post this message to the dobjmgr queue
_omgr.processMessage(msg);
}
protected void notifyClientObservers (ObserverOps.Session op)
{
_client.notifyObservers(op);
}
protected void clientCleanup (Exception logonError)
{
_client.cleanup(logonError);
_client = null; // prevent any post-cleanup tomfoolery
}
protected Client _client;
protected ClientDObjectMgr _omgr;
protected long _lastWrite;
}