Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


At the end of this phase, the connection is ready to function and forward web socket messages (as byte buffers) back and forth.

Phase 2: Flows

Inbound flow

This flow is for messages coming from the user-agent, targeting the protected application.

The WS adapter implements the Servlet ReadListener interface that is notified whenever some bytes are ready to be read from the stream. It then collect them into a Grizzly Buffer and directly write them into the Connection (sending to the protected application).

Outbound flow

This flow is for messages coming from the protected application, targeting the user-agent.

The WS adapter implements the Servlet WriteListener interface that receive notification when the stream is ready to be written. At this point, if the internal adapter's buffer is not empty, we forward its content into the servlet's stream.

When a message comes from the protected application, it ends up in the adapter, if the stream is ready for write, we directly push the buffer content into it. If not, we append the buffer value to the adapter's buffer (will be pushed when stream is ready notification will be received).

Obviously there is a lock between theses 2 methods because a thread from Tomcat and a thread from Grizzly can try to write the adapter's buffer content at the same time.

Schema (use arrows to navigate)