Added Handshake dispatch (was required, and must be single threaded)

master
Robinson 2023-11-13 14:10:00 +01:00
parent 2aebbe6116
commit cbfe51f746
No known key found for this signature in database
GPG Key ID: 8E7DB78588BD6F5C
2 changed files with 5 additions and 18 deletions

View File

@ -31,7 +31,7 @@ import java.util.concurrent.*
internal class EventDispatcher(val type: String) {
enum class EDType {
// CLOSE must be last!
CONNECT, ERROR, CLOSE
HANDSHAKE, CONNECT, ERROR, CLOSE
}
internal class ED(private val dispatcher: EventDispatcher, private val type: EDType) {
@ -44,26 +44,12 @@ internal class EventDispatcher(val type: String) {
}
}
internal class Dispatch() {
companion object {
val executor = Executors.newCachedThreadPool(
NamedThreadFactory("Multi", Configuration.networkThreadGroup)
)
}
fun launch(function: () -> Unit) {
executor.submit(function)
}
}
companion object {
private val DEBUG_EVENTS = false
private val traceId = atomic(0)
private val typedEntries: Array<EDType>
val MULTI = Dispatch()
init {
typedEntries = EDType.entries.toTypedArray()
}
@ -91,6 +77,7 @@ internal class EventDispatcher(val type: String) {
val HANDSHAKE: ED
val CONNECT: ED
val ERROR: ED
val CLOSE: ED
@ -103,6 +90,7 @@ internal class EventDispatcher(val type: String) {
}
}
HANDSHAKE = ED(this, EDType.HANDSHAKE)
CONNECT = ED(this, EDType.CONNECT)
ERROR = ED(this, EDType.ERROR)
CLOSE = ED(this, EDType.CLOSE)

View File

@ -26,7 +26,6 @@ import dorkbox.network.aeron.AeronDriver
import dorkbox.network.aeron.AeronDriver.Companion.uriHandshake
import dorkbox.network.aeron.AeronPoller
import dorkbox.network.connection.Connection
import dorkbox.network.connection.EventDispatcher
import dorkbox.network.connection.IpInfo
import dorkbox.network.exceptions.ServerException
import dorkbox.network.exceptions.ServerHandshakeException
@ -122,7 +121,7 @@ internal object ServerHandshakePollers {
// NOTE: This MUST to happen in separates thread so that we can take as long as we need when creating publications and handshaking,
// because under load -- this will REGULARLY timeout! Under no circumstance can this happen in the main processing thread!!
EventDispatcher.MULTI.launch {
server.eventDispatch.HANDSHAKE.launch {
// we have read all the data, now dispatch it.
// HandshakeMessage.HELLO
// HandshakeMessage.DONE
@ -377,7 +376,7 @@ internal object ServerHandshakePollers {
// NOTE: This MUST to happen in separates thread so that we can take as long as we need when creating publications and handshaking,
// because under load -- this will REGULARLY timeout! Under no circumstance can this happen in the main processing thread!!
EventDispatcher.MULTI.launch {
server.eventDispatch.HANDSHAKE.launch {
// HandshakeMessage.HELLO
// HandshakeMessage.DONE
val messageState = message.state