-
Type:
JEP Task
-
Resolution: Delivered
-
Priority:
P5
-
Component/s: core-libs
WebSocket API tasks
- Provide more examples in the API
- <s>Remove
Textinterface andsendText(ByteBuffer): JDK-8156650</s> - <s>Specify it's up to implementation how to treat incomplete (UTF-16 representation)
CharSequences: JDK-8156650</s> - <s>Remove word immediately everywhere from methods that return
CompletableFuture: JDK-8156693</s> - <s>
CompletableFuture<WebSocket>instead ofCompletableFuture<Void>: JDK-8156693</s> - <s>All exceptions other than
NPEandIAEshould be relayed throughCompletableFuturerather than thrown on the spot: JDK-8156693</s> - <s>Provide better design for
onPong(take care of as much as possible in the implementation rather than delegate to theListener): JDK-8159053</s> - <s>Provide better design for
onClose(e.g. returnCFto indicate when close can be sent): JDK-8159053</s> - <s>
Builder.connectTimeout(Duration)instead ofBuilder.connectTimeout(long, TimeUnit): JDK-8156742</s> - <s>
void request(long)instead oflong request(long): JDK-8156742</s> - <s>Remove
sendBinary(byte[], boolean): JDK-8156742</s> - <s>Remove
sendText(Stream<CharSequence>): JDK-8156742</s> - <s>Specify it's up to an implementation to serialize Ping, Pong and Close messages with Text and Binary ones however it wants. Given the relative order of messages of the same type (control/non-control) is preserved.</s> One outstanding write. Period.
- <s>Remove
CloseCodeand use simple(int, String): JDK-8159053</s> - <s>Return an empty
Stringfor no subprotocol rather thannull</s> - <s>if
onClose(1006)is signalled instead ofonError(), then
onOpen (onText|onBinary|onPing|onPong)* (onClose|onError)?
could be more strict
onOpen (onText|onBinary|onPing|onPong)* onClose|onError</s>
WebSocket implementation tasks
- <s>Better check subprotocol syntax. Check for separators like
"(" | ")" | "<" | ">" | "@", </s>
-
Think of repeated reading from the channel until the buffer is full or a message is received -- which comes first (optimization).
-
Default implementation of
Listener.onErrormust log the error or do something likedefault void onError(WebSocket webSocket, Throwable error) { Thread.currentThread().getUncaughtExceptionHandler() .uncaughtException(Thread.currentThread(), error); }
Or make it abstract.
- Get rid of
ByteBufferpooling on the receiving side for binary messages as an error-prone activity for user.ByteBuffers can be stored by the user and reused. Bottom line. Slicing? Yes. Pooling? No! At the same time it's absolutely fine to poolCharBuffer, since they are exposed asCharSequence. AndCharSequenceis implementable, thus we can control access to an already disposed sequences. - <s>Own package for the implementation instead of
WStype prefix.</s> - Consider changing one-off registration with key cancellation for modifying
interestOps(see Java™ NIO, 4.5 Selection Scaling); maybe we should put scalability one level higher, i.e. each channel reading/writing task is submitted to an executor? Is key cancellation followed by registration is expensive compared modifyinginterestOpsfor the duration of the task? - Provide better exception messages, more descriptive and capturing state.
- <s>Unbounded queue for outgoing messages: JDK-8157273</s> Decided not to do this.
- <s>Delegate forbidden (used by RFC 6455) headers checking to
HttpClient's internals (mainly because of the case-sensitivity rules)</s> It's fine the way it is now. - <s>Consider pros and cons of attempting to send from the same thread followed by asynchronous sent of leftovers. Investigate possible problems with stack bloating.</s>
- Consider
ByteBufferpooling on the sending side. - Provide security checks for
sendXXX. - Move UTF-16 to UTF-8 encoding operations to a point before message acceptance. So these errors become non-fatal: JDK-8156693
Test
- Group all tests in a dedicated folder
- Tests must be parametric (i.e. do not have a hardcoded data) where possible
Wordsmithing
abort()andisClosed()should agree on terminology. Use either of "TCP connection" or "socket" <s>1. Work out a better notation forsendX/onXin the javadoc. MaybesendType/onType</s>