Package org.apache.hc.core5.reactive
Class ReactiveDataProducer
- java.lang.Object
-
- org.apache.hc.core5.reactive.ReactiveDataProducer
-
- All Implemented Interfaces:
AsyncDataProducer,ResourceHolder,org.reactivestreams.Subscriber<java.nio.ByteBuffer>
@Contract(threading=SAFE) final class ReactiveDataProducer extends java.lang.Object implements AsyncDataProducer, org.reactivestreams.Subscriber<java.nio.ByteBuffer>
An asynchronous data producer that supports Reactive Streams.- Since:
- 5.0
-
-
Field Summary
Fields Modifier and Type Field Description private static intBUFFER_WINDOW_SIZEprivate java.util.ArrayDeque<java.nio.ByteBuffer>buffersprivate java.util.concurrent.atomic.AtomicBooleancompleteprivate java.util.concurrent.atomic.AtomicReference<java.lang.Throwable>exceptionprivate java.util.concurrent.locks.ReentrantLocklockprivate org.reactivestreams.Publisher<java.nio.ByteBuffer>publisherprivate java.util.concurrent.atomic.AtomicReference<DataStreamChannel>requestChannelprivate java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription>subscription
-
Constructor Summary
Constructors Constructor Description ReactiveDataProducer(org.reactivestreams.Publisher<java.nio.ByteBuffer> publisher)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Returns the number of bytes immediately available for output.voidonComplete()voidonError(java.lang.Throwable throwable)voidonNext(java.nio.ByteBuffer byteBuffer)voidonSubscribe(org.reactivestreams.Subscription subscription)voidproduce(DataStreamChannel channel)Triggered to signal the ability of the underlying data channel to accept more data.voidreleaseResources()(package private) voidsetChannel(DataStreamChannel channel)private voidsignalReadiness()
-
-
-
Field Detail
-
BUFFER_WINDOW_SIZE
private static final int BUFFER_WINDOW_SIZE
- See Also:
- Constant Field Values
-
requestChannel
private final java.util.concurrent.atomic.AtomicReference<DataStreamChannel> requestChannel
-
exception
private final java.util.concurrent.atomic.AtomicReference<java.lang.Throwable> exception
-
complete
private final java.util.concurrent.atomic.AtomicBoolean complete
-
publisher
private final org.reactivestreams.Publisher<java.nio.ByteBuffer> publisher
-
subscription
private final java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> subscription
-
buffers
private final java.util.ArrayDeque<java.nio.ByteBuffer> buffers
-
lock
private final java.util.concurrent.locks.ReentrantLock lock
-
-
Method Detail
-
setChannel
void setChannel(DataStreamChannel channel)
-
onSubscribe
public void onSubscribe(org.reactivestreams.Subscription subscription)
- Specified by:
onSubscribein interfaceorg.reactivestreams.Subscriber<java.nio.ByteBuffer>
-
onNext
public void onNext(java.nio.ByteBuffer byteBuffer)
- Specified by:
onNextin interfaceorg.reactivestreams.Subscriber<java.nio.ByteBuffer>
-
onError
public void onError(java.lang.Throwable throwable)
- Specified by:
onErrorin interfaceorg.reactivestreams.Subscriber<java.nio.ByteBuffer>
-
onComplete
public void onComplete()
- Specified by:
onCompletein interfaceorg.reactivestreams.Subscriber<java.nio.ByteBuffer>
-
signalReadiness
private void signalReadiness()
-
available
public int available()
Description copied from interface:AsyncDataProducerReturns the number of bytes immediately available for output. This method can be used as a hint to control output events of the underlying I/O session.Please note this method should return zero if the data producer is unable to produce any more data, in which case
AsyncDataProducer.produce(DataStreamChannel)method will not get triggered. The producer can resume writing out data asynchronously once more data becomes available or request output readiness events withDataStreamChannel.requestOutput().- Specified by:
availablein interfaceAsyncDataProducer- Returns:
- the number of bytes immediately available for output
- See Also:
AsyncDataProducer.produce(DataStreamChannel),DataStreamChannel.requestOutput()
-
produce
public void produce(DataStreamChannel channel) throws java.io.IOException
Description copied from interface:AsyncDataProducerTriggered to signal the ability of the underlying data channel to accept more data. The data producer can choose to write data immediately inside the call or asynchronously at some later point.Please note this method gets triggered only if
AsyncDataProducer.available()returns a positive value.- Specified by:
producein interfaceAsyncDataProducer- Parameters:
channel- the data channel capable of accepting more data.- Throws:
java.io.IOException- in case of an I/O error.- See Also:
AsyncDataProducer.available()
-
releaseResources
public void releaseResources()
- Specified by:
releaseResourcesin interfaceResourceHolder
-
-