Make a note of when we started our session and when we most recently

connected or disconnected. Use this to determine if a client has "expired"
(meaning they've been disconnected for too long).


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1871 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-10-31 21:03:57 +00:00
parent 2f7399ed68
commit 79259479c6
@@ -1,5 +1,5 @@
//
// $Id: PresentsClient.java,v 1.42 2002/10/26 02:40:30 shaper Exp $
// $Id: PresentsClient.java,v 1.43 2002/10/31 21:03:57 mdb Exp $
package com.threerings.presents.server;
@@ -81,6 +81,33 @@ public class PresentsClient
return _creds;
}
/**
* Returns true if this client has been disconnected for sufficiently
* long that its session should be forcibly ended.
*/
public boolean checkExpired (long now)
{
return (getConnection() == null && (now - _networkStamp > FLUSH_TIME));
}
/**
* Returns the time at which this client started their network
* session.
*/
public long getSessionStamp ()
{
return _sessionStamp;
}
/**
* Returns the time at which this client most recently connected or
* disconnected.
*/
public long getNetworkStamp ()
{
return _networkStamp;
}
/**
* Returns the username with which this client instance is associated.
*/
@@ -213,6 +240,9 @@ public class PresentsClient
// resolve our client object before we get fully underway
cmgr.resolveClientObject(_username, this);
// make a note of our session start time
_sessionStamp = System.currentTimeMillis();
}
/**
@@ -527,6 +557,9 @@ public class PresentsClient
if (_conn != null) {
_conn.setMessageHandler(this);
}
// make a note that our network status changed
_networkStamp = System.currentTimeMillis();
}
/**
@@ -740,6 +773,17 @@ public class PresentsClient
protected static HashMap _disps = new HashMap();
/** The time at which this client started their session. */
protected long _sessionStamp;
/** The time at which this client most recently connected or
* disconnected. */
protected long _networkStamp;
/** 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;
// register our message dispatchers
static {
_disps.put(SubscribeRequest.class, new SubscribeDispatcher());