public interface WebSocketSession extends MutableConvertibleValues<Object>, AutoCloseable
javax.websocket
and likely to be able to implement the spec in the future.EMPTY
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
close(CloseReason closeReason)
Close the session with the given event.
|
MutableConvertibleValues<Object> |
getAttributes() |
String |
getId()
The ID of the session.
|
Set<? extends WebSocketSession> |
getOpenSessions()
The current open sessions.
|
String |
getProtocolVersion()
The protocol version of the WebSocket protocol currently being used.
|
default ConvertibleMultiValues<String> |
getRequestParameters()
The request parameters used to create this session.
|
URI |
getRequestURI()
The request URI this session was opened under.
|
default Optional<String> |
getSubprotocol()
The subprotocol if one is used.
|
default ConvertibleValues<Object> |
getUriVariables()
Any matching URI path variables.
|
default Optional<Principal> |
getUserPrincipal()
The user
Principal used to create the session. |
boolean |
isOpen()
Whether the session is open.
|
boolean |
isSecure()
Whether the connection is secure.
|
boolean |
isWritable()
Whether the session is writable.
|
default <T> Publisher<T> |
send(T message)
Send the given message to the remote peer.
|
<T> Publisher<T> |
send(T message,
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.
|
<T> CompletableFuture<T> |
sendAsync(T message,
MediaType mediaType)
Send the given message to the remote peer asynchronously.
|
default CompletableFuture<?> |
sendPingAsync(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,
MediaType mediaType)
Send the given message to the remote peer synchronously.
|
clear, of, put, putAll, putAll, remove
asMap, asMap, asProperties, contains, empty, forEach, getValue, getValueType, isEmpty, iterator, names, subMap, subMap, subMap, values
get, get, get, get
forEach, spliterator
String getId()
MutableConvertibleValues<Object> getAttributes()
boolean isOpen()
boolean isWritable()
boolean isSecure()
Set<? extends WebSocketSession> getOpenSessions()
URI getRequestURI()
String getProtocolVersion()
<T> Publisher<T> send(T message, MediaType mediaType)
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.T
- The message typemessage
- The messagemediaType
- The media type of the message. Used to lookup an appropriate codec via the MediaTypeCodecRegistry
.Publisher
that either emits an error or emits the message once it has been published successfully.<T> CompletableFuture<T> sendAsync(T message, MediaType mediaType)
T
- The message typemessage
- The messagemediaType
- The media type of the message. Used to lookup an appropriate codec via the MediaTypeCodecRegistry
.CompletableFuture
that tracks the execution. CompletableFuture.get()
and related methods will return the message on success, on error throw the underlying Exception.default void sendSync(Object message, MediaType mediaType)
message
- The messagemediaType
- The media type of the message. Used to lookup an appropriate codec via the MediaTypeCodecRegistry
.default <T> Publisher<T> send(T message)
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.T
- The message typemessage
- The messagePublisher
that either emits an error or emits the message once it has been published successfully.default <T> CompletableFuture<T> sendAsync(T message)
T
- The message typemessage
- The messageCompletableFuture
that tracks the execution. CompletableFuture.get()
and related methods will return the message on success, on error throw the underlying Exception.default void sendSync(Object message)
message
- The message@NonNull default CompletableFuture<?> sendPingAsync(@NonNull byte[] content)
@OnMessage
method that accepts a
WebSocketPongMessage
.content
- The content of the ping. The remote should return the same content in its
WebSocketPongMessage
.default Optional<String> getSubprotocol()
default ConvertibleMultiValues<String> getRequestParameters()
default ConvertibleValues<Object> getUriVariables()
default Optional<Principal> getUserPrincipal()
Principal
used to create the session.Principal
void close()
close
in interface AutoCloseable
void close(CloseReason closeReason)
closeReason
- The close event