Class ReactiveDataConsumer

java.lang.Object
org.apache.hc.core5.reactive.ReactiveDataConsumer
All Implemented Interfaces:
AsyncDataConsumer, ResourceHolder, org.reactivestreams.Publisher<ByteBuffer>

@Contract(threading=SAFE) final class ReactiveDataConsumer extends Object implements AsyncDataConsumer, org.reactivestreams.Publisher<ByteBuffer>
An asynchronous data consumer that supports Reactive Streams.
Since:
5.0
  • Field Details

    • requests

      private final AtomicLong requests
    • buffers

      private final BlockingQueue<ByteBuffer> buffers
    • flushInProgress

      private final AtomicBoolean flushInProgress
    • flushLock

      private final Object flushLock
    • windowScalingIncrement

      private final AtomicInteger windowScalingIncrement
    • cancelled

      private volatile boolean cancelled
    • completed

      private volatile boolean completed
    • exception

      private volatile Exception exception
    • capacityChannel

      private volatile CapacityChannel capacityChannel
    • subscriber

      private volatile org.reactivestreams.Subscriber<? super ByteBuffer> subscriber
  • Constructor Details

    • ReactiveDataConsumer

      ReactiveDataConsumer()
  • Method Details

    • failed

      public void failed(Exception cause)
    • updateCapacity

      public void updateCapacity(CapacityChannel capacityChannel) throws IOException
      Description copied from interface: AsyncDataConsumer
      Triggered to signal ability of the underlying data stream to receive data capacity update. The data consumer can choose to write data immediately inside the call or asynchronously at some later point.
      Specified by:
      updateCapacity in interface AsyncDataConsumer
      Parameters:
      capacityChannel - the channel for capacity updates.
      Throws:
      IOException
    • signalCapacity

      private void signalCapacity(CapacityChannel channel) throws IOException
      Throws:
      IOException
    • throwIfCancelled

      private void throwIfCancelled() throws IOException
      Throws:
      IOException
    • consume

      public void consume(ByteBuffer byteBuffer) throws IOException
      Description copied from interface: AsyncDataConsumer
      Triggered to pass incoming data to the data consumer. The consumer must consume the entire content of the data buffer. The consumer must stop incrementing its capacity on the capacity channel if it is unable to accept more data. Once the data consumer has handled accumulated data or allocated more intermediate storage it can update its capacity information on the capacity channel.
      Specified by:
      consume in interface AsyncDataConsumer
      Parameters:
      byteBuffer - data source.
      Throws:
      IOException
    • streamEnd

      public void streamEnd(List<? extends Header> trailers)
      Description copied from interface: AsyncDataConsumer
      Triggered to signal termination of the data stream.
      Specified by:
      streamEnd in interface AsyncDataConsumer
      Parameters:
      trailers - data stream trailers.
    • releaseResources

      public void releaseResources()
      Specified by:
      releaseResources in interface ResourceHolder
    • flushToSubscriber

      private void flushToSubscriber()
    • subscribe

      public void subscribe(org.reactivestreams.Subscriber<? super ByteBuffer> subscriber)
      Specified by:
      subscribe in interface org.reactivestreams.Publisher<ByteBuffer>