Thanks Simone,

I think this is a good example of how this low-level API can be
leveraged to build adapters, InputStream in this case. Equally,
that could be a RS Subscriber, or some other non-blocking
async JSON parser, or something else.

Let’s not get caught up in what the JDK should provide
out-of-the-box and what is likely to be provided by the community.
However, what we must be right, in this release, is the lowest level
foundational API, other things can come later or be provided by
others in the community.

-Chris.

> On 20 Feb 2018, at 18:31, Simone Bordet <simone.bor...@gmail.com> wrote:
> 
> Hi,
> 
> On Tue, Feb 20, 2018 at 4:32 PM, Chuck Davis <cjgun...@gmail.com> wrote:
>> Simone, please, please tell me how this is done.
> 
> The WebSocket.Listener APIs return a CompletableFuture, indicating
> when the application is done with the processing of the parameters
> passed to the listener method (in particular the ByteBuffer).
> We can leverage this to avoid to copy the bytes in the ByteBuffer - we
> will just store the ByteBuffers in the ByteBufferInputStream for later
> use, and we return a CompletableFuture that we will complete when we
> have consumed the ByteBuffer bytes.
> 
> When the listener tells you that you have the LAST (or WHOLE) part,
> then you can wrap the ByteBufferInputStream with your
> ObjectInputStream.
> 
> The code is attached and shows the bare minimum implementation of
> ByteBufferInputStream - just implementing `int read()`.
> Implementing `int read(byte[], int, int)` is left as exercise :)
> 
> Just to be paranoid, the attached code license is public domain as
> explained in https://creativecommons.org/publicdomain/zero/1.0/.
> 
> Just to be clear, the only copy that happens is when you have to
> bridge from the byte[] format used by InputStream to the ByteBuffer
> format.
> The same copy happens when you use ByteArrayInputStream (that you used
> in the "good" code in your first email of this thread), so this
> version is on par with your "good" code.
> 
> This version has the advantage that guarantees that no other copy is
> done, not even by the implementation (hopefully, right Pavel ?), while
> with JDK 8 there may have been hidden copies to provide a full
> ByteBuffer.
> 
> -- 
> Simone Bordet
> ---
> Finally, no matter how good the architecture and design are,
> to deliver bug-free software with optimal performance and reliability,
> the implementation technique must be flawless.   Victoria Livschitz
> <WebSocketTest.java>

Reply via email to