1
0
Fork 1
mirror of https://gitlab.com/mangadex-pub/mangadex_at_home.git synced 2024-01-19 02:48:37 +00:00

Fix minor pathological cases

This commit is contained in:
carbotaniuman 2020-08-11 14:35:34 -05:00
parent 535d21ec8e
commit af73354d4f
2 changed files with 19 additions and 16 deletions

View file

@ -45,16 +45,17 @@ import java.util.concurrent.atomic.AtomicBoolean
class ClientSettingsException(message: String) : Exception(message)
class MangaDexClient(private val settingsFile: File, databaseFile: File, cacheFolder: File) {
// just for scheduling one task, so single-threaded
// this must remain single-threaded because of how the state mechanism works
private val executor = Executors.newSingleThreadScheduledExecutor()
private val isReloading = AtomicBoolean(false)
private val database: Database
private val cache: DiskLruCache
private var settings: ClientSettings
// state that must only be accessed from the thread on the executor
private var imageServer: ServerManager? = null
private var webUi: Http4kServer? = null
// end protected state
init {
settings = try {
@ -145,20 +146,22 @@ class MangaDexClient(private val settingsFile: File, databaseFile: File, cacheFo
}
fun shutdown() {
LOGGER.info { "Mangadex@Home Client shutting down" }
if (webUi != null) {
stopWebUi()
}
if (imageServer != null) {
stopImageServer()
}
LOGGER.info { "Mangadex@Home Client has shut down" }
executor.schedule({
LOGGER.info { "Mangadex@Home Client shutting down" }
if (webUi != null) {
stopWebUi()
}
if (imageServer != null) {
stopImageServer()
}
LOGGER.info { "Mangadex@Home Client has shut down" }
try {
cache.close()
} catch (e: IOException) {
LOGGER.error(e) { "Cache failed to close" }
}
try {
cache.close()
} catch (e: IOException) {
LOGGER.error(e) { "Cache failed to close" }
}
}, 0, TimeUnit.SECONDS)
}
/**

View file

@ -37,7 +37,7 @@ class ServerManager(serverSettings: ServerSettings, devSettings: DevSettings, ma
// this must remain single-threaded because of how the state mechanism works
private val executor = Executors.newSingleThreadScheduledExecutor()
// state that must only be accessed from the thread on the executorService
// state that must only be accessed from the thread on the executor
private var state: State
private var serverHandler: ServerHandler
// end protected state