Class BasicClientExchangeHandler<T>
- java.lang.Object
-
- org.apache.hc.core5.http.nio.support.BasicClientExchangeHandler<T>
-
- Type Parameters:
T- The result type.
- All Implemented Interfaces:
AsyncClientExchangeHandler,AsyncDataConsumer,AsyncDataExchangeHandler,AsyncDataProducer,ResourceHolder
public final class BasicClientExchangeHandler<T> extends java.lang.Object implements AsyncClientExchangeHandler
BasicAsyncClientExchangeHandlerimplementation that makes use ofAsyncRequestProducerto generate request message andAsyncResponseConsumerto process the response message returned by the server.- Since:
- 5.0
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicBooleancompletedprivate java.util.concurrent.atomic.AtomicBooleaninputTerminatedprivate java.util.concurrent.atomic.AtomicBooleanoutputTerminatedprivate AsyncRequestProducerrequestProducerprivate AsyncResponseConsumer<T>responseConsumerprivate FutureCallback<T>resultCallback
-
Constructor Summary
Constructors Constructor Description BasicClientExchangeHandler(AsyncRequestProducer requestProducer, AsyncResponseConsumer<T> responseConsumer, FutureCallback<T> resultCallback)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Returns the number of bytes immediately available for output.voidcancel()Triggered to cancel the message exchange.private voidcancelledInternal()private voidcompletedInternal(T result)voidconsume(java.nio.ByteBuffer src)Triggered to pass incoming data to the data consumer.voidconsumeInformation(HttpResponse response, HttpContext httpContext)Triggered to signal receipt of an intermediate (1xx) HTTP response.voidconsumeResponse(HttpResponse response, EntityDetails entityDetails, HttpContext httpContext)Triggered to signal receipt of a response message head.voidfailed(java.lang.Exception cause)Triggered to signal a failure in data processing.private voidfailedInternal(java.lang.Exception ex)voidproduce(DataStreamChannel channel)Triggered to signal the ability of the underlying data channel to accept more data.voidproduceRequest(RequestChannel requestChannel, HttpContext httpContext)Triggered to signal the ability of the underlying request channel to accept a request messages.private voidreleaseRequestProducer()voidreleaseResources()private voidreleaseResourcesInternal()private voidreleaseResponseConsumer()voidstreamEnd(java.util.List<? extends Header> trailers)Triggered to signal termination of the data stream.voidupdateCapacity(CapacityChannel capacityChannel)Triggered to signal ability of the underlying data stream to receive data capacity update.
-
-
-
Field Detail
-
requestProducer
private final AsyncRequestProducer requestProducer
-
responseConsumer
private final AsyncResponseConsumer<T> responseConsumer
-
completed
private final java.util.concurrent.atomic.AtomicBoolean completed
-
outputTerminated
private final java.util.concurrent.atomic.AtomicBoolean outputTerminated
-
inputTerminated
private final java.util.concurrent.atomic.AtomicBoolean inputTerminated
-
resultCallback
private final FutureCallback<T> resultCallback
-
-
Constructor Detail
-
BasicClientExchangeHandler
public BasicClientExchangeHandler(AsyncRequestProducer requestProducer, AsyncResponseConsumer<T> responseConsumer, FutureCallback<T> resultCallback)
-
-
Method Detail
-
produceRequest
public void produceRequest(RequestChannel requestChannel, HttpContext httpContext) throws HttpException, java.io.IOException
Description copied from interface:AsyncClientExchangeHandlerTriggered 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:
produceRequestin interfaceAsyncClientExchangeHandler- 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()
-
consumeInformation
public void consumeInformation(HttpResponse response, HttpContext httpContext) throws HttpException, java.io.IOException
Description copied from interface:AsyncClientExchangeHandlerTriggered to signal receipt of an intermediate (1xx) HTTP response.- Specified by:
consumeInformationin interfaceAsyncClientExchangeHandler- Parameters:
response- the intermediate (1xx) HTTP response.httpContext- the actual execution context.- Throws:
HttpException- in case of an HTTP protocol violation.java.io.IOException- in case of an I/O error.
-
consumeResponse
public void consumeResponse(HttpResponse response, EntityDetails entityDetails, HttpContext httpContext) throws HttpException, java.io.IOException
Description copied from interface:AsyncClientExchangeHandlerTriggered to signal receipt of a response message head.- Specified by:
consumeResponsein interfaceAsyncClientExchangeHandler- Parameters:
response- the response message head.entityDetails- the response entity details ornullif the response does not enclose an entity.httpContext- the actual execution context.- Throws:
HttpException- in case of an HTTP protocol violation.java.io.IOException- in case of an I/O error.
-
cancel
public void cancel()
Description copied from interface:AsyncClientExchangeHandlerTriggered to cancel the message exchange.- Specified by:
cancelin interfaceAsyncClientExchangeHandler
-
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- in case of an I/O error.
-
consume
public void consume(java.nio.ByteBuffer src) 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:
src- data source.- Throws:
java.io.IOException- in case of an I/O error.
-
streamEnd
public void streamEnd(java.util.List<? extends Header> trailers) throws HttpException, java.io.IOException
Description copied from interface:AsyncDataConsumerTriggered to signal termination of the data stream.- Specified by:
streamEndin interfaceAsyncDataConsumer- Parameters:
trailers- data stream trailers.- Throws:
HttpException- in case of an HTTP protocol violation.java.io.IOException- in case of an I/O error.
-
failed
public void failed(java.lang.Exception cause)
Description copied from interface:AsyncDataExchangeHandlerTriggered to signal a failure in data processing.- Specified by:
failedin interfaceAsyncDataExchangeHandler- Parameters:
cause- the cause of the failure.
-
completedInternal
private void completedInternal(T result)
-
failedInternal
private void failedInternal(java.lang.Exception ex)
-
cancelledInternal
private void cancelledInternal()
-
releaseResponseConsumer
private void releaseResponseConsumer()
-
releaseRequestProducer
private void releaseRequestProducer()
-
releaseResourcesInternal
private void releaseResourcesInternal()
-
releaseResources
public void releaseResources()
- Specified by:
releaseResourcesin interfaceResourceHolder
-
-