Interface WebSocketSession

All Superinterfaces:
AutoCloseable, ConversionServiceProvider, ConvertibleValues<Object>, Iterable<Map.Entry<String,Object>>, MutableConvertibleValues<Object>, ValueResolver<CharSequence>
All Known Implementing Classes:
NettyWebSocketSession

public interface WebSocketSession extends MutableConvertibleValues<Object>, AutoCloseable
Represents an open WebSocket connection. Based largely on javax.websocket and likely to be able to implement the spec in the future.
Since:
1.0
Author:
graemerocher
  • Method Details

    • getId

      String getId()
      The ID of the session.
      Returns:
      The ID of the session
    • getAttributes

      Returns:
      Only the attributes of the session
    • isOpen

      boolean isOpen()
      Whether the session is open.
      Returns:
      True if it is
    • isWritable

      boolean isWritable()
      Whether the session is writable. It may not be writable, if the buffer is currently full
      Returns:
      True if it is
    • isSecure

      boolean isSecure()
      Whether the connection is secure.
      Returns:
      True if it is secure
    • getOpenSessions

      Set<? extends WebSocketSession> getOpenSessions()
      The current open sessions.
      Returns:
      The open sessions
    • getRequestURI

      URI getRequestURI()
      The request URI this session was opened under.
      Returns:
      The request URI
    • getProtocolVersion

      String getProtocolVersion()
      The protocol version of the WebSocket protocol currently being used.
      Returns:
      The protocol version
    • send

      <T> Publisher<T> send(T message, MediaType mediaType)
      Send the given message to the remote peer. The resulting Publisher does not start sending until subscribed to. If you return it from Micronaut annotated methods such as OnOpen and OnMessage, Micronaut will subscribe to it and send the message without blocking.
      Type Parameters:
      T - The message type
      Parameters:
      message - The message
      mediaType - The media type of the message. Used to lookup an appropriate codec via the MediaTypeCodecRegistry.
      Returns:
      A Publisher that either emits an error or emits the message once it has been published successfully.
    • sendAsync

      <T> CompletableFuture<T> sendAsync(T message, MediaType mediaType)
      Send the given message to the remote peer asynchronously.
      Type Parameters:
      T - The message type
      Parameters:
      message - The message
      mediaType - The media type of the message. Used to lookup an appropriate codec via the MediaTypeCodecRegistry.
      Returns:
      A CompletableFuture that tracks the execution. CompletableFuture.get() and related methods will return the message on success, on error throw the underlying Exception.
    • sendSync

      default void sendSync(Object message, MediaType mediaType)
      Send the given message to the remote peer synchronously.
      Parameters:
      message - The message
      mediaType - The media type of the message. Used to lookup an appropriate codec via the MediaTypeCodecRegistry.
    • send

      default <T> Publisher<T> send(T message)
      Send the given message to the remote peer. The resulting Publisher does not start sending until subscribed to. If you return it from Micronaut annotated methods such as OnOpen and OnMessage, Micronaut will subscribe to it and send the message without blocking.
      Type Parameters:
      T - The message type
      Parameters:
      message - The message
      Returns:
      A Publisher that either emits an error or emits the message once it has been published successfully.
    • sendAsync

      default <T> CompletableFuture<T> sendAsync(T message)
      Send the given message to the remote peer asynchronously.
      Type Parameters:
      T - The message type
      Parameters:
      message - The message
      Returns:
      A CompletableFuture that tracks the execution. CompletableFuture.get() and related methods will return the message on success, on error throw the underlying Exception.
    • sendSync

      default void sendSync(Object message)
      Send the given message to the remote peer synchronously.
      Parameters:
      message - The message
    • sendPingAsync

      @NonNull default @NonNull CompletableFuture<?> sendPingAsync(@NonNull @io.micronaut.core.annotation.NonNull byte[] content)
      Send a ping through this WebSocket. The pong reply can be intercepted using a @OnMessage method that accepts a WebSocketPongMessage.
      Parameters:
      content - The content of the ping. The remote should return the same content in its WebSocketPongMessage.
      Returns:
      A future that completes when the ping has been sent. (Not when the pong has been received!)
    • getSubprotocol

      default Optional<String> getSubprotocol()
      The subprotocol if one is used.
      Returns:
      The subprotocol
    • getRequestParameters

      default ConvertibleMultiValues<String> getRequestParameters()
      The request parameters used to create this session.
      Returns:
      The request parameters
    • getUriVariables

      default ConvertibleValues<Object> getUriVariables()
      Any matching URI path variables.
      Returns:
      The path variables
    • getUserPrincipal

      default Optional<Principal> getUserPrincipal()
      The user Principal used to create the session.
      Returns:
      The Principal
    • close

      void close()
      Specified by:
      close in interface AutoCloseable
    • close

      void close(CloseReason closeReason)
      Close the session with the given event.
      Parameters:
      closeReason - The close event