APIdia Launch Partner
Top Inners Fields Constructors Methods
jdk.internal.net.http.websocket

public final Class WebSocketImpl

extends Object
implements WebSocket
Class Inheritance
All Implemented Interfaces
java.net.http.WebSocket
Imports
jdk.internal.net.http.HttpClientFacade, jdk.internal.net.http.common.Demand, .Log, .Logger, .MinimalFuture, .SequentialScheduler, .Utils, jdk.internal.net.http.websocket.OpeningHandshake.Result, java.io.IOException, java.lang.ref.Reference, java.net.ProtocolException, .URI, java.net.http.HttpClient, .WebSocket, java.nio.ByteBuffer, .CharBuffer, java.nio.charset.CharacterCodingException, .CharsetEncoder, .CodingErrorAction, .StandardCharsets, java.util.concurrent.Executor, .CompletableFuture, .CompletionStage, java.util.Objects, java.util.concurrent.atomic.AtomicBoolean, .AtomicLong, .AtomicReference, java.util.function.BiConsumer, .Function

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class
pack-priv static enum

Field Summary

Modifier and TypeField and Description
private ByteBuffer
private final Executor
private static final Logger
private final Demand
private final MinimalFuture<WebSocket>
private final AtomicReference<Throwable>
private volatile boolean
private boolean
private final AtomicReference<ByteBuffer>
private final WebSocket.Listener
private final AtomicBoolean
private final AtomicBoolean
private final AtomicBoolean
private String
private final AtomicLong
private final SequentialScheduler
private final AtomicLong
private final AtomicReference<WebSocketImpl.State>
private int
private final String
private CharSequence
private final Transport
private final URI

Constructor Summary

AccessConstructor and Description
private
WebSocketImpl(URI uri, HttpClient client, String subprotocol, WebSocket.Listener listener, TransportFactory transportFactory)

Method Summary

Modifier and TypeMethod and Description
public void
abort()

Implements java.net.http.WebSocket.abort.

Closes this WebSocket's input and output abruptly.

private ByteBuffer
private void
private void
private void
public String
getSubprotocol()

Implements java.net.http.WebSocket.getSubprotocol.

Returns the subprotocol used by this WebSocket.

public boolean
isInputClosed()

Implements java.net.http.WebSocket.isInputClosed.

Tells whether this WebSocket's input is closed.

private static boolean
public boolean
isOutputClosed()

Implements java.net.http.WebSocket.isOutputClosed.

Tells whether this WebSocket's output is closed.

pack-priv static WebSocketImpl
newInstance(URI uri, HttpClient client, String subprotocol, WebSocket.Listener listener, TransportFactory transport)

public static CompletableFuture<WebSocket>
private void
private CompletableFuture<WebSocket>
public void
request(long n)

Implements java.net.http.WebSocket.request.

Increments the counter of invocations of receive methods.

public CompletableFuture<WebSocket>
sendBinary(ByteBuffer message, boolean last)

Implements java.net.http.WebSocket.sendBinary.

Sends binary data with bytes from the given buffer.

public CompletableFuture<WebSocket>
sendClose(int statusCode, String reason)

Implements java.net.http.WebSocket.sendClose.

Initiates an orderly closure of this WebSocket's output by sending a Close message with the given status code and the reason.

private CompletableFuture<WebSocket>
sendClose0(int statusCode, String reason)

private void
sendCloseSilently(int statusCode)

public CompletableFuture<WebSocket>
sendPing(ByteBuffer message)

Implements java.net.http.WebSocket.sendPing.

Sends a Ping message with bytes from the given buffer.

public CompletableFuture<WebSocket>
sendPong(ByteBuffer message)

Implements java.net.http.WebSocket.sendPong.

Sends a Pong message with bytes from the given buffer.

public CompletableFuture<WebSocket>
sendText(CharSequence message, boolean last)

Implements java.net.http.WebSocket.sendText.

Sends textual data with characters from the given character sequence.

private boolean
private boolean
private void
signalClose(int statusCode, String reason)

private void
private void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

protected Transport
private boolean
private boolean
private boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

binaryDataback to summary
private ByteBuffer binaryData
clientExecutorback to summary
private final Executor clientExecutor
debugback to summary
private static final Logger debug
demandback to summary
private final Demand demand
DONEback to summary
private final MinimalFuture<WebSocket> DONE
errorback to summary
private final AtomicReference<Throwable> error
inputClosedback to summary
private volatile boolean inputClosed
lastback to summary
private boolean last
lastAutomaticPongback to summary
private final AtomicReference<ByteBuffer> lastAutomaticPong
listenerback to summary
private final WebSocket.Listener listener
outputClosedback to summary
private final AtomicBoolean outputClosed
pendingPingOrPongback to summary
private final AtomicBoolean pendingPingOrPong
pendingTextOrBinaryback to summary
private final AtomicBoolean pendingTextOrBinary
reasonback to summary
private String reason
receiveCounterback to summary
private final AtomicLong receiveCounter
receiveSchedulerback to summary
private final SequentialScheduler receiveScheduler
sendCounterback to summary
private final AtomicLong sendCounter
stateback to summary
private final AtomicReference<WebSocketImpl.State> state
statusCodeback to summary
private int statusCode
subprotocolback to summary
private final String subprotocol
textback to summary
private CharSequence text
transportback to summary
private final Transport transport
uriback to summary
private final URI uri

Constructor Detail

WebSocketImplback to summary
private WebSocketImpl(URI uri, HttpClient client, String subprotocol, WebSocket.Listener listener, TransportFactory transportFactory)

Method Detail

abortback to summary
public void abort()

Implements java.net.http.WebSocket.abort.

Doc from java.net.http.WebSocket.abort.

Closes this WebSocket's input and output abruptly.

When this method returns both the input and the output will have been closed. Any pending send operations will fail with IOException. Subsequent invocations of abort will have no effect.

Annotations
@Override
clearAutomaticPongback to summary
private ByteBuffer clearAutomaticPong()
clearPendingPingOrPongback to summary
private void clearPendingPingOrPong()
clearPendingTextOrBinaryback to summary
private void clearPendingTextOrBinary()
closeback to summary
private void close()
getSubprotocolback to summary
public String getSubprotocol()

Implements java.net.http.WebSocket.getSubprotocol.

Doc from java.net.http.WebSocket.getSubprotocol.

Returns the subprotocol used by this WebSocket.

Annotations
@Override
isInputClosedback to summary
public boolean isInputClosed()

Implements java.net.http.WebSocket.isInputClosed.

Doc from java.net.http.WebSocket.isInputClosed.

Tells whether this WebSocket's input is closed.

If this method returns true, subsequent invocations will also return true.

Annotations
@Override
isLegalReasonback to summary
private static boolean isLegalReason(String reason)
isOutputClosedback to summary
public boolean isOutputClosed()

Implements java.net.http.WebSocket.isOutputClosed.

Doc from java.net.http.WebSocket.isOutputClosed.

Tells whether this WebSocket's output is closed.

If this method returns true, subsequent invocations will also return true.

Annotations
@Override
newInstanceback to summary
pack-priv static WebSocketImpl newInstance(URI uri, HttpClient client, String subprotocol, WebSocket.Listener listener, TransportFactory transport)
newInstanceAsyncback to summary
public static CompletableFuture<WebSocket> newInstanceAsync(BuilderImpl b)
processCloseErrorback to summary
private void processCloseError(Throwable e)
replaceNullback to summary
private CompletableFuture<WebSocket> replaceNull(CompletableFuture<WebSocket> cf)
requestback to summary
public void request(long n)

Implements java.net.http.WebSocket.request.

Doc from java.net.http.WebSocket.request.

Increments the counter of invocations of receive methods.

This WebSocket will invoke onText, onBinary, onPing, onPong or onClose methods on the associated listener (i.e. receive methods) up to n more times.

Annotations
@Override
sendBinaryback to summary
public CompletableFuture<WebSocket> sendBinary(ByteBuffer message, boolean last)

Implements java.net.http.WebSocket.sendBinary.

Doc from java.net.http.WebSocket.sendBinary.

Sends binary data with bytes from the given buffer.

The data is located in bytes from the buffer's position to its limit. Upon normal completion of a CompletableFuture returned from this method the buffer will have no remaining bytes. The buffer must not be accessed until after that.

The CompletableFuture returned from this method can complete exceptionally with:

  • IllegalStateException - if there is a pending text or binary send operation or if the previous textual data does not complete the message
  • IOException - if an I/O error occurs, or if the output is closed
Annotations
@Override
sendCloseback to summary
public CompletableFuture<WebSocket> sendClose(int statusCode, String reason)

Implements java.net.http.WebSocket.sendClose.

Doc from java.net.http.WebSocket.sendClose.

Initiates an orderly closure of this WebSocket's output by sending a Close message with the given status code and the reason.

The statusCode is an integer from the range 1000 <= code <= 4999. Status codes 1002, 1003, 1006, 1007, 1009, 1010, 1012, 1013 and 1015 are illegal. Behaviour in respect to other status codes is implementation-specific. A legal reason is a string that has a UTF-8 representation not longer than 123 bytes.

A CompletableFuture returned from this method can complete exceptionally with:

Unless the CompletableFuture returned from this method completes with IllegalArgumentException, or the method throws NullPointerException, the output will be closed.

If not already closed, the input remains open until a Close message received, or abort is invoked, or an error occurs.

Annotations
@Override
sendClose0back to summary
private CompletableFuture<WebSocket> sendClose0(int statusCode, String reason)
sendCloseSilentlyback to summary
private void sendCloseSilently(int statusCode)
sendPingback to summary
public CompletableFuture<WebSocket> sendPing(ByteBuffer message)

Implements java.net.http.WebSocket.sendPing.

Doc from java.net.http.WebSocket.sendPing.

Sends a Ping message with bytes from the given buffer.

The message consists of not more than 125 bytes from the buffer's position to its limit. Upon normal completion of a CompletableFuture returned from this method the buffer will have no remaining bytes. The buffer must not be accessed until after that.

The CompletableFuture returned from this method can complete exceptionally with:

Annotations
@Override
sendPongback to summary
public CompletableFuture<WebSocket> sendPong(ByteBuffer message)

Implements java.net.http.WebSocket.sendPong.

Doc from java.net.http.WebSocket.sendPong.

Sends a Pong message with bytes from the given buffer.

The message consists of not more than 125 bytes from the buffer's position to its limit. Upon normal completion of a CompletableFuture returned from this method the buffer will have no remaining bytes. The buffer must not be accessed until after that.

Given that the WebSocket implementation will automatically send a reciprocal pong when a ping is received, it is rarely required to send a pong message explicitly.

The CompletableFuture returned from this method can complete exceptionally with:

Annotations
@Override
sendTextback to summary
public CompletableFuture<WebSocket> sendText(CharSequence message, boolean last)

Implements java.net.http.WebSocket.sendText.

Doc from java.net.http.WebSocket.sendText.

Sends textual data with characters from the given character sequence.

The character sequence must not be modified until the CompletableFuture returned from this method has completed.

A CompletableFuture returned from this method can complete exceptionally with:

  • IllegalStateException - if there is a pending text or binary send operation or if the previous binary data does not complete the message
  • IOException - if an I/O error occurs, or if the output is closed
Annotations
@Override
setPendingPingOrPongback to summary
private boolean setPendingPingOrPong()
setPendingTextOrBinaryback to summary
private boolean setPendingTextOrBinary()
signalCloseback to summary
private void signalClose(int statusCode, String reason)
signalErrorback to summary
private void signalError(Throwable error)
signalOpenback to summary
private void signalOpen()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
transportback to summary
protected Transport transport()
tryChangeStateback to summary
private boolean tryChangeState(WebSocketImpl.State expectedState, WebSocketImpl.State newState)
trySetStateback to summary
private boolean trySetState(WebSocketImpl.State newState)
trySwapAutomaticPongback to summary
private boolean trySwapAutomaticPong(ByteBuffer copy)
jdk.internal.net.http.websocket back to summary

private Class WebSocketImpl.ReceiveTask

extends CompleteRestartableTask
Class Inheritance

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private void
private void
private void
private void
private void
private void
private void
public void
Inherited from jdk.internal.net.http.common.SequentialScheduler.CompleteRestartableTask:
run

Constructor Detail

ReceiveTaskback to summary
private ReceiveTask()

Method Detail

processBinaryback to summary
private void processBinary()
processCloseback to summary
private void processClose() throws IOException
processErrorback to summary
private void processError() throws IOException
processOpenback to summary
private void processOpen()
processPingback to summary
private void processPing()
processPongback to summary
private void processPong()
processTextback to summary
private void processText()
runback to summary
public void run()

Implements abstract jdk.internal.net.http.common.SequentialScheduler.CompleteRestartableTask.run.

Doc from jdk.internal.net.http.common.SequentialScheduler.CompleteRestartableTask.run.

The body of the task.

Annotations
@Override
jdk.internal.net.http.websocket back to summary

private Class WebSocketImpl.SignallingMessageConsumer

extends Object
implements MessageStreamConsumer
Class Inheritance
  • java.lang.Object
  • jdk.internal.net.http.websocket.WebSocketImpl.SignallingMessageConsumer
All Implemented Interfaces
jdk.internal.net.http.websocket.MessageStreamConsumer

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
public void
public void
public void
public void
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

SignallingMessageConsumerback to summary
private SignallingMessageConsumer()

Method Detail

onBinaryback to summary
public void onBinary(ByteBuffer data, boolean last)

Implements jdk.internal.net.http.websocket.MessageStreamConsumer.onBinary.

Annotations
@Override
onCloseback to summary
public void onClose(int statusCode, CharSequence reason)

Implements jdk.internal.net.http.websocket.MessageStreamConsumer.onClose.

Annotations
@Override
onCompleteback to summary
public void onComplete()

Implements jdk.internal.net.http.websocket.MessageStreamConsumer.onComplete.

Annotations
@Override
onErrorback to summary
public void onError(Throwable error)

Implements jdk.internal.net.http.websocket.MessageStreamConsumer.onError.

Annotations
@Override
onPingback to summary
public void onPing(ByteBuffer data)

Implements jdk.internal.net.http.websocket.MessageStreamConsumer.onPing.

Annotations
@Override
onPongback to summary
public void onPong(ByteBuffer data)

Implements jdk.internal.net.http.websocket.MessageStreamConsumer.onPong.

Annotations
@Override
onTextback to summary
public void onText(CharSequence data, boolean last)

Implements jdk.internal.net.http.websocket.MessageStreamConsumer.onText.

Annotations
@Override
jdk.internal.net.http.websocket back to summary

pack-priv final Enum WebSocketImpl.State

extends Enum<WebSocketImpl.State>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final WebSocketImpl.State
public static final WebSocketImpl.State
public static final WebSocketImpl.State
public static final WebSocketImpl.State
public static final WebSocketImpl.State
public static final WebSocketImpl.State
public static final WebSocketImpl.State
public static final WebSocketImpl.State
public static final WebSocketImpl.State

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static WebSocketImpl.State
public static WebSocketImpl.State[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

BINARYback to summary
public static final WebSocketImpl.State BINARY
CLOSEback to summary
public static final WebSocketImpl.State CLOSE
ERRORback to summary
public static final WebSocketImpl.State ERROR
IDLEback to summary
public static final WebSocketImpl.State IDLE
OPENback to summary
public static final WebSocketImpl.State OPEN
PINGback to summary
public static final WebSocketImpl.State PING
PONGback to summary
public static final WebSocketImpl.State PONG
TEXTback to summary
public static final WebSocketImpl.State TEXT
WAITINGback to summary
public static final WebSocketImpl.State WAITING

Constructor Detail

Stateback to summary
private State()

Method Detail

valueOfback to summary
public static WebSocketImpl.State valueOf(String name)
valuesback to summary
public static WebSocketImpl.State[] values()