Class AbstractListenerWebSocketSession<T>
- Type Parameters:
T- the native delegate type
- All Implemented Interfaces:
Subscriber<Void>,WebSocketSession
- Direct Known Subclasses:
JettyWebSocketSession,StandardWebSocketSession,UndertowWebSocketSession
WebSocketSession implementations that bridge between
event-listener WebSocket APIs (e.g. Java WebSocket API JSR-356, Jetty,
Undertow) and Reactive Streams.
Also implements Subscriber<Void> so it can be used to subscribe to
the completion of WebSocketHandler.handle(WebSocketSession).
- Since:
- 5.0
- Author:
- Violeta Georgieva, Rossen Stoyanchev
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected final classProcessor to send web socket messages. -
Field Summary
Fields inherited from class org.springframework.web.reactive.socket.adapter.AbstractWebSocketSession
logger -
Constructor Summary
ConstructorsConstructorDescriptionAbstractListenerWebSocketSession(T delegate, String id, HandshakeInfo info, DataBufferFactory bufferFactory) Base constructor.AbstractListenerWebSocketSession(T delegate, String id, HandshakeInfo info, DataBufferFactory bufferFactory, reactor.core.publisher.MonoProcessor<Void> handlerCompletion) Deprecated.AbstractListenerWebSocketSession(T delegate, String id, HandshakeInfo info, DataBufferFactory bufferFactory, reactor.core.publisher.Sinks.Empty<Void> handlerCompletionSink) Alternative constructor with completion sink to use to signal when the handling of the session is complete, with success or error. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract booleanWhether the underlying WebSocket API has flow control and can suspend and resume the receiving of messages.reactor.core.publisher.Mono<CloseStatus>Provides access to theCloseStatuswith which the session is closed either locally or remotely, or completes empty if the session ended without a status.voidvoidvoidvoidonSubscribe(Subscription subscription) reactor.core.publisher.Flux<WebSocketMessage>receive()Provides access to the stream of inbound messages.protected abstract voidResume receiving new message(s) after demand is generated by the downstream Subscriber.reactor.core.publisher.Mono<Void>send(Publisher<WebSocketMessage> messages) Give a source of outgoing messages, write the messages and return aMono<Void>that completes when the source completes and writing is done.protected abstract booleansendMessage(WebSocketMessage message) Send the given WebSocket message.protected abstract voidSuspend receiving until received message(s) are processed and more demand is generated by the downstream Subscriber.Methods inherited from class org.springframework.web.reactive.socket.adapter.AbstractWebSocketSession
binaryMessage, bufferFactory, getAttributes, getDelegate, getHandshakeInfo, getId, getLogPrefix, pingMessage, pongMessage, textMessage, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.web.reactive.socket.WebSocketSession
close, close, isOpen
-
Constructor Details
-
AbstractListenerWebSocketSession
public AbstractListenerWebSocketSession(T delegate, String id, HandshakeInfo info, DataBufferFactory bufferFactory) Base constructor.- Parameters:
delegate- the native WebSocket session, channel, or connectionid- the session idinfo- the handshake infobufferFactory- the DataBuffer factor for the current connection
-
AbstractListenerWebSocketSession
public AbstractListenerWebSocketSession(T delegate, String id, HandshakeInfo info, DataBufferFactory bufferFactory, @Nullable reactor.core.publisher.Sinks.Empty<Void> handlerCompletionSink) Alternative constructor with completion sink to use to signal when the handling of the session is complete, with success or error.Primarily for use with
WebSocketClientto be able to communicate the end of handling. -
AbstractListenerWebSocketSession
@Deprecated public AbstractListenerWebSocketSession(T delegate, String id, HandshakeInfo info, DataBufferFactory bufferFactory, @Nullable reactor.core.publisher.MonoProcessor<Void> handlerCompletion) Deprecated.Alternative constructor with completion MonoProcessor to use to signal when the handling of the session is complete, with success or error.Primarily for use with
WebSocketClientto be able to communicate the end of handling.
-
-
Method Details
-
getSendProcessor
-
receive
Description copied from interface:WebSocketSessionProvides access to the stream of inbound messages.This stream receives a completion or error signal when the connection is closed. In a typical
WebSocketHandlerimplementation this stream is composed into the overall processing flow, so that when the connection is closed, handling will end.See the class-level doc of
WebSocketHandlerand the reference for more details and examples of how to handle the session.- Specified by:
receivein interfaceWebSocketSession- Specified by:
receivein classAbstractWebSocketSession<T>
-
send
Description copied from interface:WebSocketSessionGive a source of outgoing messages, write the messages and return aMono<Void>that completes when the source completes and writing is done.See the class-level doc of
WebSocketHandlerand the reference for more details and examples of how to handle the session.- Specified by:
sendin interfaceWebSocketSession- Specified by:
sendin classAbstractWebSocketSession<T>
-
closeStatus
Description copied from interface:WebSocketSessionProvides access to theCloseStatuswith which the session is closed either locally or remotely, or completes empty if the session ended without a status.- Specified by:
closeStatusin interfaceWebSocketSession
-
canSuspendReceiving
protected abstract boolean canSuspendReceiving()Whether the underlying WebSocket API has flow control and can suspend and resume the receiving of messages.Note: Sub-classes are encouraged to start out in suspended mode, if possible, and wait until demand is received.
-
suspendReceiving
protected abstract void suspendReceiving()Suspend receiving until received message(s) are processed and more demand is generated by the downstream Subscriber.Note: if the underlying WebSocket API does not provide flow control for receiving messages, this method should be a no-op and
canSuspendReceiving()should returnfalse. -
resumeReceiving
protected abstract void resumeReceiving()Resume receiving new message(s) after demand is generated by the downstream Subscriber.Note: if the underlying WebSocket API does not provide flow control for receiving messages, this method should be a no-op and
canSuspendReceiving()should returnfalse. -
sendMessage
Send the given WebSocket message.Note: Sub-classes are responsible for releasing the payload data buffer, once fully written, if pooled buffers apply to the underlying container.
- Throws:
IOException
-
onSubscribe
- Specified by:
onSubscribein interfaceSubscriber<T>
-
onNext
- Specified by:
onNextin interfaceSubscriber<T>
-
onError
- Specified by:
onErrorin interfaceSubscriber<T>
-
onComplete
public void onComplete()- Specified by:
onCompletein interfaceSubscriber<T>
-
AbstractListenerWebSocketSession(Object, String, HandshakeInfo, DataBufferFactory, Sinks.Empty)