Error notifications have their own dispatcher now (and it's in the ListenerManager)

This commit is contained in:
Robinson 2023-09-05 12:57:41 +02:00
parent d64a4bb1e1
commit 1b2487daec
No known key found for this signature in database
GPG Key ID: 8E7DB78588BD6F5C
1 changed files with 10 additions and 4 deletions

View File

@ -18,12 +18,13 @@ package dorkbox.network.connection
import dorkbox.classUtil.ClassHelper
import dorkbox.classUtil.ClassHierarchy
import dorkbox.collections.IdentityMap
import dorkbox.network.Configuration
import dorkbox.network.ipFilter.IpFilterRule
import dorkbox.os.OS
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import dorkbox.util.NamedThreadFactory
import mu.KLogger
import net.jodah.typetools.TypeResolver
import java.util.concurrent.*
import java.util.concurrent.locks.ReentrantReadWriteLock
import kotlin.concurrent.write
@ -37,6 +38,11 @@ internal class ListenerManager<CONNECTION: Connection>(private val logger: KLogg
*/
val LOAD_FACTOR = OS.getFloat(ListenerManager::class.qualifiedName + "LOAD_FACTOR", 0.8f)
internal val executor = Executors.newSingleThreadExecutor(
NamedThreadFactory("Error Dispatcher", Configuration.networkThreadGroup, Thread.NORM_PRIORITY, true)
)
/**
* Remove from the stacktrace kotlin coroutine info + dorkbox network call stack. This is NOT used by RMI
*
@ -460,7 +466,7 @@ internal class ListenerManager<CONNECTION: Connection>(private val logger: KLogg
fun notifyError(connection: CONNECTION, exception: Throwable) {
val list = onErrorList
if (list.isNotEmpty()) {
EventDispatcher.ERROR.launch {
executor.submit {
list.forEach {
try {
it(connection, exception)
@ -484,7 +490,7 @@ internal class ListenerManager<CONNECTION: Connection>(private val logger: KLogg
fun notifyError(exception: Throwable) {
val list = onErrorGlobalList
if (list.isNotEmpty()) {
EventDispatcher.ERROR.launch {
executor.submit {
list.forEach {
try {
it(exception)