Class AbstractMicronautEndpoint
- Direct Known Subclasses:
MicronautServerEndpoint
Endpoint performs onto a Micronaut WebSocket bean, shared by the
server and the client side.
The two programming models differ in what a handler receives and returns. A Jakarta endpoint
has one handler per message category, may take the container's Session, the
EndpointConfig and the Jakarta CloseReason, decodes with the
decoders it declares, and the value its @OnMessage returns is sent back to the peer. Each
of those is bridged here; a Micronaut endpoint is handled as before.
A subclass decides how the connection came about - accepted by the server or opened by the
client - and calls open(Session, EndpointConfig, ServletWebSocketSupport, WebSocketBean, JakartaEndpoint, HttpRequest, ServletWebSocketSession) from its Endpoint.onOpen(Session, EndpointConfig) with the pieces that differ: the bean,
the request the handlers are bound against and the Micronaut session. The hooks decide what
context handlers run under and what happens around the session's life.
- Since:
- 6.2.0
- Author:
- graemerocher
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidapplyLimits(jakarta.websocket.Session session, @Nullable Integer declaredTextMax, @Nullable Integer declaredBinaryMax) Applies the payload limits a handler declares asmaxMessageSize; a limit no handler declares is left to the container.protected static voidcloseQuietly(jakarta.websocket.Session session, io.micronaut.websocket.CloseReason reason) Closes the container's session, ignoring a failure to do so: the connection is going away anyway.protected final @Nullable ServletWebSocketSessionThe Micronaut view of the session.voidonClose(jakarta.websocket.Session session, jakarta.websocket.CloseReason closeReason) voidprotected final booleanopen(jakarta.websocket.Session session, jakarta.websocket.EndpointConfig config, ServletWebSocketSupport support, io.micronaut.websocket.context.WebSocketBean<Object> webSocketBean, @Nullable JakartaEndpoint jakartaEndpoint, io.micronaut.http.HttpRequest<?> originatingRequest, ServletWebSocketSession micronautSession) Sets the connection up and invokes@OnOpen.protected voidCalled once@OnOpenhas completed, or straight away when there is none.protected voidopenFailed(Throwable cause) Called when@OnOpenfailed, after@OnErrorwas offered the failure and before the session is closed.protected abstract io.micronaut.core.propagation.PropagatedContextThe context handlers run under, on top of which the request is propagated for asuspendhandler.protected voidsessionClosed(ServletWebSocketSession session, boolean opened) Called once the session is closed and its close handler has run.protected voidsessionOpened(ServletWebSocketSession session) Called once the connection is set up, before the message handlers are registered and the open handler runs.protected final ServletWebSocketSupportsupport()The shared infrastructure.protected final io.micronaut.websocket.context.WebSocketBean<Object> The bean the connection is dispatched to.Methods inherited from class jakarta.websocket.Endpoint
onOpen
-
Constructor Details
-
AbstractMicronautEndpoint
protected AbstractMicronautEndpoint()Default constructor.
-
-
Method Details
-
open
protected final boolean open(jakarta.websocket.Session session, jakarta.websocket.EndpointConfig config, ServletWebSocketSupport support, io.micronaut.websocket.context.WebSocketBean<Object> webSocketBean, @Nullable JakartaEndpoint jakartaEndpoint, io.micronaut.http.HttpRequest<?> originatingRequest, ServletWebSocketSession micronautSession) Sets the connection up and invokes@OnOpen.The handlers are resolved and validated, the limits applied and the message handlers registered with the container before the open handler runs, so a listener never sees a close that had no matching open and the endpoint never receives a message it has no handler for.
- Parameters:
session- The container's sessionconfig- The endpoint configuration the session was opened withsupport- The shared infrastructurewebSocketBean- The bean the connection is dispatched tojakartaEndpoint- What the bean declares as a Jakarta endpoint, ornullfor a Micronaut oneoriginatingRequest- The request handler arguments are bound againstmicronautSession- The Micronaut view of the session- Returns:
truewhen the connection is set up,falsewhen it could not be and the session was closed
-
propagatedContext
protected abstract io.micronaut.core.propagation.PropagatedContext propagatedContext()The context handlers run under, on top of which the request is propagated for asuspendhandler.- Returns:
- The propagated context
-
sessionOpened
Called once the connection is set up, before the message handlers are registered and the open handler runs. Nothing by default.- Parameters:
session- The Micronaut session
-
openCompleted
protected void openCompleted()Called once@OnOpenhas completed, or straight away when there is none. Nothing by default. -
openFailed
Called when@OnOpenfailed, after@OnErrorwas offered the failure and before the session is closed. Nothing by default.- Parameters:
cause- The failure
-
sessionClosed
Called once the session is closed and its close handler has run.- Parameters:
session- The Micronaut sessionopened- Whether the session had reached the open event
-
applyLimits
protected void applyLimits(jakarta.websocket.Session session, @Nullable Integer declaredTextMax, @Nullable Integer declaredBinaryMax) Applies the payload limits a handler declares asmaxMessageSize; a limit no handler declares is left to the container.- Parameters:
session- The container's sessiondeclaredTextMax- The text limit the text handler declares, ornulldeclaredBinaryMax- The binary limit the binary handler declares, ornull
-
support
The shared infrastructure.- Returns:
- The support, once
open(Session, EndpointConfig, ServletWebSocketSupport, WebSocketBean, JakartaEndpoint, HttpRequest, ServletWebSocketSession)was called
-
webSocketBean
The bean the connection is dispatched to.- Returns:
- The bean, once
open(Session, EndpointConfig, ServletWebSocketSupport, WebSocketBean, JakartaEndpoint, HttpRequest, ServletWebSocketSession)was called
-
micronautSession
The Micronaut view of the session.- Returns:
- The session, once
open(Session, EndpointConfig, ServletWebSocketSupport, WebSocketBean, JakartaEndpoint, HttpRequest, ServletWebSocketSession)was called
-
onClose
public void onClose(jakarta.websocket.Session session, jakarta.websocket.CloseReason closeReason) - Overrides:
onClosein classjakarta.websocket.Endpoint
-
onError
- Overrides:
onErrorin classjakarta.websocket.Endpoint
-
closeQuietly
protected static void closeQuietly(jakarta.websocket.Session session, io.micronaut.websocket.CloseReason reason) Closes the container's session, ignoring a failure to do so: the connection is going away anyway.- Parameters:
session- The container's sessionreason- The close reason
-