[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-1943?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16583304#comment-16583304
 ] 

Ryan Schmitt commented on HTTPCLIENT-1943:
------------------------------------------

I think I've cracked this. Here's what I've got so far:

# The key is to start by implementing {{AsyncEntityProducer}} or 
{{AsyncDataProducer}} and capturing the {{DataStreamChannel}} instance on the 
client's first invocation of {{produce()}}.
# When a data producer has data, it should buffer it somewhere and then call 
{{channel.requestOutput()}} on the instance captured in step one.
# The {{available()}} method should return a number greater than zero when 
there is buffered data to be written, an exception to be thrown, or the stream 
is ready to be closed. Otherwise, it should return 0. The {{requestOutput()}} 
call in step two will cause the client to check for available data later. 
# On subsequent invocations, the {{produce()}} method should write buffered 
data (if available), close the stream (if the entire request has been written), 
or throw an exception (if the data producer fired one downstream). Careful 
attention must be paid to the return value of the {{DataStreamChannel#write}} 
method, since the client will only read what it can buffer internally.

Assuming this outline is correct, are there any finer points I should be aware 
of?

> Add support for truly asynchronous request streaming
> ----------------------------------------------------
>
>                 Key: HTTPCLIENT-1943
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1943
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>          Components: HttpClient (async)
>    Affects Versions: 5.0 Beta1
>            Reporter: Ryan Schmitt
>            Priority: Major
>
> I've been trying to figure out how to send asynchronous streaming requests in 
> a way that would be compatible with the reactive streams spec. In the 
> reactive streaming model, the producer pushes data to the consumer; the 
> consumer does not need to poll for it (although it does need to signal its 
> capacity for more data so that the producer does not overwhelm it). I haven't 
> been able to figure out how to do this.
> The closest I've come is by subclassing AbstractBinAsyncEntityProducer and 
> implementing the produceData method. The problem with this approach is that 
> the Apache client seems to poll this method constantly (essentially 
> busy-waiting) until either channel.endStream() is called or an exception is 
> thrown. In order for this to work, I need a way to either push data directly 
> to the StreamChannel or signal to the client that more data is available 
> without having it ask me.
> Another thing I noticed is that if I implement the available() method to 
> return 0, the client stops polling and doesn't start again; it basically 
> stalls the request. It's occurred to me that I might be able to capture the 
> DataStreamChannel (via AsyncEntityProducer#produce) and push data into it 
> from a producer. I'll keep investigating, but it's mostly guesswork at this 
> point, since much of the 5.0 client is not yet documented.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to