Class AbstractListenerWebsocketsession<T>

java.lang.Object
org.springframework.web.reactive.socket.adapter.AbstractWebsocketsession<T>
org.springframework.web.reactive.socket.adapter.AbstractListenerWebsocketsession<T>
Type Parameters:
T - the native delegate type
All Implemented Interfaces:
subscriber<Void>, Websocketsession
Direct Known subclasses:
standardWebsocketsession

public abstract class AbstractListenerWebsocketsession<T> extends AbstractWebsocketsession<T> implements subscriber<Void>
Base class for 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
  • Constructor Details

    • AbstractListenerWebsocketsession

      public&nbsp;AbstractListenerWebsocketsession(T&nbsp;delegate, string&nbsp;id, HandshakeInfo&nbsp;info, DataBufferFactory&nbsp;bufferFactory)
      Base constructor.
      Parameters:
      delegate - the native Websocket session, channel, or connection
      id - the session id
      info - the handshake info
      bufferFactory - the DataBuffer factor for the current connection
    • AbstractListenerWebsocketsession

      public&nbsp;AbstractListenerWebsocketsession(T&nbsp;delegate, string&nbsp;id, HandshakeInfo&nbsp;info, DataBufferFactory&nbsp;bufferFactory, @Nullable reactor.core.publisher.sinks.Empty<Void>&nbsp;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 WebsocketClient to be able to communicate the end of handling.

  • Method Details

    • getsendProcessor

      protected&nbsp;AbstractListenerWebsocketsession<T>.WebsocketsendProcessor&nbsp;getsendProcessor()
    • receive

      public&nbsp;reactor.core.publisher.Flux<WebsocketMessage>&nbsp;receive()
      Description copied from interface:&nbsp;Websocketsession
      Provides access to the stream of inbound messages.

      This stream receives a completion or error signal when the connection is closed. In a typical WebsocketHandler implementation 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 WebsocketHandler and the reference for more details and examples of how to handle the session.

      specified by:
      receive&nbsp;in interface&nbsp;Websocketsession
      specified by:
      receive&nbsp;in class&nbsp;AbstractWebsocketsession<T>
    • send

      public&nbsp;reactor.core.publisher.Mono<Void>&nbsp;send(Publisher<WebsocketMessage>&nbsp;messages)
      Description copied from interface:&nbsp;Websocketsession
      Give a source of outgoing messages, write the messages and return a Mono<Void> that completes when the source completes and writing is done.

      see the class-level doc of WebsocketHandler and the reference for more details and examples of how to handle the session.

      specified by:
      send&nbsp;in interface&nbsp;Websocketsession
      specified by:
      send&nbsp;in class&nbsp;AbstractWebsocketsession<T>
    • closestatus

      public&nbsp;reactor.core.publisher.Mono<Closestatus>&nbsp;closestatus()
      Description copied from interface:&nbsp;Websocketsession
      Provides access to the Closestatus with which the session is closed either locally or remotely, or completes empty if the session ended without a status.
      specified by:
      closestatus&nbsp;in interface&nbsp;Websocketsession
    • cansuspendReceiving

      protected abstract&nbsp;boolean&nbsp;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&nbsp;void&nbsp;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 return false.

    • resumeReceiving

      protected abstract&nbsp;void&nbsp;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 return false.

    • sendMessage

      protected abstract&nbsp;boolean&nbsp;sendMessage(WebsocketMessage&nbsp;message) throws IOException
      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

      public&nbsp;void&nbsp;onsubscribe(subscription&nbsp;subscription)
      specified by:
      onsubscribe&nbsp;in interface&nbsp;subscriber<T>
    • onNext

      public&nbsp;void&nbsp;onNext(Void&nbsp;aVoid)
      specified by:
      onNext&nbsp;in interface&nbsp;subscriber<T>
    • onError

      public&nbsp;void&nbsp;onError(Throwable&nbsp;ex)
      specified by:
      onError&nbsp;in interface&nbsp;subscriber<T>
    • onComplete

      public&nbsp;void&nbsp;onComplete()
      specified by:
      onComplete&nbsp;in interface&nbsp;subscriber<T>