org.springframework.http.server.reactive

## Class AbstractListenerReadPublisher<T>

- java.lang.Object
- - org.springframework.http.server.reactive.AbstractListenerReadPublisher<T>

- Type Parameters:
    `T` - the type of element signaled
  All Implemented Interfaces:
    Publisher<T>

      public abstract class AbstractListenerReadPublisher<T>
      extends Object
      implements Publisher<T>

  Abstract base class for `Publisher` implementations that bridge between event-listener read APIs and Reactive Streams.

  Specifically a base class for reading from the HTTP request body with Servlet 3.1 non-blocking I/O and Undertow XNIO as well as handling incoming WebSocket messages with standard Java WebSocket (JSR-356), Jetty, and Undertow.

  Since:
    5.0
  Author:
    Arjen Poutsma, Violeta Georgieva, Rossen Stoyanchev

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static Log` | `rsReadLogger` Special logger for debugging Reactive Streams signals.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractListenerReadPublisher()`
    `AbstractListenerReadPublisher(String logPrefix)` Create an instance with the given log prefix.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract void` | `checkOnDataAvailable()` Check if data is available and either call `onDataAvailable()` immediately or schedule a notification.
    `protected abstract void` | `discardData()` Invoked after an I/O read error from the underlying server or after a cancellation signal from the downstream consumer to allow subclasses to discard any current cached data they might have.
    `String` | `getLogPrefix()` Return the configured log message prefix.
    `void` | `onAllDataRead()` Subclasses can call this method to delegate a contain notification when all data has been read.
    `void` | `onDataAvailable()` Invoked when reading is possible, either in the same thread after a check via `checkOnDataAvailable()`, or as a callback from the underlying container.
    `void` | `onError(Throwable ex)` Subclasses can call this to delegate container error notifications.
    `protected abstract T` | `read()` Read once from the input, if possible.
    `protected abstract void` | `readingPaused()` Invoked when reading is paused due to a lack of demand.
    `void` | `subscribe(Subscriber<? super T> subscriber)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### rsReadLogger

          protected static Log rsReadLogger

      Special logger for debugging Reactive Streams signals.
      See Also:
        `LogDelegateFactory.getHiddenLog(Class)`, `AbstractListenerWriteProcessor.rsWriteLogger`, `AbstractListenerWriteFlushProcessor.rsWriteFlushLogger`, `WriteResultPublisher.rsWriteResultLogger`

  - ### Constructor Detail

    - #### AbstractListenerReadPublisher

          public AbstractListenerReadPublisher()

    - #### AbstractListenerReadPublisher

          public AbstractListenerReadPublisher(String logPrefix)

      Create an instance with the given log prefix.
      Since:
        5.1

  - ### Method Detail

    - #### getLogPrefix

          public String getLogPrefix()

      Return the configured log message prefix.
      Since:
        5.1

    - #### subscribe

          public void subscribe(Subscriber<? super T> subscriber)

      Specified by:
        `subscribe` in interface `Publisher<T>`

    - #### onDataAvailable

          public final void onDataAvailable()

      Invoked when reading is possible, either in the same thread after a check via `checkOnDataAvailable()`, or as a callback from the underlying container.

    - #### onAllDataRead

          public void onAllDataRead()

      Subclasses can call this method to delegate a contain notification when all data has been read.

    - #### onError

          public final void onError(Throwable ex)

      Subclasses can call this to delegate container error notifications.

    - #### checkOnDataAvailable

          protected abstract void checkOnDataAvailable()

      Check if data is available and either call `onDataAvailable()` immediately or schedule a notification.

    - #### read

          @Nullable
          protected abstract T read()
                                       throws IOException

      Read once from the input, if possible.
      Returns:
        the item that was read; or `null`
      Throws:
        `IOException`

    - #### readingPaused

          protected abstract void readingPaused()

      Invoked when reading is paused due to a lack of demand.

      Note: This method is guaranteed not to compete with `checkOnDataAvailable()` so it can be used to safely suspend reading, if the underlying API supports it, i.e. without competing with an implicit call to resume via `checkOnDataAvailable()`.

      Since:
        5.0.2

    - #### discardData

          protected abstract void discardData()

      Invoked after an I/O read error from the underlying server or after a cancellation signal from the downstream consumer to allow subclasses to discard any current cached data they might have.
      Since:
        5.0.11