@Override public void close() { /* This is assumed to always be a NORMAL closure, no reason phrase */ close(new CloseInfo(StatusCode.NORMAL), null); }
public CloseFrame asFrame() { CloseFrame frame = new CloseFrame(); frame.setFin(true); // Frame forbidden codes result in no status code (and no reason string) if ((statusCode != StatusCode.NO_CLOSE) && (statusCode != StatusCode.NO_CODE) && (statusCode != StatusCode.FAILED_TLS_HANDSHAKE)) { assertValidStatusCode(statusCode); frame.setPayload(asByteBuffer()); } return frame; }
@Override public void onClose(CloseInfo close) { if (hasCloseBeenCalled) { // avoid duplicate close events (possible when using harsh Session.disconnect()) return; } hasCloseBeenCalled = true; int statusCode = close.getStatusCode(); String reason = close.getReason(); listener.onWebSocketClose(statusCode,reason); }
CloseInfo close = new CloseInfo(frame,validate); session.close(close.getStatusCode(),close.getReason());
public WebSocketFrame asFrame() { WebSocketFrame frame = new WebSocketFrame(OpCode.CLOSE); frame.setFin(true); frame.setPayload(asByteBuffer()); return frame; }
@Override public String toString() { return String.format("CloseInfo[code=%d,reason=%s]",statusCode,getReason()); } }
/** * CLOSE Primary Entry Point. * * <ul> * <li>atomically enqueue CLOSE frame + flip flag to reject more frames</li> * <li>setup CLOSE frame callback: must close flusher</li> * </ul> * * @param closeInfo the close details */ private void close(CloseInfo closeInfo, Callback callback) { if (LOG.isDebugEnabled()) LOG.debug("close({})", closeInfo); if (closed.compareAndSet(false, true)) { CloseFrame frame = closeInfo.asFrame(); connection.outgoingFrame(frame, new OnCloseLocalCallback(callback, connection, closeInfo), BatchMode.OFF); } }
@Override public void onLocalClose(CloseInfo close) { if (LOG.isDebugEnabled()) LOG.debug("Local Close Confirmed {}",close); if (close.isAbnormal()) { ioState.onAbnormalClose(close); } else { ioState.onCloseLocal(close); } }
@Override public void onClose(CloseInfo close) { if (hasCloseBeenCalled) { // avoid duplicate close events (possible when using harsh Session.disconnect()) return; } hasCloseBeenCalled = true; int statusCode = close.getStatusCode(); String reason = close.getReason(); listener.onWebSocketClose(statusCode,reason); }
CloseInfo close = new CloseInfo(frame,validate); session.close(close.getStatusCode(),close.getReason());
public WebSocketFrame asFrame() { WebSocketFrame frame = new WebSocketFrame(OpCode.CLOSE); frame.setFin(true); frame.setPayload(asByteBuffer()); return frame; }
if (closeInfo.isAbnormal())
@Override public void onClose(CloseInfo close) { if (hasCloseBeenCalled) { // avoid duplicate close events (possible when using harsh Session.disconnect()) return; } hasCloseBeenCalled = true; if (events.onClose != null) { events.onClose.call(websocket,session,close.getStatusCode(),close.getReason()); } }
@Override public void close(int statusCode, String reason) { close(new CloseInfo(statusCode, reason), null); }
@Override public void onClose(CloseInfo close) { if (hasCloseBeenCalled) { // avoid duplicate close events (possible when using harsh Session.disconnect()) return; } hasCloseBeenCalled = true; int statusCode = close.getStatusCode(); String reason = close.getReason(); listener.onWebSocketClose(statusCode,reason); }
public void onDisconnected() { ConnectionState event = null; synchronized (this) { if (this.state == ConnectionState.CLOSED) { // already closed return; } CloseInfo close = new CloseInfo(StatusCode.ABNORMAL,"Disconnected"); this.cleanClose = false; this.state = ConnectionState.CLOSED; this.closeInfo = close; this.inputAvailable = false; this.outputAvailable = false; this.closeHandshakeSource = CloseHandshakeSource.ABNORMAL; event = this.state; } notifyStateListeners(event); }
/** * Enqueue a close frame. * * @param statusCode * the WebSocket status code. * @param reason * the (optional) reason string. (null is allowed) * @see StatusCode */ private void enqueClose(int statusCode, String reason) { synchronized (writeBytes) { // It is possible to get close events from many different sources. // Make sure we only sent 1 over the network. if (writeBytes.isClosed()) { // already sent the close return; } } CloseInfo close = new CloseInfo(statusCode,reason); // TODO: create DisconnectCallback? outgoingFrame(close.asFrame(),new OnCloseCallback()); }