Package org.apache.http.nio.protocol
Class BasicAsyncResponseProducer
java.lang.Object
org.apache.http.nio.protocol.BasicAsyncResponseProducer
- All Implemented Interfaces:
Closeable
,AutoCloseable
,HttpAsyncResponseProducer
Basic implementation of
HttpAsyncResponseProducer
. The producer
can make use of the HttpAsyncContentProducer
interface to
efficiently stream out message content to the underlying non-blocking HTTP
connection, if it is implemented by the HttpEntity
inclosed in
the response.- Since:
- 4.2
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final HttpAsyncContentProducer
private final HttpResponse
-
Constructor Summary
ConstructorsModifierConstructorDescriptionBasicAsyncResponseProducer
(HttpResponse response) Creates a producer that can be used to transmit the given response message.protected
BasicAsyncResponseProducer
(HttpResponse response, HttpAsyncContentProducer producer) Creates a producer that can be used to transmit the given response message. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
Invoked to signal that the response processing terminated abnormally.Invoked to generate a HTTP response message head.void
produceContent
(ContentEncoder encoder, IOControl ioControl) Invoked to write out a chunk of content to theContentEncoder
.void
responseCompleted
(HttpContext context) Invoked to signal that the response has been fully written out.toString()
-
Field Details
-
response
-
producer
-
-
Constructor Details
-
BasicAsyncResponseProducer
Creates a producer that can be used to transmit the given response message. The given content producer will be used to stream out message content. Please note that the response message is expected to enclose anHttpEntity
whose properties are consistent with the behavior of the content producer.- Parameters:
response
- response message.producer
- response content producer.
-
BasicAsyncResponseProducer
Creates a producer that can be used to transmit the given response message. If the response message encloses anHttpEntity
it is also expected to implementHttpAsyncContentProducer
.- Parameters:
response
- response message.
-
-
Method Details
-
generateResponse
Description copied from interface:HttpAsyncResponseProducer
Invoked to generate a HTTP response message head.- Specified by:
generateResponse
in interfaceHttpAsyncResponseProducer
- Returns:
- HTTP response message.
-
produceContent
Description copied from interface:HttpAsyncResponseProducer
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 interfaceHttpAsyncResponseProducer
- Parameters:
encoder
- content encoder.ioControl
- I/O control of the underlying connection.- Throws:
IOException
- in case of an I/O error
-
responseCompleted
Description copied from interface:HttpAsyncResponseProducer
Invoked to signal that the response has been fully written out.- Specified by:
responseCompleted
in interfaceHttpAsyncResponseProducer
- Parameters:
context
- HTTP context
-
failed
Description copied from interface:HttpAsyncResponseProducer
Invoked to signal that the response processing terminated abnormally.- Specified by:
failed
in interfaceHttpAsyncResponseProducer
- Parameters:
ex
- exception
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
toString
-