/
ThreadPing.scala
44 lines (38 loc) · 1.31 KB
/
ThreadPing.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package engine
import play.api.Logger
import collection.mutable.ArrayBuffer
import models.ConnectionTable
object ThreadPing {
def sweepAll = {
ConnectionTable.foreach {
table =>
val closeForTimeout = new ArrayBuffer[String]
val closeForAuthorizedTime = new ArrayBuffer[String]
table.foreach {
case (id, extConn) =>
val now = new java.util.Date()
if (now.getTime - extConn.lastAccessDate.getTime > 1000 * extConn.timeout) {
closeForTimeout += id
}
else if (extConn.authorizedTime > 0 &&
now.getTime - extConn.creationDate.getTime > 1000 * extConn.authorizedTime) {
closeForAuthorizedTime += id
}
}
closeForTimeout.foreach {
id =>
Logger.info("Closed connection " + id + " : Timeout reached...")
val extConn = table.get(id)
extConn.map(_.connectionActor ! ConnectionActor.Disconnect)
table.remove(id)
}
closeForAuthorizedTime.foreach {
id =>
Logger.info("Closed connection " + id + " : Maximum time reached...")
val extConn = table.get(id)
extConn.map(_.connectionActor ! ConnectionActor.Disconnect)
table.remove(id)
}
}
}
}