Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimpleEventListenerManager 实现中增加默认调度器 #493

Merged
merged 2 commits into from
Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public interface CoreListenerManager : SimpleEventListenerManager
* 立即返回一个 [AsyncEventResult].
*
*
*
* ## 监听函数的解析、缓存与获取
* 在 [SimpleEventListenerManager] 中,真正被执行的监听函数是经过缓存与转化的,它们只会在遇到一个目前缓存中未知的事件类型的时候进行同步转化缓存。
*
Expand All @@ -73,6 +72,8 @@ public interface CoreListenerManager : SimpleEventListenerManager
*
* 但是这存在例外:当存在任何通过 [ContinuousSessionContext] 而注册的持续会话监听函数的时候,[isProcessable] 将会始终得到 `true`。
*
* 需要注意的是, [isProcessable] 的结果并不保证是 **"强可靠"** 的。由于对监听函数动态增删的支持,其内部持有的监听函数集应当保证线程安全,
* 但是不会保证**强一致性**。这可能会导致当一个监听函数被追加的这一**瞬间**,[isProcessable] 仍无法感知到它的存在。
*
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

}

Expand Down Expand Up @@ -213,8 +218,12 @@ internal class SimpleEventListenerManagerImpl internal constructor(

@OptIn(ExperimentalStdlibApi::class, ExperimentalCoroutinesApi::class)
if (context[CoroutineDispatcher] == null) {
// todo configurable
context += Dispatchers.Default.limitedParallelism(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
Expand Down