WebSocket client API

Peter Levart peter.levart at gmail.com
Wed Oct 21 10:29:44 UTC 2015



On 10/20/2015 12:49 PM, Simone Bordet wrote:
> if (cs != null) {
>      cs.thenAccept(cb -> {
>          if (cb != null) {
>              .... return*message*  to buffer pool ...
>          }
>      });
> }
>
> At that point, the return value of onText() could well be a CF<?> like
> it already is, no ?
> The implementation would just need to test for null, but then never
> actually use the returned object wrapped by the CF.
>
> What do you think ?

There is one advantage to having CompletionStage<CharBuffer> return 
value instead of CompletionStage<?> or CompletionStage<Boolean>. In 
above example, the lambda has to capture the *message* and retain it 
until the call-back happens at which point it may be that *message* has 
to be ignored (not recycled). In such case the *message* may have been 
retained by lambda for more time than necessary. If 
CompletionStage<CharBuffer> is used instead, the buffer or null is 
passed to lambda so buffer's retention time is always optimal.

Regards, Peter

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/net-dev/attachments/20151021/9515c3d2/attachment.html>


More information about the net-dev mailing list