mirror of
https://gitlab.com/mangadex-pub/mangadex_at_home.git
synced 2024-11-16 16:12:32 +01:00
Fix associated bugs
This commit is contained in:
parent
9d07c18de1
commit
535d21ec8e
@ -28,7 +28,6 @@ import com.fasterxml.jackson.module.kotlin.readValue
|
||||
import java.io.File
|
||||
import java.io.FileReader
|
||||
import java.io.IOException
|
||||
import java.lang.AssertionError
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.regex.Pattern
|
||||
@ -40,6 +39,7 @@ import mdnet.cache.HeaderMismatchException
|
||||
import org.http4k.server.Http4kServer
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
// Exception class to handle when Client Settings have invalid values
|
||||
class ClientSettingsException(message: String) : Exception(message)
|
||||
@ -47,6 +47,8 @@ class ClientSettingsException(message: String) : Exception(message)
|
||||
class MangaDexClient(private val settingsFile: File, databaseFile: File, cacheFolder: File) {
|
||||
// just for scheduling one task, so single-threaded
|
||||
private val executor = Executors.newSingleThreadScheduledExecutor()
|
||||
private val isReloading = AtomicBoolean(false)
|
||||
|
||||
private val database: Database
|
||||
private val cache: DiskLruCache
|
||||
private var settings: ClientSettings
|
||||
@ -89,6 +91,7 @@ class MangaDexClient(private val settingsFile: File, databaseFile: File, cacheFo
|
||||
|
||||
executor.scheduleWithFixedDelay({
|
||||
try {
|
||||
// this blocks the executor, so no worries about concurrency
|
||||
reloadClientSettings()
|
||||
} catch (e: Exception) {
|
||||
LOGGER.warn(e) { "Reload of ClientSettings failed" }
|
||||
@ -104,7 +107,9 @@ class MangaDexClient(private val settingsFile: File, databaseFile: File, cacheFo
|
||||
settings.webSettings?.let { webSettings ->
|
||||
val imageServer = requireNotNull(imageServer)
|
||||
|
||||
if (webUi != null) throw AssertionError()
|
||||
if (webUi != null) {
|
||||
throw AssertionError()
|
||||
}
|
||||
LOGGER.info { "WebUI starting" }
|
||||
webUi = getUiServer(webSettings, imageServer.statistics, imageServer.statsMap).also {
|
||||
it.start()
|
||||
@ -115,7 +120,9 @@ class MangaDexClient(private val settingsFile: File, databaseFile: File, cacheFo
|
||||
|
||||
// Precondition: settings must be filled with up-to-date settings
|
||||
private fun startImageServer() {
|
||||
if (imageServer != null) throw AssertionError()
|
||||
if (imageServer != null) {
|
||||
throw AssertionError()
|
||||
}
|
||||
LOGGER.info { "Server manager starting" }
|
||||
imageServer = ServerManager(settings.serverSettings, settings.devSettings, settings.maxCacheSizeInMebibytes, cache, database).also {
|
||||
it.start()
|
||||
@ -179,7 +186,9 @@ class MangaDexClient(private val settingsFile: File, databaseFile: File, cacheFo
|
||||
|
||||
if (stopWebUi) {
|
||||
LOGGER.info { "Stopping WebUI to reload ClientSettings" }
|
||||
stopWebUi()
|
||||
if(webUi != null) {
|
||||
stopWebUi()
|
||||
}
|
||||
}
|
||||
|
||||
if (restartServer) {
|
||||
|
Loading…
Reference in New Issue
Block a user