Top Description Inners Fields Constructors Methods
io.vertx.core.http.impl

public abstract Class WebSocketImplBase<S extends WebSocketBase>

extends Object
implements WebSocketInternal
Class Inheritance
All Implemented Interfaces
io.vertx.core.http.impl.WebSocketInternal, io.vertx.core.http.WebSocketBase, io.vertx.core.streams.WriteStream, io.vertx.core.streams.StreamBase, io.vertx.core.streams.ReadStream
Known Direct Subclasses
io.vertx.core.http.impl.ServerWebSocketImpl, io.vertx.core.http.impl.WebSocketImpl
Type Parameters
<S>
self return type
Imports
io.netty.buffer.ByteBuf, io.netty.channel.ChannelHandlerContext, .ChannelPromise, io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame, .CloseWebSocketFrame, .ContinuationWebSocketFrame, .PingWebSocketFrame, .PongWebSocketFrame, .TextWebSocketFrame, io.vertx.codegen.annotations.Nullable, io.vertx.core.AsyncResult, .Future, .Handler, .MultiMap, .Promise, io.vertx.core.buffer.Buffer, io.vertx.core.eventbus.EventBus, .Message, .MessageConsumer, io.vertx.core.http.HttpConnection, .WebSocketBase, .WebSocketFrame, .WebSocketFrameType, io.vertx.core.http.impl.ws.WebSocketFrameImpl, .WebSocketFrameInternal, io.vertx.core.impl.ContextInternal, io.vertx.core.impl.future.PromiseInternal, io.vertx.core.net.SocketAddress, io.vertx.core.streams.impl.InboundBuffer, javax.net.ssl.SSLPeerUnverifiedException, .SSLSession, javax.security.cert.X509Certificate, java.nio.charset.StandardCharsets, java.security.cert.Certificate, java.util.List, .UUID

This class is optimised for performance when used on the same event loop. However it can be used safely from other threads.

The internal state is protected using the synchronized keyword. If always used on the same event loop, then we benefit from biased locking which makes the overhead of synchronized near zero.

Author
Tim Fox

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private final String
private MessageConsumer<T>
private ChannelHandlerContext
private boolean
private Handler<Void>
private String
private Short
private long
protected final Http1xConnectionBase<S extends WebSocketImplBase<S>>
protected final ContextInternal
private Handler<Void>
private Handler<Void>
private WebSocketImplBase<S>.FrameAggregator
private Handler<WebSocketFrameInternal>
private Handler<Buffer>
private MultiMap
private final int
private final int
private Object
private final InboundBuffer<WebSocketFrameInternal>
private Handler<Buffer>
private String
private final boolean
private final String
private MessageConsumer<T>
private boolean

Constructor Summary

AccessConstructor and Description
pack-priv
WebSocketImplBase(ContextInternal context, Http1xConnectionBase<S extends WebSocketImplBase<S>> conn, boolean supportsContinuation, int maxWebSocketFrameSize, int maxWebSocketMessageSize, boolean registerWebSocketWriteHandlers)

Method Summary

Modifier and TypeMethod and Description
public String
binaryHandlerID()

Implements io.vertx.core.http.WebSocketBase.binaryHandlerID.

When a WebSocket is created, it may register an event handler with the event bus - the ID of that handler is given by this method.

public S
public ChannelHandlerContext
pack-priv void
public Future<Void>
close()

Implements io.vertx.core.http.WebSocketBase.close.

Close the WebSocket sending the default close frame.

public void
close(Handler<AsyncResult<Void>> handler)

Implements io.vertx.core.http.WebSocketBase.close.

Same as close() but with an handler called when the operation completes

public Future<Void>
close(short
the status code
statusCode
)

Implements io.vertx.core.http.WebSocketBase.close.

Close the WebSocket sending a close frame with specified status code.

public void
close(short statusCode, Handler<AsyncResult<Void>> handler)

Implements io.vertx.core.http.WebSocketBase.close.

Same as close(short) but with an handler called when the operation completes

public void
close(short statusCode, @Nullable String reason, Handler<AsyncResult<Void>> handler)

public Future<Void>
close(short statusCode, String reason)

pack-priv void
closeConnection()

Close the connection.

public S
public String
closeReason()

Implements io.vertx.core.http.WebSocketBase.closeReason.

Returns the close reason message from the remote endpoint or null when not yet received.

public Short
closeStatusCode()

Implements io.vertx.core.http.WebSocketBase.closeStatusCode.

Returns the close status code received from the remote endpoint or null when not yet received.

public HttpConnection
public S
private static WebSocketFrame
public Future<Void>
end()

Implements io.vertx.core.http.WebSocketBase.end.

Ends the stream.

public void
end(Handler<AsyncResult<Void>> handler)

Implements io.vertx.core.http.WebSocketBase.end.

Same as end() but with an handler called when the operation completes Calls close(Handler)

public S
private Handler<Void>
public S
public S
fetch(long amount)

Implements io.vertx.core.http.WebSocketBase.fetch.

Fetch the specified amount of elements.

public S
pack-priv synchronized Object
protected void
handleClose(boolean graceful)

protected abstract void
handleCloseConnection()

Called when a close frame is received and the WebSocket.

private void
pack-priv void
pack-priv void
pack-priv void
public S
private Handler<Buffer>
pack-priv void
handleWritabilityChanged(boolean writable)

public MultiMap
headers()

Implements io.vertx.core.http.WebSocketBase.headers.

Returns the HTTP headers when the WebSocket is first obtained in the handler.

pack-priv void
headers(MultiMap responseHeaders)

pack-priv void
initiateConnectionCloseTimeout(long
the timeout in milliseconds
timeoutMillis
)

Initiate a timeout that will close the TCP connection.

public boolean
public boolean
public SocketAddress
public S
pause()

Implements io.vertx.core.http.WebSocketBase.pause.

Pause the ReadStream, it sets the buffer in fetch mode and clears the actual demand.

public X509Certificate[]
peerCertificateChain()

Implements io.vertx.core.http.WebSocketBase.peerCertificateChain.

References Deprecated X509Certificate is deprecated or references (maybe indirectly) at least one deprecated element.

public List<Certificate>
public WebSocketBase
private Handler<Buffer>
private void
pack-priv void
public SocketAddress
public S
resume()

Implements io.vertx.core.http.WebSocketBase.resume.

Resume reading, and sets the buffer in flowing mode.

pack-priv synchronized void
setMetric(Object metric)

public S
setWriteQueueMaxSize(int
the max size of the write stream
maxSize
)

Implements io.vertx.core.http.WebSocketBase.setWriteQueueMaxSize.

Set the maximum size of the write queue to maxSize.

public SSLSession
public String
subProtocol()

Implements io.vertx.core.http.WebSocketBase.subProtocol.

Returns the WebSocket sub protocol selected by the WebSocket handshake.

pack-priv void
subProtocol(String subProtocol)

public String
textHandlerID()

Implements io.vertx.core.http.WebSocketBase.textHandlerID.

When a WebSocket is created, it may register an event handler with the eventbus, the ID of that handler is given by textHandlerID.

public WebSocketBase
private boolean
protected final Future<Void>
public Future<Void>
write(Buffer
the data to write
data
)

Implements io.vertx.core.streams.WriteStream.write.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Write some data to the stream.

public final void
write(Buffer data, Handler<AsyncResult<Void>> handler)

Implements io.vertx.core.streams.WriteStream.write.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Same as write(T) but with an handler called when the operation completes

private void
writeBinaryFrameInternal(Buffer data)
References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

public Future<Void>
writeBinaryMessage(Buffer
the data to write
data
)

Implements io.vertx.core.http.WebSocketBase.writeBinaryMessage.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Writes a (potentially large) piece of binary data to the connection.

public final S
writeBinaryMessage(Buffer data, Handler<AsyncResult<Void>> handler)

Implements io.vertx.core.http.WebSocketBase.writeBinaryMessage.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Same as writeBinaryMessage(Buffer) but with an handler called when the operation completes

public Future<Void>
writeFinalBinaryFrame(Buffer
The data to write
data
)

Implements io.vertx.core.http.WebSocketBase.writeFinalBinaryFrame.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Write a final WebSocket binary frame to the connection

public S
writeFinalBinaryFrame(Buffer data, Handler<AsyncResult<Void>> handler)

Implements io.vertx.core.http.WebSocketBase.writeFinalBinaryFrame.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Same as writeFinalBinaryFrame(Buffer, Handler) but with an handler called when the operation completes

public Future<Void>
writeFinalTextFrame(String
The text to write
text
)

Implements io.vertx.core.http.WebSocketBase.writeFinalTextFrame.

Write a final WebSocket text frame to the connection

public S
writeFinalTextFrame(String text, Handler<AsyncResult<Void>> handler)

Implements io.vertx.core.http.WebSocketBase.writeFinalTextFrame.

Same as writeFinalTextFrame(String, Handler) but with an handler called when the operation completes

public Future<Void>
writeFrame(WebSocketFrame
the frame to write
frame
)

Implements io.vertx.core.http.WebSocketBase.writeFrame.

Write a WebSocket frame to the connection

public final S
writeFrame(WebSocketFrame frame, Handler<AsyncResult<Void>> handler)

Implements io.vertx.core.http.WebSocketBase.writeFrame.

Same as writeFrame(WebSocketFrame) but with an handler called when the operation completes

private Future<Void>
writePartialMessage(WebSocketFrameType frameType, Buffer data, int offset)
References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Splits the provided buffer into multiple frames (which do not exceed the maximum web socket frame size) and writes them in order to the socket.

public Future<Void>
writePing(Buffer data)

Implements io.vertx.core.http.WebSocketBase.writePing.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Like writePing(Buffer, Handler) but with an handler called when the message has been written or failed to be written.

public final S
writePing(Buffer
the data to write, may be at most 125 bytes
data
,
Handler<AsyncResult<Void>>
called when the ping frame has been successfully written
handler
)

Implements io.vertx.core.http.WebSocketBase.writePing.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Writes a ping frame to the connection.

public Future<Void>
writePong(Buffer data)

Implements io.vertx.core.http.WebSocketBase.writePong.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Like writePong(Buffer, Handler) but with an handler called when the message has been written or failed to be written.

public final S
writePong(Buffer
the data to write, may be at most 125 bytes
data
,
Handler<AsyncResult<Void>>
called when the pong frame has been successfully written
handler
)

Implements io.vertx.core.http.WebSocketBase.writePong.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Writes a pong frame to the connection.

public boolean
writeQueueFull()

Implements io.vertx.core.streams.WriteStream.writeQueueFull.

This will return true if there are more bytes in the write queue than the value set using setWriteQueueMaxSize

private void
public Future<Void>
writeTextMessage(String
the data to write
text
)

Implements io.vertx.core.http.WebSocketBase.writeTextMessage.

Writes a (potentially large) piece of text data to the connection.

public final S
writeTextMessage(String text, Handler<AsyncResult<Void>> handler)

Implements io.vertx.core.http.WebSocketBase.writeTextMessage.

Same as writeTextMessage(String) but with an handler called when the operation completes

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait