users@websocket-spec.java.net

[jsr356-users] [jsr356-experts] Clarification required on sending messages concurrently

From: Mark Thomas <mark_at_homeinbox.net>
Date: Mon, 12 Jan 2015 10:21:08 +0000

Looking back though the EG discussions, we discussed concurrency and
agreed that one message had to complete before the next was sent [1]. No
distinction was made between synchronous and asynchronous messages.

The discussion in [1] happened before the split between
RemoteEndpoint.[Basic|Async] and after the split restriction described
in [1] only appears in the Javadoc for RemoteEndpoint.Basic.

My question is this:

Does the restriction agreed in [1] apply to async messages or not?

I believe that the restriction does apply. Without it, there is no
mechanism for the container to signal to the application to stop sending
messages if the client isn't reading them fast enough.

By way of example, consider the following:
@OnMessage
public String onMessage(String message, Session session) {
    received.add(message);
    session.getAsyncRemote().sendText(MESSAGE_ONE);
    return message;
}


My expectation is that, unless the async message completes very quickly
(unlikely) then an ISE will be thrown because the async message is still
in progress when the sync message send is triggered by the return value.

That said, if batching is enabled then it is much more likely that the
async message would complete instantly and that the sync message would
then be sent.

For bonus points, assuming that the batch buffer is big enough for both
the async and sync message, is the use of the return value to send the
message a trigger to flush the batch? I can seen no reason why this
should be the case but the question popped up on a Tomcat list so I
wanted to check here.

Mark


[1]
https://java.net/projects/websocket-spec/lists/jsr356-experts/archive/2013-02/message/48