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.File
|
||||||
import java.io.FileReader
|
import java.io.FileReader
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.lang.AssertionError
|
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
@ -40,6 +39,7 @@ import mdnet.cache.HeaderMismatchException
|
||||||
import org.http4k.server.Http4kServer
|
import org.http4k.server.Http4kServer
|
||||||
import org.jetbrains.exposed.sql.Database
|
import org.jetbrains.exposed.sql.Database
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
// Exception class to handle when Client Settings have invalid values
|
// Exception class to handle when Client Settings have invalid values
|
||||||
class ClientSettingsException(message: String) : Exception(message)
|
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) {
|
class MangaDexClient(private val settingsFile: File, databaseFile: File, cacheFolder: File) {
|
||||||
// just for scheduling one task, so single-threaded
|
// just for scheduling one task, so single-threaded
|
||||||
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
|
||||||
|
@ -89,6 +91,7 @@ class MangaDexClient(private val settingsFile: File, databaseFile: File, cacheFo
|
||||||
|
|
||||||
executor.scheduleWithFixedDelay({
|
executor.scheduleWithFixedDelay({
|
||||||
try {
|
try {
|
||||||
|
// this blocks the executor, so no worries about concurrency
|
||||||
reloadClientSettings()
|
reloadClientSettings()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
LOGGER.warn(e) { "Reload of ClientSettings failed" }
|
LOGGER.warn(e) { "Reload of ClientSettings failed" }
|
||||||
|
@ -104,7 +107,9 @@ class MangaDexClient(private val settingsFile: File, databaseFile: File, cacheFo
|
||||||
settings.webSettings?.let { webSettings ->
|
settings.webSettings?.let { webSettings ->
|
||||||
val imageServer = requireNotNull(imageServer)
|
val imageServer = requireNotNull(imageServer)
|
||||||
|
|
||||||
if (webUi != null) throw AssertionError()
|
if (webUi != null) {
|
||||||
|
throw AssertionError()
|
||||||
|
}
|
||||||
LOGGER.info { "WebUI starting" }
|
LOGGER.info { "WebUI starting" }
|
||||||
webUi = getUiServer(webSettings, imageServer.statistics, imageServer.statsMap).also {
|
webUi = getUiServer(webSettings, imageServer.statistics, imageServer.statsMap).also {
|
||||||
it.start()
|
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
|
// Precondition: settings must be filled with up-to-date settings
|
||||||
private fun startImageServer() {
|
private fun startImageServer() {
|
||||||
if (imageServer != null) throw AssertionError()
|
if (imageServer != null) {
|
||||||
|
throw AssertionError()
|
||||||
|
}
|
||||||
LOGGER.info { "Server manager starting" }
|
LOGGER.info { "Server manager starting" }
|
||||||
imageServer = ServerManager(settings.serverSettings, settings.devSettings, settings.maxCacheSizeInMebibytes, cache, database).also {
|
imageServer = ServerManager(settings.serverSettings, settings.devSettings, settings.maxCacheSizeInMebibytes, cache, database).also {
|
||||||
it.start()
|
it.start()
|
||||||
|
@ -179,8 +186,10 @@ class MangaDexClient(private val settingsFile: File, databaseFile: File, cacheFo
|
||||||
|
|
||||||
if (stopWebUi) {
|
if (stopWebUi) {
|
||||||
LOGGER.info { "Stopping WebUI to reload ClientSettings" }
|
LOGGER.info { "Stopping WebUI to reload ClientSettings" }
|
||||||
|
if(webUi != null) {
|
||||||
stopWebUi()
|
stopWebUi()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (restartServer) {
|
if (restartServer) {
|
||||||
stopImageServer()
|
stopImageServer()
|
||||||
|
|
Loading…
Reference in a new issue