users@websocket-spec.java.net

[jsr356-users] [jsr356-experts] Re: Next set of issues (message object lifetimes)

From: Scott Ferguson <ferg_at_caucho.com>
Date: Thu, 31 Jan 2013 18:11:46 -0800

On 1/31/13 5:13 PM, Danny Coward wrote:
> Hi folks,
>
>
>
> * Validity of message objects
> (http://java.net/jira/browse/WEBSOCKET_SPEC-122)
>
> Mark and I have exchanged comments over on the JIRA issue for this:
> for the message objects that can be passed into the various
> MessageHandlers, should they remain valid after the completion of the
> onMessage call ? for example if the implementation passes in a
> ByteBuffer to represent a binary message, can the developer be sure
> that it won't be recycled after the onMessage call has completed.
>
> I'd say it would be easier for developers if they could uses these
> message objects outside the scope of the onMessage call, any other
> opinions ?
>

It's pretty important that these objects be owned by the container and
lose scope after the message handler.

The need is most clear in the case of InputStream and Reader (because
their data is no longer live outside the call). But also ByteBuffer,
since that's designed to avoid buffer copies. The underlying data for
the ByteBuffer could conceivably be non-heap memory.

-- Scott