Class AbstractListenerWebsocketsession<T>
- Type Parameters:
T- the native delegate type
- All Implemented Interfaces:
subscriber<Void>, Websocketsession
- Direct Known subclasses:
standardWebsocketsession
Websocketsession implementations that bridge between
event-listener Websocket APIs (for example, Jakarta Websocket API (JsR-356), Jetty)
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 class Write processor for outbound Websocket messages. -
Field summary
Fields inherited from class AbstractWebsocketsession
logger -
Constructor summary
ConstructorsConstructorDescriptionAbstractListenerWebsocketsession(T delegate, string id, HandshakeInfo info, DataBufferFactory bufferFactory) Base constructor.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. -
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. void void void voidonsubscribe(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 AbstractWebsocketsession
binaryMessage, bufferFactory, getAttributes, getDelegate, getHandshakeInfo, getId, getLogPrefix, pingMessage, pongMessage, textMessage, tostringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface 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.
-
-
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:
receive in interface Websocketsession- specified by:
receive in class AbstractWebsocketsession<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:
send in interface Websocketsession- specified by:
send in class AbstractWebsocketsession<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:
closestatus in interface Websocketsession
-
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:
onsubscribe in interface subscriber<T>
-
onNext
- specified by:
onNext in interface subscriber<T>
-
onError
- specified by:
onError in interface subscriber<T>
-
onComplete
public void onComplete()- specified by:
onComplete in interface subscriber<T>
-