Class NettyWebSocketSession
java.lang.Object
io.micronaut.http.netty.websocket.NettyWebSocketSession
- All Implemented Interfaces:
ConversionServiceProvider
,ConvertibleValues<Object>
,MutableConvertibleValues<Object>
,ValueResolver<CharSequence>
,WebSocketSession
,AutoCloseable
,Iterable<Map.Entry<String,
Object>>
Implementation of the
WebSocketSession
interface for Netty.- Since:
- 1.0
- Author:
- graemerocher
-
Field Summary
Modifier and TypeFieldDescriptionstatic final io.netty.util.AttributeKey<NettyWebSocketSession>
The WebSocket session is stored within a Channel attribute using the given key.Fields inherited from interface io.micronaut.core.convert.value.ConvertibleValues
EMPTY
-
Constructor Summary
ModifierConstructorDescriptionprotected
NettyWebSocketSession
(String id, io.netty.channel.Channel channel, HttpRequest<?> request, MediaTypeCodecRegistry codecRegistry, String protocolVersion, boolean isSecure) Creates a new netty web socket session. -
Method Summary
Modifier and TypeMethodDescriptionclear()
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.getId()
The ID of the session.Set<? extends WebSocketSession>
The current open sessions.The protocol version of the WebSocket protocol currently being used.The request parameters used to create this session.The request URI this session was opened under.boolean
isOpen()
Whether the session is open.boolean
isSecure()
Whether the connection is secure.boolean
Whether the session is writable.names()
put
(CharSequence key, @Nullable Object value) Insert a value for the given key and value.remove
(CharSequence key) Remove a value for the given key.<T> reactor.core.publisher.Flux<T>
Send the given message to the remote peer.<T> CompletableFuture<T>
Send the given message to the remote peer asynchronously.sendPingAsync
(@io.micronaut.core.annotation.NonNull byte[] content) Send a ping through this WebSocket.void
Send the given message to the remote peer synchronously.toString()
values()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.micronaut.core.convert.value.ConvertibleValues
asMap, asMap, asProperties, contains, forEach, getConversionService, getValue, getValueType, isEmpty, iterator, subMap, subMap, subMap
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface io.micronaut.core.convert.value.MutableConvertibleValues
putAll, putAll
Methods inherited from interface io.micronaut.core.value.ValueResolver
get, get, get
Methods inherited from interface io.micronaut.websocket.WebSocketSession
getSubprotocol, getUriVariables, getUserPrincipal, send, sendAsync, sendSync
-
Field Details
-
WEB_SOCKET_SESSION_KEY
The WebSocket session is stored within a Channel attribute using the given key.
-
-
Constructor Details
-
NettyWebSocketSession
protected NettyWebSocketSession(String id, io.netty.channel.Channel channel, HttpRequest<?> request, MediaTypeCodecRegistry codecRegistry, String protocolVersion, boolean isSecure) Creates a new netty web socket session.- Parameters:
id
- The IDchannel
- The channelrequest
- The original request used to create the sessioncodecRegistry
- The codec registryprotocolVersion
- The protocol versionisSecure
- Whether the session is secure
-
-
Method Details
-
getId
Description copied from interface:WebSocketSession
The ID of the session.- Specified by:
getId
in interfaceWebSocketSession
- Returns:
- The ID of the session
-
getAttributes
- Specified by:
getAttributes
in interfaceWebSocketSession
- Returns:
- Only the attributes of the session
-
isOpen
public boolean isOpen()Description copied from interface:WebSocketSession
Whether the session is open.- Specified by:
isOpen
in interfaceWebSocketSession
- Returns:
- True if it is
-
isWritable
public boolean isWritable()Description copied from interface:WebSocketSession
Whether the session is writable. It may not be writable, if the buffer is currently full- Specified by:
isWritable
in interfaceWebSocketSession
- Returns:
- True if it is
-
isSecure
public boolean isSecure()Description copied from interface:WebSocketSession
Whether the connection is secure.- Specified by:
isSecure
in interfaceWebSocketSession
- Returns:
- True if it is secure
-
getOpenSessions
Description copied from interface:WebSocketSession
The current open sessions.- Specified by:
getOpenSessions
in interfaceWebSocketSession
- Returns:
- The open sessions
-
getRequestURI
Description copied from interface:WebSocketSession
The request URI this session was opened under.- Specified by:
getRequestURI
in interfaceWebSocketSession
- Returns:
- The request URI
-
getRequestParameters
Description copied from interface:WebSocketSession
The request parameters used to create this session.- Specified by:
getRequestParameters
in interfaceWebSocketSession
- Returns:
- The request parameters
-
getProtocolVersion
Description copied from interface:WebSocketSession
The protocol version of the WebSocket protocol currently being used.- Specified by:
getProtocolVersion
in interfaceWebSocketSession
- Returns:
- The protocol version
-
sendAsync
Description copied from interface:WebSocketSession
Send the given message to the remote peer asynchronously.- Specified by:
sendAsync
in interfaceWebSocketSession
- Type Parameters:
T
- The message type- Parameters:
message
- The messagemediaType
- The media type of the message. Used to lookup an appropriate codec via theMediaTypeCodecRegistry
.- 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
Description copied from interface:WebSocketSession
Send the given message to the remote peer synchronously.- Specified by:
sendSync
in interfaceWebSocketSession
- Parameters:
message
- The messagemediaType
- The media type of the message. Used to lookup an appropriate codec via theMediaTypeCodecRegistry
.
-
send
Description copied from interface:WebSocketSession
Send the given message to the remote peer. The resultingPublisher
does not start sending until subscribed to. If you return it from Micronaut annotated methods such asOnOpen
andOnMessage
, Micronaut will subscribe to it and send the message without blocking.- Specified by:
send
in interfaceWebSocketSession
- Type Parameters:
T
- The message type- Parameters:
message
- The messagemediaType
- The media type of the message. Used to lookup an appropriate codec via theMediaTypeCodecRegistry
.- Returns:
- A
Publisher
that either emits an error or emits the message once it has been published successfully.
-
sendPingAsync
@NonNull public @NonNull CompletableFuture<?> sendPingAsync(@NonNull @io.micronaut.core.annotation.NonNull byte[] content) Description copied from interface:WebSocketSession
Send a ping through this WebSocket. The pong reply can be intercepted using a@OnMessage
method that accepts aWebSocketPongMessage
.- Specified by:
sendPingAsync
in interfaceWebSocketSession
- Parameters:
content
- The content of the ping. The remote should return the same content in itsWebSocketPongMessage
.- Returns:
- A future that completes when the ping has been sent. (Not when the pong has been received!)
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceWebSocketSession
-
close
Description copied from interface:WebSocketSession
Close the session with the given event.- Specified by:
close
in interfaceWebSocketSession
- Parameters:
closeReason
- The close event
-
toString
-
put
Description copied from interface:MutableConvertibleValues
Insert a value for the given key and value.- Specified by:
put
in interfaceMutableConvertibleValues<Object>
- Parameters:
key
- The keyvalue
- The value- Returns:
- This values instance
-
remove
Description copied from interface:MutableConvertibleValues
Remove a value for the given key.- Specified by:
remove
in interfaceMutableConvertibleValues<Object>
- Parameters:
key
- The key- Returns:
- This values instance
-
clear
Description copied from interface:MutableConvertibleValues
Clear all values.- Specified by:
clear
in interfaceMutableConvertibleValues<Object>
- Returns:
- This values instance
-
names
- Specified by:
names
in interfaceConvertibleValues<Object>
- Returns:
- The names of the values
-
values
- Specified by:
values
in interfaceConvertibleValues<Object>
- Returns:
- The values
-
get
Description copied from interface:ValueResolver
Resolve the given property for the given name.- Specified by:
get
in interfaceValueResolver<CharSequence>
- Type Parameters:
T
- The concrete type- Parameters:
name
- The nameconversionContext
- The conversion context- Returns:
- An optional containing the property value if it exists and is able to be converted
-