Package org.apache.http.nio.protocol
Class BasicAsyncResponseProducer
- java.lang.Object
-
- org.apache.http.nio.protocol.BasicAsyncResponseProducer
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,HttpAsyncResponseProducer
public class BasicAsyncResponseProducer extends java.lang.Object implements HttpAsyncResponseProducer
Basic implementation ofHttpAsyncResponseProducer
. The producer can make use of theHttpAsyncContentProducer
interface to efficiently stream out message content to the underlying non-blocking HTTP connection, if it is implemented by theHttpEntity
inclosed in the response.- Since:
- 4.2
- See Also:
HttpAsyncContentProducer
-
-
Constructor Summary
Constructors Constructor Description BasicAsyncResponseProducer(HttpResponse response)
Creates a producer that can be used to transmit the given response message.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
failed(java.lang.Exception ex)
Invoked to signal that the response processing terminated abnormally.HttpResponse
generateResponse()
Invoked to generate a HTTP response message head.void
produceContent(ContentEncoder encoder, IOControl ioctrl)
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.java.lang.String
toString()
-
-
-
Constructor Detail
-
BasicAsyncResponseProducer
public BasicAsyncResponseProducer(HttpResponse response)
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 Detail
-
generateResponse
public HttpResponse generateResponse()
Description copied from interface:HttpAsyncResponseProducer
Invoked to generate a HTTP response message head.- Specified by:
generateResponse
in interfaceHttpAsyncResponseProducer
- Returns:
- HTTP response message.
-
produceContent
public void produceContent(ContentEncoder encoder, IOControl ioctrl) throws java.io.IOException
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.ioctrl
- I/O control of the underlying connection.- Throws:
java.io.IOException
- in case of an I/O error
-
responseCompleted
public void responseCompleted(HttpContext context)
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
public void failed(java.lang.Exception ex)
Description copied from interface:HttpAsyncResponseProducer
Invoked to signal that the response processing terminated abnormally.- Specified by:
failed
in interfaceHttpAsyncResponseProducer
- Parameters:
ex
- exception
-
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
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-