org.springframework.http.server.reactive

## Class AbstractListenerWriteFlushProcessor<T>

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

- Type Parameters:
    `T` - the type of element signaled to the `Subscriber`
  All Implemented Interfaces:
    Processor<Publisher<? extends T>,Void>, Publisher<Void>, Subscriber<Publisher<? extends T>>

      public abstract class AbstractListenerWriteFlushProcessor<T>
      extends Object
      implements Processor<Publisher<? extends T>,Void>

  An alternative to `AbstractListenerWriteProcessor` but instead writing a `Publisher<Publisher<T>>` with flush boundaries enforces after the completion of each nested Publisher.
  Since:
    5.0
  Author:
    Arjen Poutsma, Violeta Georgieva, Rossen Stoyanchev

- - ### Field Summary

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

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractListenerWriteFlushProcessor()`
    `AbstractListenerWriteFlushProcessor(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 void` | `cancel()` Cancel the upstream chain of "write" Publishers only, for example due to Servlet container error/completion notifications.
    `protected abstract Processor<? super T,Void>` | `createWriteProcessor()` Create a new processor for the current flush boundary.
    `protected abstract void` | `flush()` Flush the output if ready, or otherwise `isFlushPending()` should return true after.
    `protected void` | `flushingFailed(Throwable t)` Invoked when an error happens while flushing.
    `String` | `getLogPrefix()` Create an instance with the given log prefix.
    `protected abstract boolean` | `isFlushPending()` Whether flushing is pending.
    `protected abstract boolean` | `isWritePossible()` Whether writing/flushing is possible.
    `void` | `onComplete()` Completion signal from the upstream, write Publisher.
    `void` | `onError(Throwable ex)` Error signal from the upstream, write Publisher.
    `protected void` | `onFlushPossible()` Invoked when flushing is possible, either in the same thread after a check via `isWritePossible()`, or as a callback from the underlying container.
    `void` | `onNext(Publisher<? extends T> publisher)`
    `void` | `onSubscribe(Subscription subscription)`
    `void` | `subscribe(Subscriber<? super Void> subscriber)`

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

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

- - ### Field Detail

    - #### rsWriteFlushLogger

          protected static final Log rsWriteFlushLogger

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

  - ### Constructor Detail

    - #### AbstractListenerWriteFlushProcessor

          public AbstractListenerWriteFlushProcessor()

    - #### AbstractListenerWriteFlushProcessor

          public AbstractListenerWriteFlushProcessor(String logPrefix)

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

  - ### Method Detail

    - #### getLogPrefix

          public String getLogPrefix()

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

    - #### onSubscribe

          public final void onSubscribe(Subscription subscription)

      Specified by:
        `onSubscribe` in interface `Subscriber<Publisher<? extends T>>`

    - #### onNext

          public final void onNext(Publisher<? extends T> publisher)

      Specified by:
        `onNext` in interface `Subscriber<Publisher<? extends T>>`

    - #### onError

          public final void onError(Throwable ex)

      Error signal from the upstream, write Publisher. This is also used by subclasses to delegate error notifications from the container.
      Specified by:
        `onError` in interface `Subscriber<Publisher<? extends T>>`

    - #### onComplete

          public final void onComplete()

      Completion signal from the upstream, write Publisher. This is also used by subclasses to delegate completion notifications from the container.
      Specified by:
        `onComplete` in interface `Subscriber<Publisher<? extends T>>`

    - #### onFlushPossible

          protected final void onFlushPossible()

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

    - #### cancel

          protected void cancel()

      Cancel the upstream chain of "write" Publishers only, for example due to Servlet container error/completion notifications. This should usually be followed up with a call to either `onError(Throwable)` or `onComplete()` to notify the downstream chain, that is unless cancellation came from downstream.

    - #### subscribe

          public final void subscribe(Subscriber<? super Void> subscriber)

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

    - #### createWriteProcessor

          protected abstract Processor<? super T,Void> createWriteProcessor()

      Create a new processor for the current flush boundary.

    - #### isWritePossible

          protected abstract boolean isWritePossible()

      Whether writing/flushing is possible.

    - #### flush

          protected abstract void flush()
                                 throws IOException

      Flush the output if ready, or otherwise `isFlushPending()` should return true after.

      This is primarily for the Servlet non-blocking I/O API where flush cannot be called without a readyToWrite check.

      Throws:
        `IOException`

    - #### isFlushPending

          protected abstract boolean isFlushPending()

      Whether flushing is pending.

      This is primarily for the Servlet non-blocking I/O API where flush cannot be called without a readyToWrite check.

    - #### flushingFailed

          protected void flushingFailed(Throwable t)

      Invoked when an error happens while flushing.

      The default implementation cancels the upstream write publisher and sends an onError downstream as the result of request handling.