@@ -18,9 +18,6 @@ object GhService {
1818
1919 private val log = LoggerFactory .getLogger(GhService .javaClass)
2020
21- // Allows for parallel iteration and O(1) put/remove
22- private val clientSessions = ConcurrentHashMap <WsSession , Boolean >()
23-
2421 private val tokens = Config .getApiTokens()?.split(" ," ) ? : listOf (" " ) // empty token is limited to 60 requests
2522 private val clients = tokens.map { GitHubClient ().apply { setOAuth2Token(it) } }
2623 private val repoServices = clients.map { RepositoryService (it) }
@@ -35,8 +32,9 @@ object GhService {
3532
3633 val remainingRequests: Int get() = clients.sumBy { it.remainingRequests }
3734
35+ // Allows for parallel iteration and O(1) put/remove
36+ private val clientSessions = ConcurrentHashMap <WsSession , Boolean >()
3837 fun registerClient (ws : WsSession ) = clientSessions.put(ws, true ) == true
39-
4038 fun unregisterClient (ws : WsSession ) = clientSessions.remove(ws) == true
4139
4240 init {
@@ -56,13 +54,11 @@ object GhService {
5654
5755 // update all connected clients with remainingRequests twice per second
5856 scheduleAtFixedRate({
59- val payload = remainingRequests.toString()
6057 clientSessions.forEachKey(1 ) {
6158 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())
6662 }
6763 }
6864 }, 0 , 500 , TimeUnit .MILLISECONDS )
0 commit comments