diff --git a/src/net/socialgamer/cah/LongPollServlet.java b/src/net/socialgamer/cah/LongPollServlet.java index 5b60f27..218bbdd 100644 --- a/src/net/socialgamer/cah/LongPollServlet.java +++ b/src/net/socialgamer/cah/LongPollServlet.java @@ -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 { diff --git a/src/net/socialgamer/cah/data/User.java b/src/net/socialgamer/cah/data/User.java index 7a67b24..8bb1d2d 100644 --- a/src/net/socialgamer/cah/data/User.java +++ b/src/net/socialgamer/cah/data/User.java @@ -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(); @@ -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; + } + }