Class BasicRequestProducer
- java.lang.Object
-
- org.apache.hc.core5.http.nio.support.BasicRequestProducer
-
- All Implemented Interfaces:
AsyncDataProducer,AsyncRequestProducer,ResourceHolder
public class BasicRequestProducer extends java.lang.Object implements AsyncRequestProducer
Basic implementation ofAsyncRequestProducerthat produces one fixed request and relies on aAsyncEntityProducerto generate request entity stream.- Since:
- 5.0
-
-
Field Summary
Fields Modifier and Type Field Description private AsyncEntityProducerdataProducerprivate HttpRequestrequest
-
Constructor Summary
Constructors Constructor Description BasicRequestProducer(java.lang.String method, java.net.URI requestUri)BasicRequestProducer(java.lang.String method, java.net.URI requestUri, AsyncEntityProducer dataProducer)BasicRequestProducer(java.lang.String method, HttpHost host, java.lang.String path)BasicRequestProducer(java.lang.String method, HttpHost host, java.lang.String path, AsyncEntityProducer dataProducer)BasicRequestProducer(HttpRequest request, AsyncEntityProducer dataProducer)BasicRequestProducer(Method method, java.net.URI requestUri)BasicRequestProducer(Method method, java.net.URI requestUri, AsyncEntityProducer dataProducer)BasicRequestProducer(Method method, HttpHost host, java.lang.String path)BasicRequestProducer(Method method, HttpHost host, java.lang.String path, AsyncEntityProducer dataProducer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Returns the number of bytes immediately available for output.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.voidreleaseResources()voidsendRequest(RequestChannel requestChannel, HttpContext httpContext)Triggered to signal the ability of the underlying request channel to accept a request messages.
-
-
-
Field Detail
-
request
private final HttpRequest request
-
dataProducer
private final AsyncEntityProducer dataProducer
-
-
Constructor Detail
-
BasicRequestProducer
public BasicRequestProducer(HttpRequest request, AsyncEntityProducer dataProducer)
-
BasicRequestProducer
public BasicRequestProducer(java.lang.String method, HttpHost host, java.lang.String path, AsyncEntityProducer dataProducer)
-
BasicRequestProducer
public BasicRequestProducer(java.lang.String method, HttpHost host, java.lang.String path)
-
BasicRequestProducer
public BasicRequestProducer(java.lang.String method, java.net.URI requestUri, AsyncEntityProducer dataProducer)
-
BasicRequestProducer
public BasicRequestProducer(java.lang.String method, java.net.URI requestUri)
-
BasicRequestProducer
public BasicRequestProducer(Method method, HttpHost host, java.lang.String path, AsyncEntityProducer dataProducer)
-
BasicRequestProducer
public BasicRequestProducer(Method method, HttpHost host, java.lang.String path)
-
BasicRequestProducer
public BasicRequestProducer(Method method, java.net.URI requestUri, AsyncEntityProducer dataProducer)
-
BasicRequestProducer
public BasicRequestProducer(Method method, java.net.URI requestUri)
-
-
Method Detail
-
sendRequest
public void sendRequest(RequestChannel requestChannel, HttpContext httpContext) 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:
requestChannel- the request channel capable to accepting a request message.httpContext- the actual execution context.- Throws:
HttpException- in case of an HTTP protocol violation.java.io.IOException- in case of an I/O error.
-
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()
-
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
-
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
-
-