Added Handshake dispatch (was required, and must be single threaded)
This commit is contained in:
parent
2aebbe6116
commit
cbfe51f746
|
@ -31,7 +31,7 @@ import java.util.concurrent.*
|
||||||
internal class EventDispatcher(val type: String) {
|
internal class EventDispatcher(val type: String) {
|
||||||
enum class EDType {
|
enum class EDType {
|
||||||
// CLOSE must be last!
|
// CLOSE must be last!
|
||||||
CONNECT, ERROR, CLOSE
|
HANDSHAKE, CONNECT, ERROR, CLOSE
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class ED(private val dispatcher: EventDispatcher, private val type: EDType) {
|
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 {
|
companion object {
|
||||||
private val DEBUG_EVENTS = false
|
private val DEBUG_EVENTS = false
|
||||||
private val traceId = atomic(0)
|
private val traceId = atomic(0)
|
||||||
|
|
||||||
private val typedEntries: Array<EDType>
|
private val typedEntries: Array<EDType>
|
||||||
|
|
||||||
val MULTI = Dispatch()
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
typedEntries = EDType.entries.toTypedArray()
|
typedEntries = EDType.entries.toTypedArray()
|
||||||
}
|
}
|
||||||
|
@ -91,6 +77,7 @@ internal class EventDispatcher(val type: String) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val HANDSHAKE: ED
|
||||||
val CONNECT: ED
|
val CONNECT: ED
|
||||||
val ERROR: ED
|
val ERROR: ED
|
||||||
val CLOSE: ED
|
val CLOSE: ED
|
||||||
|
@ -103,6 +90,7 @@ internal class EventDispatcher(val type: String) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HANDSHAKE = ED(this, EDType.HANDSHAKE)
|
||||||
CONNECT = ED(this, EDType.CONNECT)
|
CONNECT = ED(this, EDType.CONNECT)
|
||||||
ERROR = ED(this, EDType.ERROR)
|
ERROR = ED(this, EDType.ERROR)
|
||||||
CLOSE = ED(this, EDType.CLOSE)
|
CLOSE = ED(this, EDType.CLOSE)
|
||||||
|
|
|
@ -26,7 +26,6 @@ import dorkbox.network.aeron.AeronDriver
|
||||||
import dorkbox.network.aeron.AeronDriver.Companion.uriHandshake
|
import dorkbox.network.aeron.AeronDriver.Companion.uriHandshake
|
||||||
import dorkbox.network.aeron.AeronPoller
|
import dorkbox.network.aeron.AeronPoller
|
||||||
import dorkbox.network.connection.Connection
|
import dorkbox.network.connection.Connection
|
||||||
import dorkbox.network.connection.EventDispatcher
|
|
||||||
import dorkbox.network.connection.IpInfo
|
import dorkbox.network.connection.IpInfo
|
||||||
import dorkbox.network.exceptions.ServerException
|
import dorkbox.network.exceptions.ServerException
|
||||||
import dorkbox.network.exceptions.ServerHandshakeException
|
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,
|
// 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!!
|
// 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.
|
// we have read all the data, now dispatch it.
|
||||||
// HandshakeMessage.HELLO
|
// HandshakeMessage.HELLO
|
||||||
// HandshakeMessage.DONE
|
// 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,
|
// 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!!
|
// 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.HELLO
|
||||||
// HandshakeMessage.DONE
|
// HandshakeMessage.DONE
|
||||||
val messageState = message.state
|
val messageState = message.state
|
||||||
|
|
Loading…
Reference in New Issue