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

public Class ServerWebSocketImpl

extends WebSocketImplBase<ServerWebSocketImpl>
implements ServerWebSocket
Class Inheritance
All Implemented Interfaces
io.vertx.core.http.ServerWebSocket, io.vertx.core.http.WebSocketBase, io.vertx.core.streams.WriteStream, io.vertx.core.streams.StreamBase, io.vertx.core.streams.ReadStream
Imports
io.netty.channel.Channel, .ChannelHandler, .ChannelPipeline, io.netty.handler.codec.http.HttpHeaders, .HttpResponseStatus, io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker, io.vertx.core.AsyncResult, .Future, .Handler, .Promise, io.vertx.core.http.ServerWebSocket, .WebSocketFrame, io.vertx.core.http.impl.ws.WebSocketFrameImpl, io.vertx.core.impl.ContextInternal, io.vertx.core.net.HostAndPort, io.vertx.core.spi.metrics.HttpServerMetrics, java.util.concurrent.atomic.AtomicReferenceFieldUpdater

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

Field Summary

Modifier and TypeField and Description
private final HostAndPort
private final long
private final Http1xServerConnection
private Promise<Integer>
private final WebSocketServerHandshaker
private final String
private final String
private final String
private Http1xServerRequest
private final String
private volatile Integer
private static final AtomicReferenceFieldUpdater<ServerWebSocketImpl, Integer>
private final String
Inherited from io.vertx.core.http.impl.WebSocketImplBase:
context

Constructor Summary

AccessConstructor and Description
pack-priv
ServerWebSocketImpl(ContextInternal context, Http1xServerConnection conn, boolean supportsContinuation, long closingTimeout, Http1xServerRequest request, WebSocketServerHandshaker handshaker, int maxWebSocketFrameSize, int maxWebSocketMessageSize, boolean registerWebSocketWriteHandlers)

Method Summary

Modifier and TypeMethod and Description
public void
accept()

Implements io.vertx.core.http.ServerWebSocket.accept.

Accept the WebSocket and terminate the WebSocket handshake.

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

Overrides io.vertx.core.http.impl.WebSocketImplBase.close.

private void
protected void
protected void
handleCloseConnection()

Implements abstract io.vertx.core.http.impl.WebSocketImplBase.handleCloseConnection.

Called when a close frame is received and the WebSocket.

private void
public String
public String
public String
public void
reject()

Implements io.vertx.core.http.ServerWebSocket.reject.

Reject the WebSocket.

public void
reject(int sc)

Implements io.vertx.core.http.ServerWebSocket.reject.

Like reject() but with a status.

public String
public void
setHandshake(Future<Integer>
the future to complete with
future
,
Handler<AsyncResult<Integer>>
the completion handler
handler
)

Implements io.vertx.core.http.ServerWebSocket.setHandshake.

Set an asynchronous result for the handshake, upon completion of the specified future, the WebSocket will either be

  • accepted when the future succeeds with the HTTP 101 status code
  • rejected when the future is succeeds with an HTTP status code different than 101
  • rejected when the future fails with the HTTP status code 500
public Future<Integer>
setHandshake(Future<Integer> future)

Implements io.vertx.core.http.ServerWebSocket.setHandshake.

Like setHandshake(Future, Handler) but returns a Future of the asynchronous result

pack-priv Boolean
tryHandshake(int sc)

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

Overrides io.vertx.core.http.impl.WebSocketImplBase.writeFrame.

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

Write a WebSocket frame to the connection

Inherited from io.vertx.core.http.impl.WebSocketImplBase:
binaryHandlerIDbinaryMessageHandlerchannelHandlerContextcheckClosedclosecloseclosecloseclosecloseConnectioncloseHandlercloseReasoncloseStatusCodeconnectiondrainHandlerendendendHandlerexceptionHandlerfetchframeHandlergetMetrichandleConnectionClosedhandleExceptionhandleFramehandlerhandleWritabilityChangedheadersheadersinitiateConnectionCloseTimeoutisClosedisSsllocalAddresspausepeerCertificateChainpeerCertificatespongHandlerregisterHandlerremoteAddressresumesetMetricsetWriteQueueMaxSizesslSessionsubProtocolsubProtocoltextHandlerIDtextMessageHandlerunsafeWriteFramewritewritewriteBinaryMessagewriteBinaryMessagewriteFinalBinaryFramewriteFinalBinaryFramewriteFinalTextFramewriteFinalTextFramewriteFramewritePingwritePingwritePongwritePongwriteQueueFullwriteTextMessagewriteTextMessage

Field Detail

authorityback to summary
private final HostAndPort authority
closingTimeoutMSback to summary
private final long closingTimeoutMS
connback to summary
private final Http1xServerConnection conn

Hides io.vertx.core.http.impl.WebSocketImplBase.conn.

handshakePromiseback to summary
private Promise<Integer> handshakePromise
handshakerback to summary
private final WebSocketServerHandshaker handshaker
hostback to summary
private final String host
pathback to summary
private final String path
queryback to summary
private final String query
requestback to summary
private Http1xServerRequest request
schemeback to summary
private final String scheme
statusback to summary
private volatile Integer status
STATUS_UPDATERback to summary
private static final AtomicReferenceFieldUpdater<ServerWebSocketImpl, Integer> STATUS_UPDATER
uriback to summary
private final String uri

Constructor Detail

ServerWebSocketImplback to summary
pack-priv ServerWebSocketImpl(ContextInternal context, Http1xServerConnection conn, boolean supportsContinuation, long closingTimeout, Http1xServerRequest request, WebSocketServerHandshaker handshaker, int maxWebSocketFrameSize, int maxWebSocketMessageSize, boolean registerWebSocketWriteHandlers)

Method Detail

acceptback to summary
public void accept()

Implements io.vertx.core.http.ServerWebSocket.accept.

Doc from io.vertx.core.http.ServerWebSocket.accept.

Accept the WebSocket and terminate the WebSocket handshake.

This method should be called from the WebSocket handler to explicitly accept the WebSocket and terminate the WebSocket handshake.

Annotations
@Override
authorityback to summary
public HostAndPort authority()

Implements io.vertx.core.http.ServerWebSocket.authority.

Returns:HostAndPort

Doc from io.vertx.core.http.ServerWebSocket.authority.

the WebSocket handshake authority

Annotations
@Override
closeback to summary
public Future<Void> close(short statusCode, String reason)

Overrides io.vertx.core.http.impl.WebSocketImplBase.close.

Annotations
@Override
doHandshakeback to summary
private void doHandshake()
handleCloseback to summary
protected void handleClose(boolean graceful)

Overrides io.vertx.core.http.impl.WebSocketImplBase.handleClose.

Annotations
@Override
handleCloseConnectionback to summary
protected void handleCloseConnection()

Implements abstract io.vertx.core.http.impl.WebSocketImplBase.handleCloseConnection.

Doc from io.vertx.core.http.impl.WebSocketImplBase.handleCloseConnection.

Called when a close frame is received and the WebSocket.

Annotations
@Override
handleHandshakeback to summary
private void handleHandshake(int sc)
hostback to summary
public String host()

Implements io.vertx.core.http.ServerWebSocket.host.

Returns:String

Doc from io.vertx.core.http.ServerWebSocket.host.

the WebSocket handshake host

Annotations
@Override
pathback to summary
public String path()

Implements io.vertx.core.http.ServerWebSocket.path.

Returns:String

Doc from io.vertx.core.http.ServerWebSocket.path.

the WebSocket handshake path.

Annotations
@Override
queryback to summary
public String query()

Implements io.vertx.core.http.ServerWebSocket.query.

Returns:String

Doc from io.vertx.core.http.ServerWebSocket.query.

the WebSocket handshake query string.

Annotations
@Override
rejectback to summary
public void reject()

Implements io.vertx.core.http.ServerWebSocket.reject.

Doc from io.vertx.core.http.ServerWebSocket.reject.

Reject the WebSocket.

Calling this method from the WebSocket handler when it is first passed to you gives you the opportunity to reject the WebSocket, which will cause the WebSocket handshake to fail by returning a 502 response code.

You might use this method, if for example you only want to accept WebSockets with a particular path.

Annotations
@Override
rejectback to summary
public void reject(int sc)

Implements io.vertx.core.http.ServerWebSocket.reject.

Doc from io.vertx.core.http.ServerWebSocket.reject.

Like reject() but with a status.

Annotations
@Override
schemeback to summary
public String scheme()

Implements io.vertx.core.http.ServerWebSocket.scheme.

Returns:String

Doc from io.vertx.core.http.ServerWebSocket.scheme.

the WebSocket handshake scheme

Annotations
@Override
setHandshakeback to summary
public void setHandshake(Future<Integer> future, Handler<AsyncResult<Integer>> handler)

Implements io.vertx.core.http.ServerWebSocket.setHandshake.

Doc from io.vertx.core.http.ServerWebSocket.setHandshake.

Set an asynchronous result for the handshake, upon completion of the specified future, the WebSocket will either be

  • accepted when the future succeeds with the HTTP 101 status code
  • rejected when the future is succeeds with an HTTP status code different than 101
  • rejected when the future fails with the HTTP status code 500
The provided future might be completed by the WebSocket itself, e.g calling the close() method will try to accept the handshake and close the WebSocket afterward. Thus it is advised to try to complete the future with Promise#tryComplete or Promise#tryFail.

This method should be called from the WebSocket handler to explicitly set an asynchronous handshake.

Calling this method will override the future completion handler.

Parameters
future:Future<Integer>

the future to complete with

handler:Handler<AsyncResult<Integer>>

the completion handler

Annotations
@Override
setHandshakeback to summary
public Future<Integer> setHandshake(Future<Integer> future)

Implements io.vertx.core.http.ServerWebSocket.setHandshake.

Doc from io.vertx.core.http.ServerWebSocket.setHandshake.

Like setHandshake(Future, Handler) but returns a Future of the asynchronous result

Annotations
@Override
tryHandshakeback to summary
pack-priv Boolean tryHandshake(int sc)
uriback to summary
public String uri()

Implements io.vertx.core.http.ServerWebSocket.uri.

Annotations
@Override
writeFrameback to summary
public Future<Void> writeFrame(WebSocketFrame frame)

Overrides io.vertx.core.http.impl.WebSocketImplBase.writeFrame.

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

Doc from io.vertx.core.http.WebSocketBase.writeFrame.

Write a WebSocket frame to the connection

Parameters
frame:WebSocketFrame

the frame to write

Returns:Future<Void>

a future completed with the result

Annotations
@Override