keep track of the last time a client started a long polling operation so we can eventually use that to remove dead clients

This commit is contained in:
Andy Janata 2011-12-24 19:35:28 -08:00
parent 10a4d4e62e
commit b73320d614
2 changed files with 14 additions and 0 deletions

View File

@ -57,6 +57,7 @@ public class LongPollServlet extends CahServlet {
final long end = start + TIMEOUT_BASE + (long) (Math.random() * TIMEOUT_RANDOMNESS);
final User user = (User) hSession.getAttribute("user");
assert (user != null);
user.contactedServer();
// TODO we might have to synchronize on the user object?
while (!(user.hasQueuedMessages()) && System.nanoTime() < end) {
try {

View File

@ -15,6 +15,8 @@ public class User {
private final Object queuedMessageSynchronization = new Object();
private long lastHeardFrom = 0;
public User(final String nickname) {
this.nickname = nickname;
queuedMessages = new PriorityBlockingQueue<QueuedMessage>();
@ -63,4 +65,15 @@ public class User {
return nickname;
}
/**
* Update the timestamp that we have last heard from this user to the current time.
*/
public void contactedServer() {
lastHeardFrom = System.nanoTime();
}
public long getLastHeardFrom() {
return lastHeardFrom;
}
}