From c8af0ba33b3cf27283de792157970a8be570ec16 Mon Sep 17 00:00:00 2001 From: Robinson Date: Sat, 25 Feb 2023 13:23:29 +0100 Subject: [PATCH] Moved add() to companion object --- .../network/connection/ListenerManager.kt | 41 ++++++------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/src/dorkbox/network/connection/ListenerManager.kt b/src/dorkbox/network/connection/ListenerManager.kt index 18dae164..24ebb685 100644 --- a/src/dorkbox/network/connection/ListenerManager.kt +++ b/src/dorkbox/network/connection/ListenerManager.kt @@ -146,9 +146,20 @@ internal class ListenerManager(private val logger: KLogg // throw everything out throwable.stackTrace = stackTrace.copyOfRange(0, 1) } + + internal inline fun add(thing: T, array: Array): Array { + val currentLength: Int = array.size + + // add the new subscription to the array + @Suppress("UNCHECKED_CAST") + val newMessageArray = array.copyOf(currentLength + 1) as Array + newMessageArray[currentLength] = thing + + return newMessageArray + } } - // initialize a emtpy arrays + // initialize emtpy arrays private val onConnectFilterList = atomic(Array<(CONNECTION.() -> Boolean)>(0) { { true } }) private val onConnectFilterMutex = Mutex() @@ -173,17 +184,6 @@ internal class ListenerManager(private val logger: KLogg // used to keep a cache of class hierarchy for distributing messages private val classHierarchyCache = ClassHierarchy(LOAD_FACTOR) - private inline fun add(thing: T, array: Array): Array { - val currentLength: Int = array.size - - // add the new subscription to the array - @Suppress("UNCHECKED_CAST") - val newMessageArray = array.copyOf(currentLength + 1) as Array - newMessageArray[currentLength] = thing - - return newMessageArray - } - /** * Adds an IP+subnet rule that defines if that IP+subnet is allowed or denied connectivity to this server. * @@ -427,23 +427,6 @@ internal class ListenerManager(private val logger: KLogg } } - /** - * Invoked when there is a global error (no connection information) - * - * The error is also sent to an error log before notifying callbacks - */ - val notifyError: (exception: Throwable) -> Unit = { exception -> - onErrorGlobalList.value.forEach { - try { - it(exception) - } catch (t: Throwable) { - // NOTE: when we remove stuff, we ONLY want to remove the "tail" of the stacktrace, not ALL parts of the stacktrace - cleanStackTrace(t) - logger.error("Global error", t) - } - } - } - /** * Invoked when a message object was received from a remote peer. *