Interface WebSocketSession

All Superinterfaces:
AutoCloseable, io.micronaut.core.convert.ConversionServiceProvider, io.micronaut.core.convert.value.ConvertibleValues<Object>, Iterable<Map.Entry<String,Object>>, io.micronaut.core.convert.value.MutableConvertibleValues<Object>, io.micronaut.core.value.ValueResolver<CharSequence>

public interface WebSocketSession extends io.micronaut.core.convert.value.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
  • Field Summary

    Fields inherited from interface io.micronaut.core.convert.value.ConvertibleValues

    EMPTY
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
    close(CloseReason closeReason)
    Close the session with the given event.
    io.micronaut.core.convert.value.MutableConvertibleValues<Object>
     
    The ID of the session.
    The current open sessions.
    The protocol version of the WebSocket protocol currently being used.
    default io.micronaut.core.convert.value.ConvertibleMultiValues<String>
    The request parameters used to create this session.
    The request URI this session was opened under.
    default Optional<String>
    The subprotocol if one is used.
    default io.micronaut.core.convert.value.ConvertibleValues<Object>
    Any matching URI path variables.
    The user Principal used to create the session.
    boolean
    Whether the session is open.
    boolean
    Whether the connection is secure.
    boolean
    Whether the session is writable.
    default <T> org.reactivestreams.Publisher<T>
    send(T message)
    Send the given message to the remote peer.
    <T> org.reactivestreams.Publisher<T>
    send(T message, io.micronaut.http.MediaType mediaType)
    Send the given message to the remote peer.
    default <T> CompletableFuture<T>
    sendAsync(T message)
    Send the given message to the remote peer asynchronously.
    sendAsync(T message, io.micronaut.http.MediaType mediaType)
    Send the given message to the remote peer asynchronously.
    default @NonNull CompletableFuture<?>
    sendPingAsync(@io.micronaut.core.annotation.NonNull byte[] content)
    Send a ping through this WebSocket.
    default void
    sendSync(Object message)
    Send the given message to the remote peer synchronously.
    default void
    sendSync(Object message, io.micronaut.http.MediaType mediaType)
    Send the given message to the remote peer synchronously.

    Methods inherited from interface io.micronaut.core.convert.value.ConvertibleValues

    asMap, asMap, asProperties, contains, forEach, getConversionService, getValue, getValueType, isEmpty, iterator, names, subMap, subMap, subMap, values

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator

    Methods inherited from interface io.micronaut.core.convert.value.MutableConvertibleValues

    clear, put, putAll, putAll, remove

    Methods inherited from interface io.micronaut.core.value.ValueResolver

    get, get, get, get
  • Method Details

    • getId

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

      io.micronaut.core.convert.value.MutableConvertibleValues<Object> 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> org.reactivestreams.Publisher<T> send(T message, io.micronaut.http.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 look up 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, io.micronaut.http.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 look up 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, io.micronaut.http.MediaType mediaType)
      Send the given message to the remote peer synchronously.
      Parameters:
      message - The message
      mediaType - The media type of the message. Used to look up an appropriate codec via the MediaTypeCodecRegistry.
    • send

      default <T> org.reactivestreams.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 io.micronaut.core.convert.value.ConvertibleMultiValues<String> getRequestParameters()
      The request parameters used to create this session.
      Returns:
      The request parameters
    • getUriVariables

      default io.micronaut.core.convert.value.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