Context
spring-webflux:5.3.0. org.springframework.web.reactive.socket.WebSocketSession
Motivation
It's common to decide what to do next according to the status (open or closed) of "WebSocketSession". And we know WebSocketSession#closeStatus can be used as a workaround to know whether a session has been closed but it's troublesome to check the status of a session in that way.
Solution
Expose a public method like "isClosed" to indicate whether the connection has been closed in WebSocketSession (WebFlux)
Comment From: jhoeller
Or maybe an isOpen()
method like on our classic WebSocketSession
, @rstoyanchev ?
Comment From: JamesChenX
@jhoeller Thanks for your quick reply. Both isOpen()
and isClosed
are acceptable because we just want to know the status of the WebSocket session.
Comment From: rstoyanchev
We can create isOpen
. Reactor Netty doesn't seem to expose a similar method but it can be tracked, e.g. via getInbound().receiveCloseStatus()
notifications. @violetagg is a boolean method (isOpen, isDisposed, etc.) something that could be exposed somewhere? Especially if it is readily available, we wouldn't have to maintain and update such state at the Spring Framework level.
For Jetty/Tomcat this can be implemented as a simple delegation to the underlying session. For Undertow I don't see anything convenient on a first glance so we'll need to add some state to track it.
Comment From: violetagg
@rstoyanchev Isn't Connection.channel().isActive()
exactly what you need?
Comment From: violetagg
Connection.isDisposed()
is actually a shortcut for the above.
Comment From: rstoyanchev
Thanks @violetagg, I've implemented it. Please, see the way it worked out for Reactor Netty is slightly inconvenient with the callback but not an issue in our case since it's used internally.