Julien Vermillard wrote:
<snip non-streaming parts>
Now streaming :
MutableHttpResponse response = new DefaultHttpResponse();
response.setStatus(HttpResponseStatus.OK);
// add a first chunk (optional)
response.addContent(buffer1);
PartialResponseListener listener = new PartialResponseListener() {
public void queueEmpty(HTTPResponse response) {
if(moreDataToSend) {
...
// add more data
response.addContent(buffer);
} else {
// streaming is done finish the response
response.done();
}
}
};
response.commitPartialResponse(response, listener);
Who will handle errors when sending a part of the response fails? The
current commitResponse()-API doesn't seem to expose errors very well either.
Also, what should queueEmpty() do if there is currently no more content
to be added to the queue, but more content will still be produced at a
later time? I guess this can be handled with a NullListener that does
nothing when the queue is emptied, and just adding content to the
response from the producer whenever new content becomes available.
What I would like to discuss here is to find a good looking API doing
everything you can imagine about streaming (audio,commet,big
files,etc..) before looking at impementation
I hope the questions above help other's thinking :)