mirror of
https://gitlab.com/mangadex-pub/mangadex_at_home.git
synced 2024-01-19 02:48:37 +00:00
Fix the reast of the formatting issues
This commit is contained in:
parent
27f36110f6
commit
ff2831f1b6
|
@ -35,7 +35,7 @@ import mdnet.BuildInfo
|
|||
import mdnet.base.settings.ClientSettings
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
class ClientSettingsException(message: String): Exception(message)
|
||||
class ClientSettingsException(message: String) : Exception(message)
|
||||
|
||||
object Main {
|
||||
private val LOGGER = LoggerFactory.getLogger(Main::class.java)
|
||||
|
@ -84,7 +84,7 @@ object Main {
|
|||
dieWithError(e)
|
||||
}
|
||||
}
|
||||
} catch(e: ClientSettingsException) {
|
||||
} catch (e: ClientSettingsException) {
|
||||
dieWithError(e)
|
||||
}
|
||||
|
||||
|
|
|
@ -25,8 +25,9 @@ import com.fasterxml.jackson.databind.ObjectMapper
|
|||
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException
|
||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||
import com.fasterxml.jackson.module.kotlin.readValue
|
||||
import mdnet.base.Main.dieWithError
|
||||
import java.io.File
|
||||
import java.io.FileReader
|
||||
import java.io.FileWriter
|
||||
import java.io.IOException
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
|
@ -35,6 +36,7 @@ import java.util.concurrent.Executors
|
|||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
import mdnet.base.Main.dieWithError
|
||||
import mdnet.base.data.Statistics
|
||||
import mdnet.base.server.getServer
|
||||
import mdnet.base.server.getUiServer
|
||||
|
@ -44,8 +46,6 @@ import mdnet.cache.DiskLruCache
|
|||
import mdnet.cache.HeaderMismatchException
|
||||
import org.http4k.server.Http4kServer
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.io.FileReader
|
||||
import java.io.FileWriter
|
||||
|
||||
sealed class State
|
||||
// server is not running
|
||||
|
@ -57,7 +57,7 @@ data class GracefulShutdown(val lastRunning: Running, val counts: Int = 0, val n
|
|||
// server is currently running
|
||||
data class Running(val server: Http4kServer, val settings: ServerSettings, val minutesToSettingsReload: Int) : State()
|
||||
// server is stopped to reload client settings
|
||||
data class ReloadClientSettings(val newSettings: ClientSettings, val restartWebUI: Boolean = false): State()
|
||||
data class ReloadClientSettings(val newSettings: ClientSettings, val restartWebUI: Boolean = false) : State()
|
||||
// clientSettings must only be accessed from the thread on the executorService
|
||||
class MangaDexClient(private var clientSettings: ClientSettings, private val clientSettingsFile: String) {
|
||||
// this must remain singlethreaded because of how the state mechanism works
|
||||
|
@ -79,7 +79,6 @@ class MangaDexClient(private var clientSettings: ClientSettings, private val cli
|
|||
private var webUi: Http4kServer? = null
|
||||
private val cache: DiskLruCache
|
||||
|
||||
|
||||
init {
|
||||
try {
|
||||
cache = DiskLruCache.open(
|
||||
|
@ -211,12 +210,10 @@ class MangaDexClient(private var clientSettings: ClientSettings, private val cli
|
|||
val minutesToNextReload = state.minutesToSettingsReload - 1
|
||||
if (minutesToNextReload <= 0) {
|
||||
reloadClientSettings()
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this.state = state.copy(minutesToSettingsReload = minutesToNextReload)
|
||||
}
|
||||
}
|
||||
else if (state is ReloadClientSettings) {
|
||||
} else if (state is ReloadClientSettings) {
|
||||
clientSettings = state.newSettings
|
||||
LOGGER.info("Reloaded ClientSettings: {}", clientSettings)
|
||||
|
||||
|
@ -226,7 +223,7 @@ class MangaDexClient(private var clientSettings: ClientSettings, private val cli
|
|||
|
||||
// Start the WebUI if we had to stop it
|
||||
// and still want it
|
||||
if(state.restartWebUI && clientSettings.webSettings != null) {
|
||||
if (state.restartWebUI && clientSettings.webSettings != null) {
|
||||
LOGGER.info("Starting WebUI after reloading ClientSettings")
|
||||
if (webUi == null) {
|
||||
webUi = getUiServer(clientSettings.webSettings!!, statistics, statsMap)
|
||||
|
@ -349,7 +346,7 @@ class MangaDexClient(private var clientSettings: ClientSettings, private val cli
|
|||
try {
|
||||
val newSettings = JACKSON.readValue<ClientSettings>(FileReader(clientSettingsFile)).apply(Main::validateSettings)
|
||||
|
||||
if(newSettings == clientSettings) {
|
||||
if (newSettings == clientSettings) {
|
||||
LOGGER.info { "Client Settings have not changed" }
|
||||
return
|
||||
}
|
||||
|
@ -367,10 +364,10 @@ class MangaDexClient(private var clientSettings: ClientSettings, private val cli
|
|||
newSettings.webSettings?.uiPort != clientSettings.webSettings?.uiPort
|
||||
|
||||
// Stop the the WebUI if needed
|
||||
if(restartWebUI && newSettings.webSettings != null) {
|
||||
if (restartWebUI && newSettings.webSettings != null) {
|
||||
LOGGER.info("Stopping WebUI to reload ClientSettings")
|
||||
webUi?.stop()
|
||||
} else if(restartWebUI && newSettings.webSettings == null) {
|
||||
} else if (restartWebUI && newSettings.webSettings == null) {
|
||||
LOGGER.info("Stopping WebUI to because it is no longer in ClientSettings")
|
||||
webUi?.close()
|
||||
webUi = null
|
||||
|
@ -378,7 +375,7 @@ class MangaDexClient(private var clientSettings: ClientSettings, private val cli
|
|||
restartWebUI = false
|
||||
}
|
||||
|
||||
if(restartServer) {
|
||||
if (restartServer) {
|
||||
// If we are restarting the server
|
||||
// We must do it gracefully and set
|
||||
// the new settings later
|
||||
|
@ -392,7 +389,7 @@ class MangaDexClient(private var clientSettings: ClientSettings, private val cli
|
|||
}
|
||||
// Start the WebUI if we had to stop it
|
||||
// and still want it
|
||||
if(restartWebUI && clientSettings.webSettings != null) {
|
||||
if (restartWebUI && clientSettings.webSettings != null) {
|
||||
LOGGER.info("Starting WebUI after reloading ClientSettings")
|
||||
if (webUi == null) {
|
||||
webUi = getUiServer(clientSettings.webSettings!!, statistics, statsMap)
|
||||
|
@ -412,7 +409,7 @@ class MangaDexClient(private var clientSettings: ClientSettings, private val cli
|
|||
dieWithError(e)
|
||||
}
|
||||
}
|
||||
} catch(e: ClientSettingsException) {
|
||||
} catch (e: ClientSettingsException) {
|
||||
LOGGER.warn("Can't reload client settings: " + e.message)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue