-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.kt
51 lines (44 loc) · 1.3 KB
/
App.kt
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
45
46
47
48
49
50
51
package com.numberlogger
import com.google.inject.Guice
import com.google.inject.Injector
import org.slf4j.LoggerFactory
import javax.inject.Inject
import kotlin.system.exitProcess
class App @Inject constructor(
private val server: Server,
private val numberClient: NumberLocalFileClient,
private val reporter: Reporter
) : Runnable {
private var isShuttingDown = false
override fun run() {
numberClient.run()
server.run(this)
reporter.run()
}
fun shutdown() {
log.info("Shutting down app")
isShuttingDown = true
server.stop()
reporter.close()
numberClient.close()
}
fun isShuttingDown() { isShuttingDown }
}
private val log = LoggerFactory.getLogger(object {}::class.java.`package`.name)
fun main() {
try {
val config = NumberLogAppConfig(
filePath = "src/main/resources/numbers.log",
maxConnections = 5,
reportEveryNMillis = 10000,
flushBufferEveryNMillis = 1,
serverPort = 4000)
val module = NumberLogModule(config)
val injector: Injector = Guice.createInjector(module)
val app = injector.getInstance(App::class.java)
app.run()
} catch (t: Throwable) {
log.error(t.message, t)
exitProcess(1)
}
}