@Override public void onStreamAdded(Http2Stream stream) { // Unconditionally used the reduced flow control state because it requires no object allocation // and the DefaultFlowState will be allocated in onStreamActive. stream.setProperty(stateKey, REDUCED_FLOW_STATE); }
DefaultHttp2FrameStream setStreamAndProperty(PropertyKey streamKey, Http2Stream stream) { assert id == -1 || stream.id() == id; this.stream = stream; stream.setProperty(streamKey, this); return this; }
@Override public void onStreamActive(Http2Stream stream) { // Need to be sure the stream's initial window is adjusted for SETTINGS // frames which may have been exchanged while it was in IDLE stream.setProperty(stateKey, new DefaultState(stream, initialWindowSize)); }
DefaultHttp2FrameStream setStreamAndProperty(PropertyKey streamKey, Http2Stream stream) { assert id == -1 || stream.id() == id; this.stream = stream; stream.setProperty(streamKey, this); return this; }
@Override public void onStreamAdded(Http2Stream stream) { // If the stream state is not open then the stream is not yet eligible for flow controlled frames and // only requires the ReducedFlowState. Otherwise the full amount of memory is required. stream.setProperty(stateKey, new FlowState(stream)); }
/** * Make {@code message} be the state associated with {@code stream}. * @param stream The stream which {@code message} is associated with. * @param message The message which contains the HTTP semantics. */ protected final void putMessage(Http2Stream stream, FullHttpMessage message) { FullHttpMessage previous = stream.setProperty(messageKey, message); if (previous != message && previous != null) { previous.release(); } }
@Override public void onStreamAdded(Http2Stream stream) { stream.setProperty(stateKey, new State(stream)); }
@Override public void onStreamAdded(final Http2Stream stream) { stream.setProperty(ApnsClientHandler.this.responsePromisePropertyKey, this.unattachedResponsePromisesByStreamId.remove(stream.id())); }
/** * Called after the super class has written the headers and created any associated stream objects. * @param compressor The compressor associated with the stream identified by {@code streamId}. * @param streamId The stream id for which the headers were written. */ private void bindCompressorToStream(EmbeddedChannel compressor, int streamId) { if (compressor != null) { Http2Stream stream = connection().stream(streamId); if (stream != null) { stream.setProperty(propertyKey, compressor); } } }
DefaultHttp2FrameStream setStreamAndProperty(PropertyKey streamKey, Http2Stream stream) { assert id == -1 || stream.id() == id; this.stream = stream; stream.setProperty(streamKey, this); return this; }
@Override public void onHeadersRead(final ChannelHandlerContext context, final int streamId, final Http2Headers headers, final int padding, final boolean endOfStream) { log.trace("Received headers from APNs gateway on stream {}: {}", streamId, headers); final Http2Stream stream = this.connection().stream(streamId); if (endOfStream) { this.handleEndOfStream(context, stream, headers, null); } else { stream.setProperty(this.responseHeadersPropertyKey, headers); } }
@Override public void onHeadersRead(final ChannelHandlerContext context, final int streamId, final Http2Headers headers, final int padding, final boolean endOfStream) { final Http2Stream stream = this.connection().stream(streamId); stream.setProperty(this.headersPropertyKey, headers); if (endOfStream) { this.handleEndOfStream(context, stream); } }
@Override public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endOfStream) { /** * https://http2.github.io/http2-spec/#rfc.section.5.1.1 second paragraph * only when in upgrade h2c mode, 0x01 cannot be selected as a new stream identifier. * some gateway or proxy product, use 0x01 as first normal request's stream id when * in prior knowleadge mode. */ if (this.isUpgradeH2cMode && streamId > 1 || !this.isUpgradeH2cMode && streamId > 0) { // 正常的请求(streamId==1 的是settings请求) if (endOfStream) { // 没有DATA帧的请求,可能是DATA handleRequest(ctx, streamId, headers, null); } else { // 缓存起来 connection().stream(streamId).setProperty(headerKey, headers); } } }
@Override public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endOfStream) { /** * https://http2.github.io/http2-spec/#rfc.section.5.1.1 second paragraph * only when in upgrade h2c mode, 0x01 cannot be selected as a new stream identifier. * some gateway or proxy product, use 0x01 as first normal request's stream id when * in prior knowleadge mode. */ if (this.isUpgradeH2cMode && streamId > 1 || !this.isUpgradeH2cMode && streamId > 0) { // 正常的请求(streamId==1 的是settings请求) if (endOfStream) { // 没有DATA帧的请求,可能是DATA handleRequest(ctx, streamId, headers, null); } else { // 缓存起来 connection().stream(streamId).setProperty(headerKey, headers); } } }
@Override protected void onStreamError(final ChannelHandlerContext context, final boolean isOutbound, final Throwable cause, final Http2Exception.StreamException streamException) { final Http2Stream stream = this.connection().stream(streamException.streamId()); stream.setProperty(this.streamErrorCausePropertyKey, streamException); super.onStreamError(context, isOutbound, cause, streamException); }
@Override public int onDataRead(final ChannelHandlerContext context, final int streamId, final ByteBuf data, final int padding, final boolean endOfStream) { final int bytesProcessed = data.readableBytes() + padding; final Http2Stream stream = this.connection().stream(streamId); if (stream.getProperty(this.payloadPropertyKey) == null) { stream.setProperty(this.payloadPropertyKey, data.alloc().heapBuffer(MAX_CONTENT_LENGTH)); } ((ByteBuf) stream.getProperty(this.payloadPropertyKey)).writeBytes(data); if (endOfStream) { this.handleEndOfStream(context, stream); } return bytesProcessed; }
@Override public void onStreamClosed(Http2Stream stream) { try { // When a stream is closed, consume any remaining bytes so that they // are restored to the connection window. FlowState state = state(stream); int unconsumedBytes = state.unconsumedBytes(); if (ctx != null && unconsumedBytes > 0) { connectionState().consumeBytes(unconsumedBytes); state.consumeBytes(unconsumedBytes); } } catch (Http2Exception e) { PlatformDependent.throwException(e); } finally { // Unconditionally reduce the amount of memory required for flow control because there is no // object allocation costs associated with doing so and the stream will not have any more // local flow control state to keep track of anymore. stream.setProperty(stateKey, REDUCED_FLOW_STATE); } } });
public UniformStreamByteDistributor(Http2Connection connection) { // Add a state for the connection. stateKey = connection.newKey(); Http2Stream connectionStream = connection.connectionStream(); connectionStream.setProperty(stateKey, new State(connectionStream)); // Register for notification of new streams. connection.addListener(new Http2ConnectionAdapter() { @Override public void onStreamAdded(Http2Stream stream) { stream.setProperty(stateKey, new State(stream)); } @Override public void onStreamClosed(Http2Stream stream) { state(stream).close(); } }); }
stream.setProperty(upgradeKey, true); InboundHttpToHttp2Adapter.handle( ctx, connection(), decoder().frameListener(), upgrade.upgradeRequest().retain());
stream.setProperty(upgradeKey, true); InboundHttpToHttp2Adapter.handle( ctx, connection(), decoder().frameListener(), upgrade.upgradeRequest().retain());