@Internal public class NettyWebSocketSession extends Object implements WebSocketSession
WebSocketSession
interface for Netty.Modifier and Type | Field and Description |
---|---|
static io.netty.util.AttributeKey<NettyWebSocketSession> |
WEB_SOCKET_SESSION_KEY
The WebSocket session is stored within a Channel attribute using the given key.
|
EMPTY
Modifier | Constructor and Description |
---|---|
protected |
NettyWebSocketSession(String id,
io.netty.channel.Channel channel,
HttpRequest<?> request,
MediaTypeCodecRegistry codecRegistry,
String protocolVersion,
boolean isSecure)
Creates a new netty web socket session.
|
Modifier and Type | Method and Description |
---|---|
MutableConvertibleValues<Object> |
clear()
Clear all values.
|
void |
close() |
void |
close(CloseReason closeReason)
Close the session with the given event.
|
<T> Optional<T> |
get(CharSequence name,
ArgumentConversionContext<T> conversionContext)
Resolve the given property for the given name.
|
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.
|
ConvertibleMultiValues<String> |
getRequestParameters()
The request parameters used to create this session.
|
URI |
getRequestURI()
The request URI this session was opened under.
|
boolean |
isOpen()
Whether the session is open.
|
boolean |
isSecure()
Whether the connection is secure.
|
boolean |
isWritable()
Whether the session is writable.
|
Set<String> |
names() |
MutableConvertibleValues<Object> |
put(CharSequence key,
Object value)
Insert a value for the given key and value.
|
MutableConvertibleValues<Object> |
remove(CharSequence key)
Remove a value for the given key.
|
<T> reactor.core.publisher.Flux<T> |
send(T message,
MediaType mediaType)
Send the given message to the remote peer.
|
<T> CompletableFuture<T> |
sendAsync(T message,
MediaType mediaType)
Send the given message to the remote peer asynchronously.
|
CompletableFuture<?> |
sendPingAsync(byte[] content)
Send a ping through this WebSocket.
|
void |
sendSync(Object message,
MediaType mediaType)
Send the given message to the remote peer synchronously.
|
String |
toString() |
Collection<Object> |
values() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getSubprotocol, getUriVariables, getUserPrincipal, send, sendAsync, sendSync
of, putAll, putAll
asMap, asMap, asProperties, contains, empty, forEach, getValue, getValueType, isEmpty, iterator, subMap, subMap, subMap
get, get, get
forEach, spliterator
public static final io.netty.util.AttributeKey<NettyWebSocketSession> WEB_SOCKET_SESSION_KEY
protected NettyWebSocketSession(String id, io.netty.channel.Channel channel, HttpRequest<?> request, MediaTypeCodecRegistry codecRegistry, String protocolVersion, boolean isSecure)
id
- The IDchannel
- The channelrequest
- The original request used to create the sessioncodecRegistry
- The codec registryprotocolVersion
- The protocol versionisSecure
- Whether the session is securepublic String getId()
WebSocketSession
getId
in interface WebSocketSession
public MutableConvertibleValues<Object> getAttributes()
getAttributes
in interface WebSocketSession
public boolean isOpen()
WebSocketSession
isOpen
in interface WebSocketSession
public boolean isWritable()
WebSocketSession
isWritable
in interface WebSocketSession
public boolean isSecure()
WebSocketSession
isSecure
in interface WebSocketSession
public Set<? extends WebSocketSession> getOpenSessions()
WebSocketSession
getOpenSessions
in interface WebSocketSession
public URI getRequestURI()
WebSocketSession
getRequestURI
in interface WebSocketSession
public ConvertibleMultiValues<String> getRequestParameters()
WebSocketSession
getRequestParameters
in interface WebSocketSession
public String getProtocolVersion()
WebSocketSession
getProtocolVersion
in interface WebSocketSession
public <T> CompletableFuture<T> sendAsync(T message, MediaType mediaType)
WebSocketSession
sendAsync
in interface WebSocketSession
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.public void sendSync(Object message, MediaType mediaType)
WebSocketSession
sendSync
in interface WebSocketSession
message
- The messagemediaType
- The media type of the message. Used to lookup an appropriate codec via the MediaTypeCodecRegistry
.public <T> reactor.core.publisher.Flux<T> send(T message, MediaType mediaType)
WebSocketSession
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.send
in interface WebSocketSession
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.@NonNull public CompletableFuture<?> sendPingAsync(@NonNull byte[] content)
WebSocketSession
@OnMessage
method that accepts a
WebSocketPongMessage
.sendPingAsync
in interface WebSocketSession
content
- The content of the ping. The remote should return the same content in its
WebSocketPongMessage
.public void close()
close
in interface WebSocketSession
close
in interface AutoCloseable
public void close(CloseReason closeReason)
WebSocketSession
close
in interface WebSocketSession
closeReason
- The close eventpublic MutableConvertibleValues<Object> put(CharSequence key, @Nullable Object value)
MutableConvertibleValues
put
in interface MutableConvertibleValues<Object>
key
- The keyvalue
- The valuepublic MutableConvertibleValues<Object> remove(CharSequence key)
MutableConvertibleValues
remove
in interface MutableConvertibleValues<Object>
key
- The keypublic MutableConvertibleValues<Object> clear()
MutableConvertibleValues
clear
in interface MutableConvertibleValues<Object>
public Set<String> names()
names
in interface ConvertibleValues<Object>
public Collection<Object> values()
values
in interface ConvertibleValues<Object>
public <T> Optional<T> get(CharSequence name, ArgumentConversionContext<T> conversionContext)
ValueResolver
get
in interface ValueResolver<CharSequence>
T
- The concrete typename
- The nameconversionContext
- The conversion context