/** * Construct Generator with provided policy and bufferPool * * @param policy * the policy to use * @param bufferPool * the buffer pool to use * @param validating * true to enable RFC frame validation */ public Generator(WebSocketPolicy policy, ByteBufferPool bufferPool, boolean validating) { this.behavior = policy.getBehavior(); this.bufferPool = bufferPool; this.validating = validating; }
/** * Construct Generator with provided policy and bufferPool * * @param policy * the policy to use * @param bufferPool * the buffer pool to use * @param validating * true to enable RFC frame validation * @param readOnly * true if generator is to treat frames as read-only and not modify them. Useful for debugging purposes, but not generally for runtime use. */ public Generator(WebSocketPolicy policy, ByteBufferPool bufferPool, boolean validating, boolean readOnly) { this.behavior = policy.getBehavior(); this.bufferPool = bufferPool; this.validating = validating; this.readOnly = readOnly; }
/** * Construct Generator with provided policy and bufferPool * * @param policy * the policy to use * @param bufferPool * the buffer pool to use * @param validating * true to enable RFC frame validation */ public Generator(WebSocketPolicy policy, ByteBufferPool bufferPool, boolean validating) { this.behavior = policy.getBehavior(); this.bufferPool = bufferPool; this.validating = validating; }
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("WebSocketSession["); builder.append("websocket=").append(websocket); builder.append(",behavior=").append(policy.getBehavior()); builder.append(",connection=").append(connection); builder.append(",remote=").append(remote); builder.append(",incoming=").append(incomingHandler); builder.append(",outgoing=").append(outgoingHandler); builder.append("]"); return builder.toString(); } }
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("WebSocketSession["); builder.append("websocket=").append(websocket); builder.append(",behavior=").append(policy.getBehavior()); builder.append(",connection=").append(connection); builder.append(",remote=").append(remote); builder.append(",incoming=").append(incomingHandler); builder.append(",outgoing=").append(outgoingHandler); builder.append("]"); return builder.toString(); }
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("WebSocketSession["); builder.append("websocket=").append(websocket); builder.append(",behavior=").append(policy.getBehavior()); builder.append(",connection=").append(connection); builder.append(",remote=").append(remote); builder.append(",incoming=").append(incomingHandler); builder.append(",outgoing=").append(outgoingHandler); builder.append("]"); return builder.toString(); } }
private void unhandled(Throwable t) { LOG.warn("Unhandled Error (closing connection)",t); // Unhandled Error, close the connection. switch (policy.getBehavior()) { case SERVER: terminateConnection(StatusCode.SERVER_ERROR,t.getClass().getSimpleName()); break; case CLIENT: terminateConnection(StatusCode.POLICY_VIOLATION,t.getClass().getSimpleName()); break; } } }
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append(this.getClass().getSimpleName()); builder.append("@").append(Integer.toHexString(hashCode())); builder.append("[behavior=").append(getBehavior()); builder.append(",maxTextMessageSize=").append(getMaxTextMessageSize()); builder.append(",maxTextMessageBufferSize=").append(getMaxTextMessageBufferSize()); builder.append(",maxBinaryMessageSize=").append(getMaxBinaryMessageSize()); builder.append(",maxBinaryMessageBufferSize=").append(getMaxTextMessageBufferSize()); builder.append(",asyncWriteTimeout=").append(getAsyncWriteTimeout()); builder.append(",idleTimeout=").append(getIdleTimeout()); builder.append(",inputBufferSize=").append(getInputBufferSize()); builder.append("]"); return builder.toString(); }
private void unhandled(Throwable t) { LOG.warn("Unhandled Error (closing connection)",t); // Unhandled Error, close the connection. switch (policy.getBehavior()) { case SERVER: terminateConnection(StatusCode.SERVER_ERROR,t.getClass().getSimpleName()); break; case CLIENT: terminateConnection(StatusCode.POLICY_VIOLATION,t.getClass().getSimpleName()); break; } } }
/** * Jetty Connection onOpen event * * @param connection the connection that was opened */ @Override public void onOpened(Connection connection) { if(LOG_OPEN.isDebugEnabled()) LOG_OPEN.debug("[{}] {}.onOpened()",policy.getBehavior(),this.getClass().getSimpleName()); open(); }
@Override public void onOpen() { if(LOG.isDebugEnabled()) LOG.debug("[{}] {}.onOpened()",policy.getBehavior(),this.getClass().getSimpleName()); super.onOpen(); this.ioState.onOpened(); }
@Override public RemoteEndpoint getRemote() { if(LOG_OPEN.isDebugEnabled()) LOG_OPEN.debug("[{}] {}.getRemote()",policy.getBehavior(),this.getClass().getSimpleName()); ConnectionState state = connection.getIOState().getConnectionState(); if ((state == ConnectionState.OPEN) || (state == ConnectionState.CONNECTED)) { return remote; } throw new WebSocketException("RemoteEndpoint unavailable, current state [" + state + "], expecting [OPEN or CONNECTED]"); }
private void unhandled(Throwable t) { TARGET_LOG.warn("Unhandled Error (closing connection)",t); onError(t); if (t instanceof CloseException) { terminateConnection(((CloseException)t).getStatusCode(),t.getClass().getSimpleName()); return; } // Unhandled Error, close the connection. switch (policy.getBehavior()) { case SERVER: terminateConnection(StatusCode.SERVER_ERROR,t.getClass().getSimpleName()); break; case CLIENT: terminateConnection(StatusCode.POLICY_VIOLATION,t.getClass().getSimpleName()); break; } } }
/** * Physical connection disconnect. * <p> * Not related to WebSocket close handshake. */ @Override public void onClose() { if (LOG.isDebugEnabled()) LOG.debug("{} onClose()",policy.getBehavior()); super.onClose(); ioState.onDisconnected(); }
@Override public void disconnect() { if (LOG.isDebugEnabled()) LOG.debug("{} disconnect()",policy.getBehavior()); flusher.terminate(new EOFException("Disconnected"), false); EndPoint endPoint = getEndPoint(); // We need to gently close first, to allow // SSL close alerts to be sent by Jetty endPoint.shutdownOutput(); endPoint.close(); }
@Override public void onFillable() { LOG.debug("{} onFillable()",policy.getBehavior()); stats.countOnFillableEvents.incrementAndGet(); ByteBuffer buffer = bufferPool.acquire(getInputBufferSize(),true); BufferUtil.clear(buffer); boolean readMore = false; try { isFilling = true; readMore = (read(buffer) != -1); } finally { bufferPool.release(buffer); } if (readMore && (suspendToken.get() == false)) { fillInterested(); } else { isFilling = false; } }
@Override public void onFillable() { LOG.debug("{} onFillable()",policy.getBehavior()); stats.countOnFillableEvents.incrementAndGet(); ByteBuffer buffer = bufferPool.acquire(getInputBufferSize(),true); BufferUtil.clear(buffer); boolean readMore = false; try { isFilling = true; readMore = (read(buffer) != -1); } finally { bufferPool.release(buffer); } if (readMore && (suspendToken.get() == false)) { fillInterested(); } else { isFilling = false; } }
LOG.debug("{} onFillable()",policy.getBehavior()); stats.countOnFillableEvents.incrementAndGet();
/** * Incoming mux control block, destined for the control channel (id 0) */ @Override public void onMuxNewChannelSlot(MuxNewChannelSlot slot) { if (policy.getBehavior() == WebSocketBehavior.SERVER) { throw new MuxPhysicalConnectionException(MuxDropChannel.Reason.UNKNOWN_MUX_CONTROL_BLOCK,"NewChannelSlot not allowed per spec"); } if (slot.isFallback()) { if (slot.getNumberOfSlots() == 0) { throw new MuxPhysicalConnectionException(MuxDropChannel.Reason.UNKNOWN_MUX_CONTROL_BLOCK,"Cannot have 0 number of slots during fallback"); } if (slot.getInitialSendQuota() == 0) { throw new MuxPhysicalConnectionException(MuxDropChannel.Reason.UNKNOWN_MUX_CONTROL_BLOCK,"Cannot have 0 initial send quota during fallback"); } } // TODO: handle channel slot }
/** * Incoming mux control block, destined for the control channel (id 0) */ @Override public void onMuxNewChannelSlot(MuxNewChannelSlot slot) { if (policy.getBehavior() == WebSocketBehavior.SERVER) { throw new MuxPhysicalConnectionException(MuxDropChannel.Reason.UNKNOWN_MUX_CONTROL_BLOCK,"NewChannelSlot not allowed per spec"); } if (slot.isFallback()) { if (slot.getNumberOfSlots() == 0) { throw new MuxPhysicalConnectionException(MuxDropChannel.Reason.UNKNOWN_MUX_CONTROL_BLOCK,"Cannot have 0 number of slots during fallback"); } if (slot.getInitialSendQuota() == 0) { throw new MuxPhysicalConnectionException(MuxDropChannel.Reason.UNKNOWN_MUX_CONTROL_BLOCK,"Cannot have 0 initial send quota during fallback"); } } // TODO: handle channel slot }