org.springframework.http.server.reactive

Class AbstractListenerWriteProcessor<T>

  • java.lang.Object
    • org.springframework.http.server.reactive.AbstractListenerWriteProcessor<T>
  • Type Parameters:
    T - the type of element signaled to the Subscriber
    All Implemented Interfaces:
    org.reactivestreams.Processor<T,java.lang.Void>, org.reactivestreams.Publisher<java.lang.Void>, org.reactivestreams.Subscriber<T>
    Direct Known Subclasses:
    AbstractListenerWebSocketSession.WebSocketSendProcessor


    public abstract class AbstractListenerWriteProcessor<T>
    extends java.lang.Object
    implements org.reactivestreams.Processor<T,java.lang.Void>
    Abstract base class for Processor implementations that bridge between event-listener write APIs and Reactive Streams.

    Specifically a base class for writing to the HTTP response body with Servlet 3.1 non-blocking I/O and Undertow XNIO as well for writing WebSocket messages through the Java WebSocket API (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 rsWriteLogger
      Special logger for debugging Reactive Streams signals.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method and Description
      void cancel()
      Invoked during an error or completion callback from the underlying container to cancel the upstream subscription.
      protected void dataReceived(T data)
      Template method invoked after a data item to write is received via Subscriber.onNext(Object).
      java.lang.String getLogPrefix()
      Create an instance with the given log prefix.
      protected abstract boolean isDataEmpty(T data)
      Whether the given data item has any content to write.
      protected abstract boolean isWritePossible()
      Whether writing is possible.
      void onComplete()
      Completion signal from the upstream, write Publisher.
      void onError(java.lang.Throwable ex)
      Error signal from the upstream, write Publisher.
      void onNext(T data) 
      void onSubscribe(org.reactivestreams.Subscription subscription) 
      void onWritePossible()
      Invoked when writing is possible, either in the same thread after a check via isWritePossible(), or as a callback from the underlying container.
      void subscribe(org.reactivestreams.Subscriber<? super java.lang.Void> subscriber) 
      protected abstract boolean write(T data)
      Write the given item.
      protected void writingComplete()
      Invoked after onComplete or onError notification.
      protected void writingFailed(java.lang.Throwable ex)
      Invoked when an I/O error occurs during a write.
      protected void writingPaused()
      Deprecated. 
      originally introduced for Undertow to stop write notifications when no data is available, but deprecated as of as of 5.0.6 since constant switching on every requested item causes a significant slowdown.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractListenerWriteProcessor

        public AbstractListenerWriteProcessor()
      • AbstractListenerWriteProcessor

        public AbstractListenerWriteProcessor(java.lang.String logPrefix)
        Create an instance with the given log prefix.
        Since:
        5.1
    • Method Detail

      • getLogPrefix

        public java.lang.String getLogPrefix()
        Create an instance with the given log prefix.
        Since:
        5.1
      • onSubscribe

        public final void onSubscribe(org.reactivestreams.Subscription subscription)
        Specified by:
        onSubscribe in interface org.reactivestreams.Subscriber<T>
      • onNext

        public final void onNext(T data)
        Specified by:
        onNext in interface org.reactivestreams.Subscriber<T>
      • onError

        public final void onError(java.lang.Throwable ex)
        Error signal from the upstream, write Publisher. This is also used by sub-classes to delegate error notifications from the container.
        Specified by:
        onError in interface org.reactivestreams.Subscriber<T>
      • onComplete

        public final void onComplete()
        Completion signal from the upstream, write Publisher. This is also used by sub-classes to delegate completion notifications from the container.
        Specified by:
        onComplete in interface org.reactivestreams.Subscriber<T>
      • onWritePossible

        public final void onWritePossible()
        Invoked when writing is possible, either in the same thread after a check via isWritePossible(), or as a callback from the underlying container.
      • cancel

        public void cancel()
        Invoked during an error or completion callback from the underlying container to cancel the upstream subscription.
      • subscribe

        public final void subscribe(org.reactivestreams.Subscriber<? super java.lang.Void> subscriber)
        Specified by:
        subscribe in interface org.reactivestreams.Publisher<java.lang.Void>
      • isDataEmpty

        protected abstract boolean isDataEmpty(T data)
        Whether the given data item has any content to write. If false the item is not written.
      • dataReceived

        protected void dataReceived(T data)
        Template method invoked after a data item to write is received via Subscriber.onNext(Object). The default implementation saves the data item for writing once that is possible.
      • isWritePossible

        protected abstract boolean isWritePossible()
        Whether writing is possible.
      • write

        protected abstract boolean write(T data)
                                  throws java.io.IOException
        Write the given item.

        Note: Sub-classes are responsible for releasing any data buffer associated with the item, once fully written, if pooled buffers apply to the underlying container.

        Parameters:
        data - the item to write
        Returns:
        whether the current data item was written and another one requested (true), or or otherwise if more writes are required.
        Throws:
        java.io.IOException
      • writingPaused

        @Deprecated
        protected void writingPaused()
        Deprecated. originally introduced for Undertow to stop write notifications when no data is available, but deprecated as of as of 5.0.6 since constant switching on every requested item causes a significant slowdown.
        Invoked after the current data has been written and before requesting the next item from the upstream, write Publisher.

        The default implementation is a no-op.

      • writingComplete

        protected void writingComplete()
        Invoked after onComplete or onError notification.

        The default implementation is a no-op.

      • writingFailed

        protected void writingFailed(java.lang.Throwable ex)
        Invoked when an I/O error occurs during a write. Sub-classes may choose to ignore this if they know the underlying API will provide an error notification in a container thread.

        Defaults to no-op.