@@ -18,9 +18,6 @@ object GhService {
18
18
19
19
private val log = LoggerFactory .getLogger(GhService .javaClass)
20
20
21
- // Allows for parallel iteration and O(1) put/remove
22
- private val clientSessions = ConcurrentHashMap <WsSession , Boolean >()
23
-
24
21
private val tokens = Config .getApiTokens()?.split(" ," ) ? : listOf (" " ) // empty token is limited to 60 requests
25
22
private val clients = tokens.map { GitHubClient ().apply { setOAuth2Token(it) } }
26
23
private val repoServices = clients.map { RepositoryService (it) }
@@ -35,8 +32,9 @@ object GhService {
35
32
36
33
val remainingRequests: Int get() = clients.sumBy { it.remainingRequests }
37
34
35
+ // Allows for parallel iteration and O(1) put/remove
36
+ private val clientSessions = ConcurrentHashMap <WsSession , Boolean >()
38
37
fun registerClient (ws : WsSession ) = clientSessions.put(ws, true ) == true
39
-
40
38
fun unregisterClient (ws : WsSession ) = clientSessions.remove(ws) == true
41
39
42
40
init {
@@ -56,13 +54,11 @@ object GhService {
56
54
57
55
// update all connected clients with remainingRequests twice per second
58
56
scheduleAtFixedRate({
59
- val payload = remainingRequests.toString()
60
57
clientSessions.forEachKey(1 ) {
61
58
try {
62
- if (it.isOpen)
63
- it.send(payload)
64
- } catch (e: IOException ) {
65
- log?.error(e.toString())
59
+ it.send(remainingRequests.toString())
60
+ } catch (e: Exception ) {
61
+ log.error(e.toString())
66
62
}
67
63
}
68
64
}, 0 , 500 , TimeUnit .MILLISECONDS )
0 commit comments