jsr356-experts@websocket-spec.java.net

[jsr356-experts] Re: Last refactoring/naming proposal: RemoteEndpoint

From: Joakim Erdfelt <joakim_at_intalio.com>
Date: Wed, 20 Feb 2013 19:22:09 -0700

If you are going to go through with splitting up the interface into Async
<-> Basic.
Simplify it even more.
Get rid of the verbose method names.

Example (gentle cleanup version):

public interface NewGentleRemoteEndpoint {
    public interface Async extends NewRemoteEndpoint {
/** Timeout on async send, in milliseconds */
long getSendTimeout();

/** Send BINARY */
Future<SendResult> sendBinary(ByteBuffer data);

/** Send BINARY */
void sendBinary(ByteBuffer data, SendHandler completion);

/** Send with Encoder (TEXT or BINARY) */
Future<SendResult> sendObject(Object o);

/** Send with Encoder (TEXT or BINARY) */
void sendObject(Object o, SendHandler handler);

/** Send TEXT */
Future<SendResult> sendText(String text);

/** Send TEXT */
void sendText(String text, SendHandler completion);

/** Set Timeout in milliseconds */
void setSendTimeout(long timeoutmillis);
    }

    public interface Basic extends NewRemoteEndpoint {
/** Get BINARY Stream */
OutputStream getSendStream() throws IOException;

/** Get TEXT Stream */
Writer getSendWriter() throws IOException;

/** Send BINARY */
void sendBinary(ByteBuffer data) throws IOException;

/** Send Partial BINARY */
void sendBinary(ByteBuffer partialMessage, boolean isLast) throws
IOException;

/** Send with Encoder (TEXT or BINARY) */
void sendObject(Object o) throws IOException, EncodeException;

/** Send TEXT */
void sendText(String text) throws IOException;

/** Send Partial TEXT */
void sendText(String partialMessage, boolean isLast) throws IOException;

/** Send PING */
void sendPing(ByteBuffer applicationData) throws IOException,
IllegalArgumentException;
    }

    void flushBatch() throws IOException;

    boolean getBatchingAllowed();

    void setBatchingAllowed(boolean allowed) throws IOException;
}

Example (extreme version):

public interface NewExtremeRemoteEndpoint {
    public interface Async extends NewRemoteEndpoint {
/** Timeout on async send, in milliseconds */
long getSendTimeout();

/** Send BINARY */
Future<SendResult> send(ByteBuffer data);

/** Send BINARY */
void send(ByteBuffer data, SendHandler completion);

/** Send with Encoder (TEXT or BINARY) */
Future<SendResult> send(Object o);

/** Send with Encoder (TEXT or BINARY) */
void send(Object o, SendHandler handler);

/** Send TEXT */
Future<SendResult> send(String text);

/** Send TEXT */
void send(String text, SendHandler completion);

/** Set Timeout in milliseconds */
void setSendTimeout(long timeoutmillis);
    }

    public interface Basic extends NewRemoteEndpoint {
/** Get BINARY Stream */
OutputStream getSendStream() throws IOException;

/** Get TEXT Stream */
Writer getSendWriter() throws IOException;

/** Send BINARY */
void send(ByteBuffer data) throws IOException;

/** Send Partial BINARY */
void send(ByteBuffer partialMessage, boolean isLast) throws IOException;

/** Send with Encoder (TEXT or BINARY) */
void send(Object o) throws IOException, EncodeException;

/** Send TEXT */
void send(String text) throws IOException;

/** Send Partial TEXT */
void send(String partialMessage, boolean isLast) throws IOException;

/** Send PING */
void sendPing(ByteBuffer applicationData) throws IOException,
IllegalArgumentException;
    }

    void flushBatch() throws IOException;

    boolean getBatchingAllowed();

    void setBatchingAllowed(boolean allowed) throws IOException;
}


--
Joakim Erdfelt <joakim_at_intalio.com>
webtide.com <http://www.webtide.com/>
Developer advice, services and support
from the Jetty & CometD experts
eclipse.org/jetty - cometd.org
On Wed, Feb 20, 2013 at 6:03 PM, Danny Coward <danny.coward_at_oracle.com>wrote:
>  Hi folks,
>
> I've been sitting on this one for a while. Now that we are close to
> finishing v 1.0, its time to bring it out ! It's not really a big
> refactoring, but it could have some benefits in clarity and being able to
> extend RemoteEndpoint functionality in the future in a more organized way.
>
> I'm on the fence about it, and would appreciate some other opinions.
>
> The proposal is to divide up the functionality on the RemoteEndpoint
> interface into a RemoteEndpoint.Basic interface devoted to synchronous
> processing, and a RemoteEndpoint.Async devoted to async processing, and a
> common super interface RemoteEndpoint for functions common to both.
> Probably the container would use the same object to represent both: its
> really a cosmetic change.
>
> Instead of:-
>
> OLD:  Session: RemoteEndpoint getRemoteEndpoint(), we would have
>
> NEW: Session: T getRemoteEndpoint(T extends RemoteEndpoint);
> So, T could be RemoteEndpoint.Basic or RemoteEndpoint.Async.
>
>
> Here's a full listing of the NEW API under the proposal, and below that is
> the OLD (existing) API.
>
> public interface NewRemoteEndpoint {
>     void setBatchingAllowed(boolean allowed) throws IOException;
>     boolean getBatchingAllowed();
>     void flushBatch() throws IOException;
>
>     public interface Async extends NewRemoteEndpoint {
>         long getAsyncSendTimeout();
>         void setAsyncSendTimeout(long timeoutmillis);
>         void sendStringByCompletion(String text, SendHandler completion);
>         Future<SendResult> sendStringByFuture(String text);
>         Future<SendResult> sendBytesByFuture(ByteBuffer data);
>         void sendBytesByCompletion(ByteBuffer data, SendHandler
> completion);
>         Future<SendResult> sendObjectByFuture(Object o);
>         void sendObjectByCompletion(Object o, SendHandler handler);
>     }
>
>     public interface Basic extends NewRemoteEndpoint {
>         void sendString(String text) throws IOException;
>         void sendBytes(ByteBuffer data) throws IOException;
>         void sendObject(Object o) throws IOException, EncodeException;
>         void sendPartialString(String partialMessage, boolean isLast)
> throws IOException;
>         void sendPartialBytes(ByteBuffer partialByte, boolean isLast)
> throws IOException; // or Iterable<byte[]>
>         void sendPing(ByteBuffer applicationData) throws IOException,
> IllegalArgumentException;
>         OutputStream getSendStream() throws IOException;
>         Writer getSendWriter() throws IOException;
>     }
>
>
>
> public interface RemoteEndpoint {
>     void setBatchingAllowed(boolean allowed) throws IOException;
>     boolean getBatchingAllowed();
>     void flushBatch() throws IOException;
>     long getAsyncSendTimeout();
>     void setAsyncSendTimeout(long timeoutmillis);
>     void sendString(String text) throws IOException;
>     void sendBytes(ByteBuffer data) throws IOException;
>     void sendPartialString(String partialMessage, boolean isLast) throws
> IOException;
>     void sendPartialBytes(ByteBuffer partialByte, boolean isLast) throws
> IOException; // or Iterable<byte[]>
>     OutputStream getSendStream() throws IOException;
>     Writer getSendWriter() throws IOException;
>     void sendObject(Object o) throws IOException, EncodeException;
>     void sendStringByCompletion(String text, SendHandler completion);
>     Future<SendResult> sendStringByFuture(String text);
>     Future<SendResult> sendBytesByFuture(ByteBuffer data);
>     void sendBytesByCompletion(ByteBuffer data, SendHandler completion);
>     Future<SendResult> sendObjectByFuture(Object o);
>     void sendObjectByCompletion(Object o, SendHandler handler);
>     void sendPing(ByteBuffer applicationData) throws IOException,
> IllegalArgumentException;
>     void sendPong(ByteBuffer applicationData) throws IOException,
> IllegalArgumentException;
> }
>
> --
>   <http://www.oracle.com> * Danny Coward *
>  Java EE
> Oracle Corporation
>