Class AbstractMicronautEndpoint

java.lang.Object
jakarta.websocket.Endpoint
io.micronaut.servlet.websocket.AbstractMicronautEndpoint
Direct Known Subclasses:
MicronautServerEndpoint

@Internal public abstract class AbstractMicronautEndpoint extends jakarta.websocket.Endpoint
The dispatch a Jakarta 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
    Modifier
    Constructor
    Description
    protected
    Default constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    applyLimits(jakarta.websocket.Session session, @Nullable Integer declaredTextMax, @Nullable Integer declaredBinaryMax)
    Applies the payload limits a handler declares as maxMessageSize; a limit no handler declares is left to the container.
    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.
    protected final @Nullable ServletWebSocketSession
    The Micronaut view of the session.
    void
    onClose(jakarta.websocket.Session session, jakarta.websocket.CloseReason closeReason)
     
    void
    onError(jakarta.websocket.Session session, Throwable throwable)
     
    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.
    protected void
    Called once @OnOpen has completed, or straight away when there is none.
    protected void
    Called when @OnOpen failed, after @OnError was offered the failure and before the session is closed.
    protected abstract io.micronaut.core.propagation.PropagatedContext
    The context handlers run under, on top of which the request is propagated for a suspend handler.
    protected void
    sessionClosed(ServletWebSocketSession session, boolean opened)
    Called once the session is closed and its close handler has run.
    protected void
    Called once the connection is set up, before the message handlers are registered and the open handler runs.
    protected final ServletWebSocketSupport
    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

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 session
      config - The endpoint configuration the session was opened with
      support - The shared infrastructure
      webSocketBean - The bean the connection is dispatched to
      jakartaEndpoint - What the bean declares as a Jakarta endpoint, or null for a Micronaut one
      originatingRequest - The request handler arguments are bound against
      micronautSession - The Micronaut view of the session
      Returns:
      true when the connection is set up, false when 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 a suspend handler.
      Returns:
      The propagated context
    • sessionOpened

      protected void sessionOpened(ServletWebSocketSession session)
      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 @OnOpen has completed, or straight away when there is none. Nothing by default.
    • openFailed

      protected void openFailed(Throwable cause)
      Called when @OnOpen failed, after @OnError was offered the failure and before the session is closed. Nothing by default.
      Parameters:
      cause - The failure
    • sessionClosed

      protected void sessionClosed(ServletWebSocketSession session, boolean opened)
      Called once the session is closed and its close handler has run.
      Parameters:
      session - The Micronaut session
      opened - 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 as maxMessageSize; a limit no handler declares is left to the container.
      Parameters:
      session - The container's session
      declaredTextMax - The text limit the text handler declares, or null
      declaredBinaryMax - The binary limit the binary handler declares, or null
    • support

    • webSocketBean

      protected final io.micronaut.websocket.context.WebSocketBean<Object> webSocketBean()
      The bean the connection is dispatched to.
      Returns:
      The bean, once open(Session, EndpointConfig, ServletWebSocketSupport, WebSocketBean, JakartaEndpoint, HttpRequest, ServletWebSocketSession) was called
    • micronautSession

      protected final @Nullable ServletWebSocketSession 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:
      onClose in class jakarta.websocket.Endpoint
    • onError

      public void onError(jakarta.websocket.Session session, Throwable throwable)
      Overrides:
      onError in class jakarta.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 session
      reason - The close reason