T
- The result type.public final class BasicClientExchangeHandler<T> extends Object implements AsyncClientExchangeHandler
AsyncClientExchangeHandler
implementation that makes use
of AsyncRequestProducer
to generate request message
and AsyncResponseConsumer
to process the response message returned by the server.Constructor and Description |
---|
BasicClientExchangeHandler(AsyncRequestProducer requestProducer,
AsyncResponseConsumer<T> responseConsumer,
FutureCallback<T> resultCallback) |
Modifier and Type | Method and Description |
---|---|
int |
available()
Returns the number of bytes immediately available for output.
|
void |
cancel()
Triggered to cancel the message exchange.
|
void |
consume(ByteBuffer src)
Triggered to pass incoming data to the data consumer.
|
void |
consumeInformation(HttpResponse response,
HttpContext httpContext)
Triggered to signal receipt of an intermediate (1xx) HTTP response.
|
void |
consumeResponse(HttpResponse response,
EntityDetails entityDetails,
HttpContext httpContext)
Triggered to signal receipt of a response message head.
|
void |
failed(Exception cause)
Triggered to signal a failure in data processing.
|
void |
produce(DataStreamChannel channel)
Triggered to signal the ability of the underlying data channel
to accept more data.
|
void |
produceRequest(RequestChannel requestChannel,
HttpContext httpContext)
Triggered to signal the ability of the underlying request channel
to accept a request messages.
|
void |
releaseResources() |
void |
streamEnd(List<? extends Header> trailers)
Triggered to signal termination of the data stream.
|
void |
updateCapacity(CapacityChannel capacityChannel)
Triggered to signal ability of the underlying data stream to receive
data capacity update.
|
public BasicClientExchangeHandler(AsyncRequestProducer requestProducer, AsyncResponseConsumer<T> responseConsumer, FutureCallback<T> resultCallback)
public void produceRequest(RequestChannel requestChannel, HttpContext httpContext) throws HttpException, IOException
AsyncClientExchangeHandler
produceRequest
in interface AsyncClientExchangeHandler
requestChannel
- the request channel capable to accepting a request message.httpContext
- the actual execution context.HttpException
- in case of an HTTP protocol violation.IOException
- in case of an I/O error.public int available()
AsyncDataProducer
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
with DataStreamChannel.requestOutput()
.
available
in interface AsyncDataProducer
AsyncDataProducer.produce(DataStreamChannel)
,
DataStreamChannel.requestOutput()
public void produce(DataStreamChannel channel) throws IOException
AsyncDataProducer
Please note this method gets triggered only if AsyncDataProducer.available()
returns a positive value.
produce
in interface AsyncDataProducer
channel
- the data channel capable of accepting more data.IOException
- in case of an I/O error.AsyncDataProducer.available()
public void consumeInformation(HttpResponse response, HttpContext httpContext) throws HttpException, IOException
AsyncClientExchangeHandler
consumeInformation
in interface AsyncClientExchangeHandler
response
- the intermediate (1xx) HTTP response.httpContext
- the actual execution context.HttpException
- in case of an HTTP protocol violation.IOException
- in case of an I/O error.public void consumeResponse(HttpResponse response, EntityDetails entityDetails, HttpContext httpContext) throws HttpException, IOException
AsyncClientExchangeHandler
consumeResponse
in interface AsyncClientExchangeHandler
response
- the response message head.entityDetails
- the response entity details or null
if the response
does not enclose an entity.httpContext
- the actual execution context.HttpException
- in case of an HTTP protocol violation.IOException
- in case of an I/O error.public void cancel()
AsyncClientExchangeHandler
cancel
in interface AsyncClientExchangeHandler
public void updateCapacity(CapacityChannel capacityChannel) throws IOException
AsyncDataConsumer
updateCapacity
in interface AsyncDataConsumer
capacityChannel
- the channel for capacity updates.IOException
- in case of an I/O error.public void consume(ByteBuffer src) throws IOException
AsyncDataConsumer
consume
in interface AsyncDataConsumer
src
- data source.IOException
- in case of an I/O error.public void streamEnd(List<? extends Header> trailers) throws HttpException, IOException
AsyncDataConsumer
streamEnd
in interface AsyncDataConsumer
trailers
- data stream trailers.HttpException
- in case of an HTTP protocol violation.IOException
- in case of an I/O error.public void failed(Exception cause)
AsyncDataExchangeHandler
failed
in interface AsyncDataExchangeHandler
cause
- the cause of the failure.public void releaseResources()
releaseResources
in interface ResourceHolder
Copyright © 2005–2021 The Apache Software Foundation. All rights reserved.