Package org.apache.hc.core5.reactive
Class ReactiveDataConsumer
- java.lang.Object
-
- org.apache.hc.core5.reactive.ReactiveDataConsumer
-
- All Implemented Interfaces:
AsyncDataConsumer,ResourceHolder,org.reactivestreams.Publisher<java.nio.ByteBuffer>
@Contract(threading=SAFE) final class ReactiveDataConsumer extends java.lang.Object implements AsyncDataConsumer, org.reactivestreams.Publisher<java.nio.ByteBuffer>
An asynchronous data consumer that supports Reactive Streams.- Since:
- 5.0
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.BlockingQueue<java.nio.ByteBuffer>buffersprivate booleancancelledprivate CapacityChannelcapacityChannelprivate booleancompletedprivate java.lang.Exceptionexceptionprivate java.util.concurrent.atomic.AtomicBooleanflushInProgressprivate java.lang.ObjectflushLockprivate java.util.concurrent.atomic.AtomicLongrequestsprivate org.reactivestreams.Subscriber<? super java.nio.ByteBuffer>subscriberprivate java.util.concurrent.atomic.AtomicIntegerwindowScalingIncrement
-
Constructor Summary
Constructors Constructor Description ReactiveDataConsumer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconsume(java.nio.ByteBuffer byteBuffer)Triggered to pass incoming data to the data consumer.voidfailed(java.lang.Exception cause)private voidflushToSubscriber()voidreleaseResources()private voidsignalCapacity(CapacityChannel channel)voidstreamEnd(java.util.List<? extends Header> trailers)Triggered to signal termination of the data stream.voidsubscribe(org.reactivestreams.Subscriber<? super java.nio.ByteBuffer> subscriber)private voidthrowIfCancelled()voidupdateCapacity(CapacityChannel capacityChannel)Triggered to signal ability of the underlying data stream to receive data capacity update.
-
-
-
Field Detail
-
requests
private final java.util.concurrent.atomic.AtomicLong requests
-
buffers
private final java.util.concurrent.BlockingQueue<java.nio.ByteBuffer> buffers
-
flushInProgress
private final java.util.concurrent.atomic.AtomicBoolean flushInProgress
-
flushLock
private final java.lang.Object flushLock
-
windowScalingIncrement
private final java.util.concurrent.atomic.AtomicInteger windowScalingIncrement
-
cancelled
private volatile boolean cancelled
-
completed
private volatile boolean completed
-
exception
private volatile java.lang.Exception exception
-
capacityChannel
private volatile CapacityChannel capacityChannel
-
subscriber
private volatile org.reactivestreams.Subscriber<? super java.nio.ByteBuffer> subscriber
-
-
Method Detail
-
failed
public void failed(java.lang.Exception cause)
-
updateCapacity
public void updateCapacity(CapacityChannel capacityChannel) throws java.io.IOException
Description copied from interface:AsyncDataConsumerTriggered 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:
updateCapacityin interfaceAsyncDataConsumer- Parameters:
capacityChannel- the channel for capacity updates.- Throws:
java.io.IOException
-
signalCapacity
private void signalCapacity(CapacityChannel channel) throws java.io.IOException
- Throws:
java.io.IOException
-
throwIfCancelled
private void throwIfCancelled() throws java.io.IOException- Throws:
java.io.IOException
-
consume
public void consume(java.nio.ByteBuffer byteBuffer) throws java.io.IOExceptionDescription copied from interface:AsyncDataConsumerTriggered 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:
consumein interfaceAsyncDataConsumer- Parameters:
byteBuffer- data source.- Throws:
java.io.IOException
-
streamEnd
public void streamEnd(java.util.List<? extends Header> trailers)
Description copied from interface:AsyncDataConsumerTriggered to signal termination of the data stream.- Specified by:
streamEndin interfaceAsyncDataConsumer- Parameters:
trailers- data stream trailers.
-
releaseResources
public void releaseResources()
- Specified by:
releaseResourcesin interfaceResourceHolder
-
flushToSubscriber
private void flushToSubscriber()
-
subscribe
public void subscribe(org.reactivestreams.Subscriber<? super java.nio.ByteBuffer> subscriber)
- Specified by:
subscribein interfaceorg.reactivestreams.Publisher<java.nio.ByteBuffer>
-
-