Update a pathological case
This commit is contained in:
parent
6efff4ce40
commit
2c4cfefb94
|
@ -36,6 +36,7 @@ data class Running(val server: Http4kServer, val settings: ServerSettings) : Sta
|
||||||
class MangaDexClient(private val clientSettings: ClientSettings) {
|
class MangaDexClient(private val clientSettings: ClientSettings) {
|
||||||
// this must remain singlethreaded because of how the state mechanism works
|
// this must remain singlethreaded because of how the state mechanism works
|
||||||
private val executorService = Executors.newSingleThreadScheduledExecutor()
|
private val executorService = Executors.newSingleThreadScheduledExecutor()
|
||||||
|
// state must only be accessed from the thread on the executorService
|
||||||
private var state: State = Uninitialized
|
private var state: State = Uninitialized
|
||||||
|
|
||||||
private val serverHandler: ServerHandler = ServerHandler(clientSettings)
|
private val serverHandler: ServerHandler = ServerHandler(clientSettings)
|
||||||
|
@ -260,21 +261,32 @@ class MangaDexClient(private val clientSettings: ClientSettings) {
|
||||||
fun shutdown() {
|
fun shutdown() {
|
||||||
LOGGER.info("Mangadex@Home Client stopping")
|
LOGGER.info("Mangadex@Home Client stopping")
|
||||||
|
|
||||||
|
val latch = CountDownLatch(1)
|
||||||
|
executorService.schedule({
|
||||||
val state = this.state
|
val state = this.state
|
||||||
if (state is Running) {
|
if (state is Running) {
|
||||||
val latch = CountDownLatch(1)
|
|
||||||
|
|
||||||
this.state = GracefulShutdown(state, nextState = Shutdown) {
|
this.state = GracefulShutdown(state, nextState = Shutdown) {
|
||||||
|
latch.countDown()
|
||||||
|
}
|
||||||
|
latch.await()
|
||||||
|
} else if (state is GracefulShutdown) {
|
||||||
|
this.state = state.copy(nextState = Shutdown) {
|
||||||
|
latch.countDown()
|
||||||
|
}
|
||||||
|
} else if (state is Uninitialized || state is Shutdown) {
|
||||||
|
this.state = Shutdown
|
||||||
|
latch.countDown()
|
||||||
|
}
|
||||||
|
}, 0, TimeUnit.SECONDS)
|
||||||
|
latch.await()
|
||||||
|
|
||||||
webUi?.close()
|
webUi?.close()
|
||||||
try {
|
try {
|
||||||
cache.close()
|
cache.close()
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
LOGGER.error("Cache failed to close", e)
|
LOGGER.error("Cache failed to close", e)
|
||||||
}
|
}
|
||||||
latch.countDown()
|
|
||||||
}
|
|
||||||
latch.await()
|
|
||||||
}
|
|
||||||
executorService.shutdown()
|
executorService.shutdown()
|
||||||
LOGGER.info("Mangadex@Home Client stopped")
|
LOGGER.info("Mangadex@Home Client stopped")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue