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 ClientSettingsException(message: String) : Exception(message)
class MangaDexClient(private val settingsFile: File, databaseFile: File, cacheFolder: File) { 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 executor = Executors.newSingleThreadScheduledExecutor()
private val isReloading = AtomicBoolean(false)
private val database: Database private val database: Database
private val cache: DiskLruCache private val cache: DiskLruCache
private var settings: ClientSettings private var settings: ClientSettings
// state that must only be accessed from the thread on the executor
private var imageServer: ServerManager? = null private var imageServer: ServerManager? = null
private var webUi: Http4kServer? = null private var webUi: Http4kServer? = null
// end protected state
init { init {
settings = try { settings = try {
@ -145,6 +146,7 @@ class MangaDexClient(private val settingsFile: File, databaseFile: File, cacheFo
} }
fun shutdown() { fun shutdown() {
executor.schedule({
LOGGER.info { "Mangadex@Home Client shutting down" } LOGGER.info { "Mangadex@Home Client shutting down" }
if (webUi != null) { if (webUi != null) {
stopWebUi() stopWebUi()
@ -159,6 +161,7 @@ class MangaDexClient(private val settingsFile: File, databaseFile: File, cacheFo
} catch (e: IOException) { } catch (e: IOException) {
LOGGER.error(e) { "Cache failed to close" } 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 // this must remain single-threaded because of how the state mechanism works
private val executor = Executors.newSingleThreadScheduledExecutor() 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 state: State
private var serverHandler: ServerHandler private var serverHandler: ServerHandler
// end protected state // end protected state