mirror of
https://gitlab.com/mangadex-pub/mangadex_at_home.git
synced 2024-01-19 02:48:37 +00:00
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 state = this.state
|
val latch = CountDownLatch(1)
|
||||||
if (state is Running) {
|
executorService.schedule({
|
||||||
val latch = CountDownLatch(1)
|
val state = this.state
|
||||||
|
if (state is Running) {
|
||||||
this.state = GracefulShutdown(state, nextState = Shutdown) {
|
this.state = GracefulShutdown(state, nextState = Shutdown) {
|
||||||
webUi?.close()
|
latch.countDown()
|
||||||
try {
|
|
||||||
cache.close()
|
|
||||||
} catch (e: IOException) {
|
|
||||||
LOGGER.error("Cache failed to close", e)
|
|
||||||
}
|
}
|
||||||
|
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()
|
latch.countDown()
|
||||||
}
|
}
|
||||||
latch.await()
|
}, 0, TimeUnit.SECONDS)
|
||||||
|
latch.await()
|
||||||
|
|
||||||
|
webUi?.close()
|
||||||
|
try {
|
||||||
|
cache.close()
|
||||||
|
} catch (e: IOException) {
|
||||||
|
LOGGER.error("Cache failed to close", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
executorService.shutdown()
|
executorService.shutdown()
|
||||||
LOGGER.info("Mangadex@Home Client stopped")
|
LOGGER.info("Mangadex@Home Client stopped")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue