mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
delete LoggerControllerProvider
This commit is contained in:
parent
97ca3d38f2
commit
73463554b8
@ -36,8 +36,6 @@ public open class AutoSavePluginData private constructor(
|
||||
private lateinit var owner_: AutoSavePluginDataHolder
|
||||
private val autoSaveIntervalMillis_: LongRange get() = owner_.autoSaveIntervalMillis
|
||||
private lateinit var storage_: PluginDataStorage
|
||||
private var authSaveJob: Job? = null
|
||||
private var completionHandle: DisposableHandle? = null
|
||||
|
||||
public final override val saveName: String
|
||||
get() = _saveName
|
||||
@ -56,27 +54,18 @@ public open class AutoSavePluginData private constructor(
|
||||
?: throw IllegalArgumentException("Cannot find a serial name for ${this::class}")
|
||||
}
|
||||
|
||||
@ConsoleExperimentalApi
|
||||
public fun destroy() {
|
||||
completionHandle?.dispose()
|
||||
authSaveJob?.cancel()
|
||||
completionHandle = null
|
||||
authSaveJob = null
|
||||
}
|
||||
|
||||
@ConsoleExperimentalApi
|
||||
override fun onInit(owner: PluginDataHolder, storage: PluginDataStorage) {
|
||||
check(owner is AutoSavePluginDataHolder) { "owner must be AutoSavePluginDataHolder for AutoSavePluginData" }
|
||||
|
||||
if (this::storage_.isInitialized) {
|
||||
check(storage == this.storage_) { "AutoSavePluginData is already initialized with one storage and cannot be reinitialized with another." }
|
||||
destroy() // Destroy old jobs
|
||||
}
|
||||
|
||||
this.storage_ = storage
|
||||
this.owner_ = owner
|
||||
|
||||
completionHandle = owner_.coroutineContext[Job]?.invokeOnCompletion {
|
||||
owner_.coroutineContext[Job]?.invokeOnCompletion {
|
||||
kotlin.runCatching {
|
||||
doSave()
|
||||
}.onFailure { e ->
|
||||
@ -91,7 +80,7 @@ public open class AutoSavePluginData private constructor(
|
||||
}
|
||||
|
||||
if (shouldPerformAutoSaveWheneverChanged()) {
|
||||
authSaveJob = owner_.launch(CoroutineName("AutoSavePluginData.timedAutoSave: ${this::class.qualifiedNameOrTip}")) {
|
||||
owner_.launch(CoroutineName("AutoSavePluginData.timedAutoSave: ${this::class.qualifiedNameOrTip}")) {
|
||||
while (isActive) {
|
||||
try {
|
||||
delay(autoSaveIntervalMillis_.last) // 定时自动保存一次, 用于 kts 序列化的对象
|
||||
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.console.extensions
|
||||
|
||||
import net.mamoe.mirai.console.extension.AbstractSingletonExtensionPoint
|
||||
import net.mamoe.mirai.console.extension.SingletonExtension
|
||||
import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge
|
||||
import net.mamoe.mirai.console.internal.logging.LoggerControllerImpl
|
||||
import net.mamoe.mirai.console.logging.LoggerController
|
||||
import net.mamoe.mirai.console.permission.PermissionService
|
||||
|
||||
public interface LoggerControllerProvider : SingletonExtension<LoggerController> {
|
||||
public companion object ExtensionPoint :
|
||||
AbstractSingletonExtensionPoint<LoggerControllerProvider, LoggerController>(LoggerControllerProvider::class, MiraiConsoleImplementationBridge.frontendLoggerController)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see LoggerControllerProvider
|
||||
*/
|
||||
public class LoggerControllerProviderImpl(override val instance: LoggerController) : LoggerControllerProvider
|
||||
|
||||
/**
|
||||
* @see LoggerControllerProvider
|
||||
*/
|
||||
public class LoggerControllerProviderLazy(initializer: () -> LoggerController) : LoggerControllerProvider {
|
||||
override val instance: LoggerController by lazy(initializer)
|
||||
}
|
@ -25,7 +25,6 @@ import net.mamoe.mirai.console.command.BuiltInCommands
|
||||
import net.mamoe.mirai.console.command.CommandManager
|
||||
import net.mamoe.mirai.console.command.ConsoleCommandSender
|
||||
import net.mamoe.mirai.console.data.PluginDataStorage
|
||||
import net.mamoe.mirai.console.extensions.LoggerControllerProvider
|
||||
import net.mamoe.mirai.console.extensions.PermissionServiceProvider
|
||||
import net.mamoe.mirai.console.extensions.PostStartupExtension
|
||||
import net.mamoe.mirai.console.extensions.SingletonExtensionSelector
|
||||
@ -36,12 +35,12 @@ import net.mamoe.mirai.console.internal.data.builtins.LoggerConfig
|
||||
import net.mamoe.mirai.console.internal.data.castOrNull
|
||||
import net.mamoe.mirai.console.internal.extension.BuiltInSingletonExtensionSelector
|
||||
import net.mamoe.mirai.console.internal.extension.GlobalComponentStorage
|
||||
import net.mamoe.mirai.console.internal.logging.LoggerControllerDelegate
|
||||
import net.mamoe.mirai.console.internal.logging.LoggerControllerImpl
|
||||
import net.mamoe.mirai.console.internal.logging.MiraiConsoleLogger
|
||||
import net.mamoe.mirai.console.internal.permission.BuiltInPermissionService
|
||||
import net.mamoe.mirai.console.internal.plugin.PluginManagerImpl
|
||||
import net.mamoe.mirai.console.internal.util.autoHexToBytes
|
||||
import net.mamoe.mirai.console.logging.LoggerController
|
||||
import net.mamoe.mirai.console.permission.PermissionService
|
||||
import net.mamoe.mirai.console.permission.PermissionService.Companion.permit
|
||||
import net.mamoe.mirai.console.permission.RootPermission
|
||||
@ -90,8 +89,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
|
||||
override fun createLoginSolver(requesterBot: Long, configuration: BotConfiguration): LoginSolver =
|
||||
instance.createLoginSolver(requesterBot, configuration)
|
||||
|
||||
internal val frontendLoggerController = instance.loggerController
|
||||
override val loggerController: LoggerControllerDelegate = LoggerControllerDelegate(frontendLoggerController)
|
||||
override val loggerController: LoggerController by instance::loggerController
|
||||
|
||||
init {
|
||||
DefaultLogger = this::createLogger
|
||||
@ -106,10 +104,9 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
|
||||
@Suppress("RemoveRedundantBackticks")
|
||||
internal fun doStart() {
|
||||
|
||||
phase `pre setup logger controller`@{
|
||||
loggerController.delegate = frontendLoggerController
|
||||
if (frontendLoggerController === LoggerControllerImpl) {
|
||||
// Relaod LoggerConfig first.
|
||||
phase `setup logger controller`@{
|
||||
if (loggerController === LoggerControllerImpl) {
|
||||
// Relaod LoggerConfig.
|
||||
ConsoleDataScope.addAndReloadConfig(LoggerConfig)
|
||||
}
|
||||
}
|
||||
@ -180,13 +177,6 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
|
||||
}
|
||||
}
|
||||
|
||||
phase `setup logger controller`@{
|
||||
val selected = LoggerControllerProvider.selectedInstance
|
||||
if (selected !== frontendLoggerController) {
|
||||
ConsoleDataScope.dropConfig(LoggerConfig)
|
||||
loggerController.delegate = selected
|
||||
}
|
||||
}
|
||||
|
||||
phase `load PermissionService`@{
|
||||
mainLogger.verbose { "Loading PermissionService..." }
|
||||
|
@ -1,21 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.console.internal.logging
|
||||
|
||||
import net.mamoe.mirai.console.logging.LoggerController
|
||||
import net.mamoe.mirai.utils.SimpleLogger
|
||||
|
||||
internal class LoggerControllerDelegate(
|
||||
@Volatile
|
||||
var delegate: LoggerController
|
||||
) : LoggerController {
|
||||
override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = delegate.shouldLog(identity, priority)
|
||||
}
|
Loading…
Reference in New Issue
Block a user