Package org.apache.http.nio.protocol
Class BasicAsyncRequestProducer
- java.lang.Object
-
- org.apache.http.nio.protocol.BasicAsyncRequestProducer
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,HttpAsyncRequestProducer
public class BasicAsyncRequestProducer extends java.lang.Object implements HttpAsyncRequestProducer
Basic implementation ofHttpAsyncRequestProducer. The producer can make use of theHttpAsyncContentProducerinterface to efficiently stream out message content to the underlying non-blocking HTTP connection, if it is implemented by the enclosedHttpEntity.- Since:
- 4.2
- See Also:
HttpAsyncContentProducer
-
-
Constructor Summary
Constructors Constructor Description BasicAsyncRequestProducer(HttpHost target, HttpRequest request)Creates a producer that can be used to transmit the given request message.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidfailed(java.lang.Exception ex)Invoked to signal that the response processing terminated abnormally.HttpRequestgenerateRequest()Invoked to generate a HTTP request message head.HttpHostgetTarget()Invoked to obtain the request target host.booleanisRepeatable()Determines whether or not this producer is capable of producing HTTP request messages more than once.voidproduceContent(ContentEncoder encoder, IOControl ioctrl)Invoked to write out a chunk of content to theContentEncoder.voidrequestCompleted(HttpContext context)Invoked to signal that the request has been fully written out.voidresetRequest()Invoked to reset the producer to its initial state.java.lang.StringtoString()
-
-
-
Constructor Detail
-
BasicAsyncRequestProducer
public BasicAsyncRequestProducer(HttpHost target, HttpRequest request)
Creates a producer that can be used to transmit the given request message. If the request message encloses anHttpEntityit is also expected to implementHttpAsyncContentProducer.- Parameters:
target- target host.request- request message.
-
-
Method Detail
-
generateRequest
public HttpRequest generateRequest()
Description copied from interface:HttpAsyncRequestProducerInvoked to generate a HTTP request message head. The message is expected to implement theHttpEntityEnclosingRequestinterface if it is to enclose a content entity. TheHttpAsyncRequestProducer.produceContent( ContentEncoder, IOControl)method will not be invoked ifHttpEntityEnclosingRequest.getEntity()returnsnull.- Specified by:
generateRequestin interfaceHttpAsyncRequestProducer- Returns:
- HTTP request message.
-
getTarget
public HttpHost getTarget()
Description copied from interface:HttpAsyncRequestProducerInvoked to obtain the request target host.- Specified by:
getTargetin interfaceHttpAsyncRequestProducer
-
produceContent
public void produceContent(ContentEncoder encoder, IOControl ioctrl) throws java.io.IOException
Description copied from interface:HttpAsyncRequestProducerInvoked to write out a chunk of content to theContentEncoder. TheIOControlinterface 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
ContentEncoderobject is not thread-safe and should only be used within the context of this method call. TheIOControlobject can be shared and used on other thread to resume output event notifications when more content is made available.- Specified by:
produceContentin interfaceHttpAsyncRequestProducer- Parameters:
encoder- content encoder.ioctrl- I/O control of the underlying connection.- Throws:
java.io.IOException- in case of an I/O error
-
requestCompleted
public void requestCompleted(HttpContext context)
Description copied from interface:HttpAsyncRequestProducerInvoked to signal that the request has been fully written out.- Specified by:
requestCompletedin interfaceHttpAsyncRequestProducer- Parameters:
context- HTTP context
-
failed
public void failed(java.lang.Exception ex)
Description copied from interface:HttpAsyncRequestProducerInvoked to signal that the response processing terminated abnormally.- Specified by:
failedin interfaceHttpAsyncRequestProducer- Parameters:
ex- exception
-
isRepeatable
public boolean isRepeatable()
Description copied from interface:HttpAsyncRequestProducerDetermines whether or not this producer is capable of producing HTTP request messages more than once.- Specified by:
isRepeatablein interfaceHttpAsyncRequestProducer
-
resetRequest
public void resetRequest() throws java.io.IOExceptionDescription copied from interface:HttpAsyncRequestProducerInvoked 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:
resetRequestin interfaceHttpAsyncRequestProducer- Throws:
java.io.IOException- in case of an I/O error
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-