Package org.apache.http.nio.protocol
Class BasicAsyncRequestProducer
java.lang.Object
org.apache.http.nio.protocol.BasicAsyncRequestProducer
- All Implemented Interfaces:
Closeable
,AutoCloseable
,HttpAsyncRequestProducer
Basic implementation of
HttpAsyncRequestProducer
. 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 enclosed HttpEntity
.- Since:
- 4.2
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionBasicAsyncRequestProducer
(HttpHost target, HttpRequest request) Creates a producer that can be used to transmit the given request message. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
Invoked to signal that the response processing terminated abnormally.Invoked to generate a HTTP request message head.Invoked to obtain the request target host.boolean
Determines whether or not this producer is capable of producing HTTP request messages more than once.void
produceContent
(ContentEncoder encoder, IOControl ioctrl) Invoked to write out a chunk of content to theContentEncoder
.void
requestCompleted
(HttpContext context) Invoked to signal that the request has been fully written out.void
Invoked to reset the producer to its initial state.toString()
-
Constructor Details
-
BasicAsyncRequestProducer
Creates a producer that can be used to transmit the given request message. If the request message encloses anHttpEntity
it is also expected to implementHttpAsyncContentProducer
.- Parameters:
target
- target host.request
- request message.
-
-
Method Details
-
generateRequest
Description copied from interface:HttpAsyncRequestProducer
Invoked to generate a HTTP request message head. The message is expected to implement theHttpEntityEnclosingRequest
interface if it is to enclose a content entity. TheHttpAsyncRequestProducer.produceContent(ContentEncoder, IOControl)
method will not be invoked ifHttpEntityEnclosingRequest.getEntity()
returnsnull
.- Specified by:
generateRequest
in interfaceHttpAsyncRequestProducer
- Returns:
- HTTP request message.
-
getTarget
Description copied from interface:HttpAsyncRequestProducer
Invoked to obtain the request target host.- Specified by:
getTarget
in interfaceHttpAsyncRequestProducer
-
produceContent
Description copied from interface:HttpAsyncRequestProducer
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 interfaceHttpAsyncRequestProducer
- Parameters:
encoder
- content encoder.ioctrl
- I/O control of the underlying connection.- Throws:
IOException
- in case of an I/O error
-
requestCompleted
Description copied from interface:HttpAsyncRequestProducer
Invoked to signal that the request has been fully written out.- Specified by:
requestCompleted
in interfaceHttpAsyncRequestProducer
- Parameters:
context
- HTTP context
-
failed
Description copied from interface:HttpAsyncRequestProducer
Invoked to signal that the response processing terminated abnormally.- Specified by:
failed
in interfaceHttpAsyncRequestProducer
- Parameters:
ex
- exception
-
isRepeatable
public boolean isRepeatable()Description copied from interface:HttpAsyncRequestProducer
Determines whether or not this producer is capable of producing HTTP request messages more than once.- Specified by:
isRepeatable
in interfaceHttpAsyncRequestProducer
-
resetRequest
Description copied from interface:HttpAsyncRequestProducer
Invoked to reset the producer to its initial state. Repeatable request producers are expected to release currently allocated resources that are no longer needed or re-acquire resources needed to repeat the process.- Specified by:
resetRequest
in interfaceHttpAsyncRequestProducer
- Throws:
IOException
- in case of an I/O error
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
toString
-