From c0794bad8c459843c034f5503fac26da9a666a1d Mon Sep 17 00:00:00 2001 From: ForteScarlet Date: Sun, 6 Nov 2022 02:35:24 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(core):=20SimpleEventListenerManagerImp?= =?UTF-8?q?l=20=E5=86=85=E9=83=A8=E7=9A=84=E9=BB=98=E8=AE=A4=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E8=B0=83=E5=BA=A6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../love/forte/simbot/core/event/SimpleEventListenerManager.kt | 3 ++- .../forte/simbot/core/event/SimpleEventListenerManagerImpl.kt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/simbot-cores/simbot-core/src/main/kotlin/love/forte/simbot/core/event/SimpleEventListenerManager.kt b/simbot-cores/simbot-core/src/main/kotlin/love/forte/simbot/core/event/SimpleEventListenerManager.kt index 9d4688577..d7c33a49f 100644 --- a/simbot-cores/simbot-core/src/main/kotlin/love/forte/simbot/core/event/SimpleEventListenerManager.kt +++ b/simbot-cores/simbot-core/src/main/kotlin/love/forte/simbot/core/event/SimpleEventListenerManager.kt @@ -50,7 +50,6 @@ public interface CoreListenerManager : SimpleEventListenerManager * 立即返回一个 [AsyncEventResult]. * * - * * ## 监听函数的解析、缓存与获取 * 在 [SimpleEventListenerManager] 中,真正被执行的监听函数是经过缓存与转化的,它们只会在遇到一个目前缓存中未知的事件类型的时候进行同步转化缓存。 * @@ -73,6 +72,8 @@ public interface CoreListenerManager : SimpleEventListenerManager * * 但是这存在例外:当存在任何通过 [ContinuousSessionContext] 而注册的持续会话监听函数的时候,[isProcessable] 将会始终得到 `true`。 * + * 需要注意的是, [isProcessable] 的结果并不保证是 **"强可靠"** 的。由于对监听函数动态增删的支持,其内部持有的监听函数集应当保证线程安全, + * 但是不会保证**强一致性**。这可能会导致当一个监听函数被追加的这一**瞬间**,[isProcessable] 仍无法感知到它的存在。 * * */ diff --git a/simbot-cores/simbot-core/src/main/kotlin/love/forte/simbot/core/event/SimpleEventListenerManagerImpl.kt b/simbot-cores/simbot-core/src/main/kotlin/love/forte/simbot/core/event/SimpleEventListenerManagerImpl.kt index a341451a7..9112cdd66 100644 --- a/simbot-cores/simbot-core/src/main/kotlin/love/forte/simbot/core/event/SimpleEventListenerManagerImpl.kt +++ b/simbot-cores/simbot-core/src/main/kotlin/love/forte/simbot/core/event/SimpleEventListenerManagerImpl.kt @@ -214,7 +214,7 @@ internal class SimpleEventListenerManagerImpl internal constructor( @OptIn(ExperimentalStdlibApi::class, ExperimentalCoroutinesApi::class) if (context[CoroutineDispatcher] == null) { // todo configurable - context += Dispatchers.Default.limitedParallelism(16) + context += Dispatchers.Default.limitedParallelism(Runtime.getRuntime().availableProcessors().coerceAtLeast(16)) } managerCoroutineContext = context From f2d311cabda46b1c96d468c9648cb77bc1e5968a Mon Sep 17 00:00:00 2001 From: ForteScarlet Date: Sun, 6 Nov 2022 02:41:49 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat(core):=20SimpleEventListenerManagerImp?= =?UTF-8?q?l=20=E5=86=85=E9=83=A8=E7=9A=84=E9=BB=98=E8=AE=A4=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E8=B0=83=E5=BA=A6=E5=99=A8=E5=8F=AF=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/event/SimpleEventListenerManagerImpl.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/simbot-cores/simbot-core/src/main/kotlin/love/forte/simbot/core/event/SimpleEventListenerManagerImpl.kt b/simbot-cores/simbot-core/src/main/kotlin/love/forte/simbot/core/event/SimpleEventListenerManagerImpl.kt index 9112cdd66..8813f0880 100644 --- a/simbot-cores/simbot-core/src/main/kotlin/love/forte/simbot/core/event/SimpleEventListenerManagerImpl.kt +++ b/simbot-cores/simbot-core/src/main/kotlin/love/forte/simbot/core/event/SimpleEventListenerManagerImpl.kt @@ -45,6 +45,11 @@ internal class SimpleEventListenerManagerImpl internal constructor( LoggerFactory.getLogger("love.forte.simbot.core.event.SimpleEventListenerManagerImpl") private const val EVENT_KEY_PROCESSABLE_COUNTER_CLEAR_THRESHOLD = 83 + + /** + * 是否禁用产生内部使用的默认调度器。 + */ + private const val DISABLE_DEFAULT_DISPATCHER = "love.forte.simbot.core.SimpleListenerManager.disableDefaultDispatcher" } @@ -213,8 +218,12 @@ internal class SimpleEventListenerManagerImpl internal constructor( @OptIn(ExperimentalStdlibApi::class, ExperimentalCoroutinesApi::class) if (context[CoroutineDispatcher] == null) { - // todo configurable - context += Dispatchers.Default.limitedParallelism(Runtime.getRuntime().availableProcessors().coerceAtLeast(16)) + if (System.getProperty(DISABLE_DEFAULT_DISPATCHER).toBoolean()) { + // todo configurable + context += Dispatchers.Default.limitedParallelism(Runtime.getRuntime().availableProcessors().coerceAtLeast(16)) + } else { + logger.debug("No dispatcher for current simple listener manager, and default dispatcher is disabled.") + } } managerCoroutineContext = context