Fix minor pathological cases
This commit is contained in:
parent
535d21ec8e
commit
af73354d4f
|
@ -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,20 +146,22 @@ class MangaDexClient(private val settingsFile: File, databaseFile: File, cacheFo
|
||||||
}
|
}
|
||||||
|
|
||||||
fun shutdown() {
|
fun shutdown() {
|
||||||
LOGGER.info { "Mangadex@Home Client shutting down" }
|
executor.schedule({
|
||||||
if (webUi != null) {
|
LOGGER.info { "Mangadex@Home Client shutting down" }
|
||||||
stopWebUi()
|
if (webUi != null) {
|
||||||
}
|
stopWebUi()
|
||||||
if (imageServer != null) {
|
}
|
||||||
stopImageServer()
|
if (imageServer != null) {
|
||||||
}
|
stopImageServer()
|
||||||
LOGGER.info { "Mangadex@Home Client has shut down" }
|
}
|
||||||
|
LOGGER.info { "Mangadex@Home Client has shut down" }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cache.close()
|
cache.close()
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
LOGGER.error(e) { "Cache failed to close" }
|
LOGGER.error(e) { "Cache failed to close" }
|
||||||
}
|
}
|
||||||
|
}, 0, TimeUnit.SECONDS)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue