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:
parent
10a4d4e62e
commit
b73320d614
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue