Class PipeliningClientExchangeHandler<T>
- java.lang.Object
-
- org.apache.http.nio.protocol.PipeliningClientExchangeHandler<T>
-
- Type Parameters:
T
- the result type of request execution.
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,Cancellable
,HttpAsyncClientExchangeHandler
@Pipelined public class PipeliningClientExchangeHandler<T> extends java.lang.Object implements HttpAsyncClientExchangeHandler
Pipelining implementation ofHttpAsyncClientExchangeHandler
that executes a series of pipelined HTTP requests.- Since:
- 4.4
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicBoolean
closed
private NHttpClientConnection
conn
private ConnectionReuseStrategy
connReuseStrategy
private BasicFuture<java.util.List<T>>
future
private HttpProcessor
httpPocessor
private java.util.concurrent.atomic.AtomicBoolean
keepAlive
private HttpContext
localContext
private java.util.Queue<HttpAsyncRequestProducer>
requestProducerQueue
private java.util.concurrent.atomic.AtomicReference<HttpAsyncRequestProducer>
requestProducerRef
private java.util.Queue<HttpRequest>
requestQueue
private java.util.Queue<HttpAsyncResponseConsumer<T>>
responseConsumerQueue
private java.util.concurrent.atomic.AtomicReference<HttpAsyncResponseConsumer<T>>
responseConsumerRef
private java.util.Queue<T>
resultQueue
-
Constructor Summary
Constructors Constructor Description PipeliningClientExchangeHandler(java.util.List<? extends HttpAsyncRequestProducer> requestProducers, java.util.List<? extends HttpAsyncResponseConsumer<T>> responseConsumers, FutureCallback<java.util.List<T>> callback, HttpContext localContext, NHttpClientConnection conn, HttpProcessor httpPocessor, ConnectionReuseStrategy connReuseStrategy)
Creates new instance ofPipeliningClientExchangeHandler
.PipeliningClientExchangeHandler(java.util.List<? extends HttpAsyncRequestProducer> requestProducers, java.util.List<? extends HttpAsyncResponseConsumer<T>> responseConsumers, HttpContext localContext, NHttpClientConnection conn, HttpProcessor httpPocessor)
Creates new instance ofPipeliningClientExchangeHandler
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
cancel()
Cancels the ongoing operation or process.void
close()
private static void
closeQuietly(java.io.Closeable closeable)
void
consumeContent(ContentDecoder decoder, IOControl ioControl)
Invoked to process a chunk of content from theContentDecoder
.void
failed(java.lang.Exception ex)
Invoked to signal that the response processing terminated abnormally.HttpRequest
generateRequest()
Invoked to generate a HTTP request message head.java.util.concurrent.Future<java.util.List<T>>
getFuture()
void
inputTerminated()
Invoked to signal that the connection has been terminated prematurely by the opposite end.boolean
isDone()
Determines whether or not the response processing completed.void
produceContent(ContentEncoder encoder, IOControl ioControl)
Invoked to write out a chunk of content to theContentEncoder
.private void
releaseResources()
void
requestCompleted()
Invoked to signal that the request has been fully written out.void
responseCompleted()
Invoked to signal that the response has been fully processed.void
responseReceived(HttpResponse response)
Invoked when a HTTP response message is received.
-
-
-
Field Detail
-
requestProducerQueue
private final java.util.Queue<HttpAsyncRequestProducer> requestProducerQueue
-
responseConsumerQueue
private final java.util.Queue<HttpAsyncResponseConsumer<T>> responseConsumerQueue
-
requestQueue
private final java.util.Queue<HttpRequest> requestQueue
-
resultQueue
private final java.util.Queue<T> resultQueue
-
future
private final BasicFuture<java.util.List<T>> future
-
localContext
private final HttpContext localContext
-
conn
private final NHttpClientConnection conn
-
httpPocessor
private final HttpProcessor httpPocessor
-
connReuseStrategy
private final ConnectionReuseStrategy connReuseStrategy
-
requestProducerRef
private final java.util.concurrent.atomic.AtomicReference<HttpAsyncRequestProducer> requestProducerRef
-
responseConsumerRef
private final java.util.concurrent.atomic.AtomicReference<HttpAsyncResponseConsumer<T>> responseConsumerRef
-
keepAlive
private final java.util.concurrent.atomic.AtomicBoolean keepAlive
-
closed
private final java.util.concurrent.atomic.AtomicBoolean closed
-
-
Constructor Detail
-
PipeliningClientExchangeHandler
public PipeliningClientExchangeHandler(java.util.List<? extends HttpAsyncRequestProducer> requestProducers, java.util.List<? extends HttpAsyncResponseConsumer<T>> responseConsumers, FutureCallback<java.util.List<T>> callback, HttpContext localContext, NHttpClientConnection conn, HttpProcessor httpPocessor, ConnectionReuseStrategy connReuseStrategy)
Creates new instance ofPipeliningClientExchangeHandler
.- Parameters:
requestProducers
- the request producers.responseConsumers
- the response consumers.callback
- the future callback invoked when the operation is completed.localContext
- the local execution context.conn
- the actual connection.httpPocessor
- the HTTP protocol processor.connReuseStrategy
- the connection re-use strategy.
-
PipeliningClientExchangeHandler
public PipeliningClientExchangeHandler(java.util.List<? extends HttpAsyncRequestProducer> requestProducers, java.util.List<? extends HttpAsyncResponseConsumer<T>> responseConsumers, HttpContext localContext, NHttpClientConnection conn, HttpProcessor httpPocessor)
Creates new instance ofPipeliningClientExchangeHandler
.- Parameters:
requestProducers
- the request producers.responseConsumers
- the response consumers.localContext
- the local execution context.conn
- the actual connection.httpPocessor
- the HTTP protocol processor.
-
-
Method Detail
-
getFuture
public java.util.concurrent.Future<java.util.List<T>> getFuture()
-
closeQuietly
private static void closeQuietly(java.io.Closeable closeable)
-
releaseResources
private void releaseResources()
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
generateRequest
public HttpRequest generateRequest() throws java.io.IOException, HttpException
Description copied from interface:HttpAsyncClientExchangeHandler
Invoked to generate a HTTP request message head. The message is expected to implement theHttpEntityEnclosingRequest
interface if it is to enclose a content entity. TheHttpAsyncClientExchangeHandler.produceContent(ContentEncoder, IOControl)
method will not be invoked ifHttpEntityEnclosingRequest.getEntity()
returnsnull
.- Specified by:
generateRequest
in interfaceHttpAsyncClientExchangeHandler
- Returns:
- HTTP request message.
- Throws:
java.io.IOException
- in case of an I/O errorHttpException
- in case of HTTP protocol violation
-
produceContent
public void produceContent(ContentEncoder encoder, IOControl ioControl) throws java.io.IOException
Description copied from interface:HttpAsyncClientExchangeHandler
Invoked to write out a chunk of content to theContentEncoder
. TheIOControl
interface can be used to suspend output event notifications if the producer is temporarily unable to produce more content.When all content is finished, the producer MUST call
ContentEncoder.complete()
. Failure to do so may cause the entity to be incorrectly delimited.Please note that the
ContentEncoder
object is not thread-safe and should only be used within the context of this method call. TheIOControl
object can be shared and used on other thread to resume output event notifications when more content is made available.- Specified by:
produceContent
in interfaceHttpAsyncClientExchangeHandler
- Parameters:
encoder
- content encoder.ioControl
- I/O control of the underlying connection.- Throws:
java.io.IOException
- in case of an I/O error
-
requestCompleted
public void requestCompleted()
Description copied from interface:HttpAsyncClientExchangeHandler
Invoked to signal that the request has been fully written out.- Specified by:
requestCompleted
in interfaceHttpAsyncClientExchangeHandler
-
responseReceived
public void responseReceived(HttpResponse response) throws java.io.IOException, HttpException
Description copied from interface:HttpAsyncClientExchangeHandler
Invoked when a HTTP response message is received. Please note that theHttpAsyncClientExchangeHandler.consumeContent(ContentDecoder, IOControl)
method will be invoked only if the response messages has a content entity enclosed.- Specified by:
responseReceived
in interfaceHttpAsyncClientExchangeHandler
- Parameters:
response
- HTTP response message.- Throws:
java.io.IOException
- in case of an I/O errorHttpException
- in case of HTTP protocol violation
-
consumeContent
public void consumeContent(ContentDecoder decoder, IOControl ioControl) throws java.io.IOException
Description copied from interface:HttpAsyncClientExchangeHandler
Invoked to process a chunk of content from theContentDecoder
. TheIOControl
interface can be used to suspend input event notifications if the consumer is temporarily unable to process content.The consumer can use the
ContentDecoder.isCompleted()
method to find out whether or not the message content has been fully consumed.Please note that the
ContentDecoder
object is not thread-safe and should only be used within the context of this method call. TheIOControl
object can be shared and used on other thread to resume input event notifications when the consumer is capable of processing more content.- Specified by:
consumeContent
in interfaceHttpAsyncClientExchangeHandler
- Parameters:
decoder
- content decoder.ioControl
- I/O control of the underlying connection.- Throws:
java.io.IOException
- in case of an I/O error
-
responseCompleted
public void responseCompleted() throws java.io.IOException
Description copied from interface:HttpAsyncClientExchangeHandler
Invoked to signal that the response has been fully processed.- Specified by:
responseCompleted
in interfaceHttpAsyncClientExchangeHandler
- Throws:
java.io.IOException
-
inputTerminated
public void inputTerminated()
Description copied from interface:HttpAsyncClientExchangeHandler
Invoked to signal that the connection has been terminated prematurely by the opposite end.- Specified by:
inputTerminated
in interfaceHttpAsyncClientExchangeHandler
-
failed
public void failed(java.lang.Exception ex)
Description copied from interface:HttpAsyncClientExchangeHandler
Invoked to signal that the response processing terminated abnormally.- Specified by:
failed
in interfaceHttpAsyncClientExchangeHandler
- Parameters:
ex
- exception
-
cancel
public boolean cancel()
Description copied from interface:Cancellable
Cancels the ongoing operation or process.- Specified by:
cancel
in interfaceCancellable
- Returns:
true
if the operation or process has been cancelled as a result of this method call orfalse
if it has already been cancelled or not started.
-
isDone
public boolean isDone()
Description copied from interface:HttpAsyncClientExchangeHandler
Determines whether or not the response processing completed.- Specified by:
isDone
in interfaceHttpAsyncClientExchangeHandler
-
-