Fixed issues with connection listenermanagers assignment from a client connection. Added more notes
This commit is contained in:
parent
7c32c066b4
commit
01d818fa6e
@ -275,6 +275,8 @@ open class Client<CONNECTION : Connection>(config: Configuration = Configuration
|
|||||||
ClientRejectedException(errorMessage))
|
ClientRejectedException(errorMessage))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
newConnection.listenerManager.lazySet(listenerManager as ListenerManager<Connection>)
|
||||||
|
|
||||||
|
|
||||||
connection = newConnection
|
connection = newConnection
|
||||||
|
@ -245,12 +245,12 @@ open class Server<CONNECTION : Connection>(config: ServerConfiguration = ServerC
|
|||||||
var shouldCleanupConnection = false
|
var shouldCleanupConnection = false
|
||||||
|
|
||||||
if (connection.isExpired()) {
|
if (connection.isExpired()) {
|
||||||
logger.debug {"[${connection.sessionId}] connection expired"}
|
logger.trace {"[${connection.sessionId}] connection expired"}
|
||||||
shouldCleanupConnection = true
|
shouldCleanupConnection = true
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (connection.isClosed()) {
|
else if (connection.isClosed()) {
|
||||||
logger.debug {"[${connection.sessionId}] connection closed"}
|
logger.trace {"[${connection.sessionId}] connection closed"}
|
||||||
shouldCleanupConnection = true
|
shouldCleanupConnection = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,11 +265,14 @@ open class Server<CONNECTION : Connection>(config: ServerConfiguration = ServerC
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
}, { connectionToClean ->
|
}, { connectionToClean ->
|
||||||
logger.debug {"[${connectionToClean.sessionId}] removed connection"}
|
|
||||||
|
|
||||||
// have to free up resources!
|
// have to free up resources!
|
||||||
handshake.cleanup(connectionToClean)
|
handshake.cleanup(connectionToClean)
|
||||||
|
|
||||||
|
// there are 2 ways to call close.
|
||||||
|
// MANUALLY
|
||||||
|
// when a connection is disconnected via a timeout/expire.
|
||||||
|
// the compareAndSet is used to make sure that if we call close() MANUALLY, when the auto-cleanup/disconnect is called -- it doesn't
|
||||||
|
// try to do it again.
|
||||||
connectionToClean.close()
|
connectionToClean.close()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ open class Connection(connectionParameters: ConnectionParams<*>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val endPoint = connectionParameters.endPoint
|
private val endPoint = connectionParameters.endPoint
|
||||||
private val listenerManager = atomic<ListenerManager<Connection>?>(null)
|
internal val listenerManager = atomic<ListenerManager<Connection>?>(null)
|
||||||
|
|
||||||
val logger = endPoint.logger
|
val logger = endPoint.logger
|
||||||
|
|
||||||
@ -297,8 +297,15 @@ open class Connection(connectionParameters: ConnectionParams<*>) {
|
|||||||
* Closes the connection, and removes all connection specific listeners
|
* Closes the connection, and removes all connection specific listeners
|
||||||
*/
|
*/
|
||||||
suspend fun close() {
|
suspend fun close() {
|
||||||
|
// there are 2 ways to call close.
|
||||||
|
// MANUALLY
|
||||||
|
// when a connection is disconnected via a timeout/expire.
|
||||||
|
// the compareAndSet is used to make sure that if we call close() MANUALLY, when the auto-cleanup/disconnect is called -- it doesn't
|
||||||
|
// try to do it again.
|
||||||
|
|
||||||
|
// the server 'handshake' connection info is cleaned up with the disconnect via timeout/expire.
|
||||||
if (isClosed.compareAndSet(expect = false, update = true)) {
|
if (isClosed.compareAndSet(expect = false, update = true)) {
|
||||||
// the server 'handshake' connection info is already cleaned up before this is called
|
logger.info {"[${sessionId}] closed connection"}
|
||||||
|
|
||||||
subscription.close()
|
subscription.close()
|
||||||
|
|
||||||
|
@ -698,7 +698,6 @@ internal constructor(val type: Class<*>, internal val config: Configuration) : A
|
|||||||
// don't need anything fast or fancy here, because this method will only be called once
|
// don't need anything fast or fancy here, because this method will only be called once
|
||||||
connections.forEach {
|
connections.forEach {
|
||||||
it.close()
|
it.close()
|
||||||
listenerManager.notifyDisconnect(it) // if disconnect has a "connect" in it, this will case SO MANY PROBLEMS
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user