WebSocket client API

Simone Bordet simone.bordet at gmail.com
Fri Oct 9 20:12:50 UTC 2015


Hi,

On Fri, Oct 9, 2015 at 5:07 PM, Paul Sandoz <paul.sandoz at oracle.com> wrote:
> Regarding resource management. This one is tricky. For HTTP Michael had a clever trick of piggy backing off the back pressure support, but i think that might be too clever as it is conflating two independent actions. I have a hunch that to do this effectively we may need some sort of resource supplier that is registered with the builder. That supplier defines the resource management strategy and requirements on a listener consuming resources (that is somewhat annoying because it couples the resource supplier with the listener).
>

I have already proposed this:

interface WebSocket
  void sendText(ByteBuffer text, boolean last, Consumer<Throwable> handler);
  void sendBinary(ByteBuffer binary, boolean last, Consumer<Throwable> handler);
  void sendPing(ByteBuffer payload, Consumer<Throwable> handler);
  void sendPong(ByteBuffer payload, Consumer<Throwable> handler);
  void close(int code, ByteBuffer reason, Consumer<Throwable> handler);
  String getSubProtocol();
  void request(long);
  void abort();
  CloseState getCloseState();

  class Builder
    Builder listener(Listener l);
    Builder subProtocols(String... p);
    CompletableFuture<WebSocket> build();
  end

  interface Listener
    default void onOpen(WebSocket ws) { ws.request(1); }
    default void onClose(WebSocket ws, int code, ByteBuffer reason) { }
    default void onPing(WebSocket ws, ByteBuffer payload) { ws.request(1); }
    default void onPong(WebSocket ws, ByteBuffer payload) { ws.request(1); }
    default void onText(WebSocket ws, ByteBuffer text, boolean isLast,
Consumer<Throwable> handler) { handler.accept(null); ws.request(1); }
    default void onBinary(WebSocket ws, ByteBuffer binary, boolean
isLast, Consumer<Throwable> handler) { handler.accept(null);
ws.request(1); }
    default void onError(WebSocket ws, Throwable failure) { }
  end

  enum CloseState { OPEN, REMOTE, LOCAL, CLOSED, ABORTED }

end

I hope it gets a second consideration.

-- 
Simone Bordet
http://bordet.blogspot.com
---
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


More information about the net-dev mailing list