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
FieldsModifier 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
ConstructorsModifierConstructorDescriptionprotectedNettyWebSocketSession(String id, io.netty.channel.Channel channel, HttpRequest<?> request, MediaTypeCodecRegistry codecRegistry, MessageBodyHandlerRegistry handlerRegistry, String protocolVersion, boolean isSecure) Creates a new netty web socket session. -
Method Summary
Modifier and TypeMethodDescriptionclear()Clear all values.voidclose()voidclose(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.booleanisOpen()Whether the session is open.booleanisSecure()Whether the connection is secure.booleanWhether 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.voidSend 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, waitMethods inherited from interface io.micronaut.core.convert.value.ConvertibleValues
asMap, asMap, asProperties, contains, forEach, getConversionService, getValue, getValueType, isEmpty, iterator, subMap, subMap, subMapMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface io.micronaut.core.convert.value.MutableConvertibleValues
putAll, putAllMethods inherited from interface io.micronaut.core.value.ValueResolver
get, get, getMethods 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, MessageBodyHandlerRegistry handlerRegistry, 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 registryhandlerRegistry- The handlers registryprotocolVersion- The protocol versionisSecure- Whether the session is secure
-
-
Method Details
-
getId
Description copied from interface:WebSocketSessionThe ID of the session.- Specified by:
getIdin interfaceWebSocketSession- Returns:
- The ID of the session
-
getAttributes
- Specified by:
getAttributesin interfaceWebSocketSession- Returns:
- Only the attributes of the session
-
isOpen
public boolean isOpen()Description copied from interface:WebSocketSessionWhether the session is open.- Specified by:
isOpenin interfaceWebSocketSession- Returns:
- True if it is
-
isWritable
public boolean isWritable()Description copied from interface:WebSocketSessionWhether the session is writable. It may not be writable, if the buffer is currently full- Specified by:
isWritablein interfaceWebSocketSession- Returns:
- True if it is
-
isSecure
public boolean isSecure()Description copied from interface:WebSocketSessionWhether the connection is secure.- Specified by:
isSecurein interfaceWebSocketSession- Returns:
- True if it is secure
-
getOpenSessions
Description copied from interface:WebSocketSessionThe current open sessions.- Specified by:
getOpenSessionsin interfaceWebSocketSession- Returns:
- The open sessions
-
getRequestURI
Description copied from interface:WebSocketSessionThe request URI this session was opened under.- Specified by:
getRequestURIin interfaceWebSocketSession- Returns:
- The request URI
-
getRequestParameters
Description copied from interface:WebSocketSessionThe request parameters used to create this session.- Specified by:
getRequestParametersin interfaceWebSocketSession- Returns:
- The request parameters
-
getProtocolVersion
Description copied from interface:WebSocketSessionThe protocol version of the WebSocket protocol currently being used.- Specified by:
getProtocolVersionin interfaceWebSocketSession- Returns:
- The protocol version
-
sendAsync
Description copied from interface:WebSocketSessionSend the given message to the remote peer asynchronously.- Specified by:
sendAsyncin interfaceWebSocketSession- Type Parameters:
T- The message type- Parameters:
message- The messagemediaType- The media type of the message. Used to look up an appropriate codec via theMediaTypeCodecRegistry.- Returns:
- A
CompletableFuturethat 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:WebSocketSessionSend the given message to the remote peer synchronously.- Specified by:
sendSyncin interfaceWebSocketSession- Parameters:
message- The messagemediaType- The media type of the message. Used to look up an appropriate codec via theMediaTypeCodecRegistry.
-
send
Description copied from interface:WebSocketSessionSend the given message to the remote peer. The resultingPublisherdoes not start sending until subscribed to. If you return it from Micronaut annotated methods such asOnOpenandOnMessage, Micronaut will subscribe to it and send the message without blocking.- Specified by:
sendin interfaceWebSocketSession- Type Parameters:
T- The message type- Parameters:
message- The messagemediaType- The media type of the message. Used to look up an appropriate codec via theMediaTypeCodecRegistry.- Returns:
- A
Publisherthat 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:WebSocketSessionSend a ping through this WebSocket. The pong reply can be intercepted using a@OnMessagemethod that accepts aWebSocketPongMessage.- Specified by:
sendPingAsyncin 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceWebSocketSession
-
close
Description copied from interface:WebSocketSessionClose the session with the given event.- Specified by:
closein interfaceWebSocketSession- Parameters:
closeReason- The close event
-
toString
-
put
Description copied from interface:MutableConvertibleValuesInsert a value for the given key and value.- Specified by:
putin interfaceMutableConvertibleValues<Object>- Parameters:
key- The keyvalue- The value- Returns:
- This values instance
-
remove
Description copied from interface:MutableConvertibleValuesRemove a value for the given key.- Specified by:
removein interfaceMutableConvertibleValues<Object>- Parameters:
key- The key- Returns:
- This values instance
-
clear
Description copied from interface:MutableConvertibleValuesClear all values.- Specified by:
clearin interfaceMutableConvertibleValues<Object>- Returns:
- This values instance
-
names
- Specified by:
namesin interfaceConvertibleValues<Object>- Returns:
- The names of the values
-
values
- Specified by:
valuesin interfaceConvertibleValues<Object>- Returns:
- The values
-
get
Description copied from interface:ValueResolverResolve the given property for the given name.- Specified by:
getin 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
-