Class ClassicToAsyncRequestProducer
- java.lang.Object
-
- org.apache.hc.core5.http.nio.support.classic.ClassicToAsyncRequestProducer
-
- All Implemented Interfaces:
AsyncDataProducer,AsyncRequestProducer,ResourceHolder
@Experimental public class ClassicToAsyncRequestProducer extends java.lang.Object implements AsyncRequestProducer
- Since:
- 5.4
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classClassicToAsyncRequestProducer.InternalOutputStreamstatic interfaceClassicToAsyncRequestProducer.IORunnable
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicReference<SharedOutputBuffer>bufferRefprivate java.util.concurrent.CountDownLatchcountDownLatchprivate java.util.concurrent.atomic.AtomicReference<java.lang.Exception>exceptionRefprivate intinitialBufferSizeprivate booleanrepeatableprivate ClassicHttpRequestrequestprivate Timeouttimeout
-
Constructor Summary
Constructors Constructor Description ClassicToAsyncRequestProducer(ClassicHttpRequest request, int initialBufferSize, Timeout timeout)ClassicToAsyncRequestProducer(ClassicHttpRequest request, Timeout timeout)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Returns the number of bytes immediately available for output.ClassicToAsyncRequestProducer.IORunnableblockWaiting()voidfailed(java.lang.Exception cause)Triggered to signal a failure in data generation.booleanisRepeatable()Tests whether the producer can consistently produce the same content after invocation ofResourceHolder.releaseResources().voidproduce(DataStreamChannel channel)Triggered to signal the ability of the underlying data channel to accept more data.(package private) voidpropagateException()voidreleaseResources()voidsendRequest(RequestChannel channel, HttpContext context)Triggered to signal the ability of the underlying request channel to accept a request messages.
-
-
-
Field Detail
-
request
private final ClassicHttpRequest request
-
initialBufferSize
private final int initialBufferSize
-
timeout
private final Timeout timeout
-
countDownLatch
private final java.util.concurrent.CountDownLatch countDownLatch
-
bufferRef
private final java.util.concurrent.atomic.AtomicReference<SharedOutputBuffer> bufferRef
-
exceptionRef
private final java.util.concurrent.atomic.AtomicReference<java.lang.Exception> exceptionRef
-
repeatable
private volatile boolean repeatable
-
-
Constructor Detail
-
ClassicToAsyncRequestProducer
public ClassicToAsyncRequestProducer(ClassicHttpRequest request, int initialBufferSize, Timeout timeout)
-
ClassicToAsyncRequestProducer
public ClassicToAsyncRequestProducer(ClassicHttpRequest request, Timeout timeout)
-
-
Method Detail
-
propagateException
void propagateException() throws java.io.IOException- Throws:
java.io.IOException
-
blockWaiting
public ClassicToAsyncRequestProducer.IORunnable blockWaiting() throws java.io.IOException, java.lang.InterruptedException
- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
sendRequest
public void sendRequest(RequestChannel channel, HttpContext context) throws HttpException, java.io.IOException
Description copied from interface:AsyncRequestProducerTriggered to signal the ability of the underlying request channel to accept a request messages. The data producer can choose to send a request message immediately inside the call or asynchronously at some later point.- Specified by:
sendRequestin interfaceAsyncRequestProducer- Parameters:
channel- the request channel capable to accepting a request message.context- the actual execution context.- Throws:
HttpException- in case of an HTTP protocol violation.java.io.IOException- in case of an I/O error.
-
isRepeatable
public boolean isRepeatable()
Description copied from interface:AsyncRequestProducerTests whether the producer can consistently produce the same content after invocation ofResourceHolder.releaseResources().- Specified by:
isRepeatablein interfaceAsyncRequestProducer
-
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()
-
failed
public void failed(java.lang.Exception cause)
Description copied from interface:AsyncRequestProducerTriggered to signal a failure in data generation.- Specified by:
failedin interfaceAsyncRequestProducer- Parameters:
cause- the cause of the failure.
-
releaseResources
public void releaseResources()
- Specified by:
releaseResourcesin interfaceResourceHolder
-
-