Added facilities for idling out clients that have not communicated with
the server in 90 seconds. The client is set up to ping the server if it has had nothing to say to it for other reasons in the last 60 seconds. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1860 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: Client.java,v 1.32 2002/10/21 18:04:56 mdb Exp $
|
||||
// $Id: Client.java,v 1.33 2002/10/29 23:51:26 mdb Exp $
|
||||
|
||||
package com.threerings.presents.client;
|
||||
|
||||
@@ -224,8 +224,9 @@ public class Client
|
||||
{
|
||||
InvocationService isvc = getService(sclass);
|
||||
if (isvc == null) {
|
||||
throw new RuntimeException(sclass.getName() + " isn't available. " +
|
||||
"I can't bear to go on.");
|
||||
throw new RuntimeException(
|
||||
sclass.getName() + " isn't available. " +
|
||||
"I can't bear to go on.");
|
||||
}
|
||||
return isvc;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: Communicator.java,v 1.21 2002/07/23 05:52:48 mdb Exp $
|
||||
// $Id: Communicator.java,v 1.22 2002/10/29 23:51:26 mdb Exp $
|
||||
|
||||
package com.threerings.presents.client;
|
||||
|
||||
@@ -13,6 +13,8 @@ import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
|
||||
import com.samskivert.io.NestableIOException;
|
||||
import com.samskivert.util.Interval;
|
||||
import com.samskivert.util.IntervalManager;
|
||||
import com.samskivert.util.LoopingThread;
|
||||
import com.samskivert.util.Queue;
|
||||
|
||||
@@ -84,6 +86,16 @@ public class Communicator
|
||||
// start up the writer thread if everything went successfully
|
||||
_reader = new Reader();
|
||||
_reader.start();
|
||||
|
||||
// register an interval to send pings when appropriate
|
||||
_piid = IntervalManager.register(new Interval() {
|
||||
public void intervalExpired (int id, Object arg) {
|
||||
if (checkNeedsPing()) {
|
||||
Log.info("Upstream idle, sending ping.");
|
||||
postMessage(new PingRequest());
|
||||
}
|
||||
}
|
||||
}, 5000L, null, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,6 +111,11 @@ public class Communicator
|
||||
return;
|
||||
}
|
||||
|
||||
// stop our ping interval
|
||||
if (_piid != -1) {
|
||||
IntervalManager.remove(_piid);
|
||||
}
|
||||
|
||||
// post a logoff message
|
||||
postMessage(new LogoffRequest());
|
||||
|
||||
@@ -263,6 +280,28 @@ public class Communicator
|
||||
|
||||
// then write the framed message to actual output stream
|
||||
_fout.writeFrameAndReset(_out);
|
||||
|
||||
// make a note of our most recent write time
|
||||
updateWriteStamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a note of the time at which we last communicated with the
|
||||
* server.
|
||||
*/
|
||||
protected synchronized void updateWriteStamp ()
|
||||
{
|
||||
_lastWrite = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if we need to send a ping to the server because we
|
||||
* haven't communicated in sufficiently long.
|
||||
*/
|
||||
protected synchronized boolean checkNeedsPing ()
|
||||
{
|
||||
long now = System.currentTimeMillis();
|
||||
return (now - _lastWrite > PingRequest.PING_INTERVAL);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -507,6 +546,9 @@ public class Communicator
|
||||
protected OutputStream _out;
|
||||
protected Queue _msgq = new Queue();
|
||||
|
||||
protected int _piid;
|
||||
protected long _lastWrite;
|
||||
|
||||
/** We use this to frame our upstream messages. */
|
||||
protected FramingOutputStream _fout;
|
||||
protected ObjectOutputStream _oout;
|
||||
|
||||
Reference in New Issue
Block a user