Fix inspector warnings
- Move the methods used by an inner class to the inner class - Removal of various redundant things (throws, parens, ..)
This commit is contained in:
parent
750f023ced
commit
66d8d8219a
@ -15,22 +15,6 @@
|
|||||||
|
|
||||||
package io.netty.handler.codec.http2;
|
package io.netty.handler.codec.http2;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http2.Http2CodecUtil.CONNECTION_STREAM_ID;
|
|
||||||
import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_PRIORITY_WEIGHT;
|
|
||||||
import static io.netty.handler.codec.http2.Http2CodecUtil.HTTP_UPGRADE_STREAM_ID;
|
|
||||||
import static io.netty.handler.codec.http2.Http2CodecUtil.connectionPrefaceBuf;
|
|
||||||
import static io.netty.handler.codec.http2.Http2CodecUtil.toByteBuf;
|
|
||||||
import static io.netty.handler.codec.http2.Http2CodecUtil.toHttp2Exception;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Error.NO_ERROR;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Error.PROTOCOL_ERROR;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Error.STREAM_CLOSED;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Exception.protocolError;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Stream.State.CLOSED;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Stream.State.HALF_CLOSED_LOCAL;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Stream.State.HALF_CLOSED_REMOTE;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Stream.State.OPEN;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Stream.State.RESERVED_LOCAL;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Stream.State.RESERVED_REMOTE;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
@ -40,9 +24,14 @@ import io.netty.handler.codec.ByteToMessageDecoder;
|
|||||||
|
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static io.netty.handler.codec.http2.Http2CodecUtil.*;
|
||||||
|
import static io.netty.handler.codec.http2.Http2Error.*;
|
||||||
|
import static io.netty.handler.codec.http2.Http2Exception.*;
|
||||||
|
import static io.netty.handler.codec.http2.Http2Stream.State.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract base class for a handler of HTTP/2 frames. Handles reading and writing of HTTP/2 frames
|
* Abstract base class for a handler of HTTP/2 frames. Handles reading and writing of HTTP/2 frames
|
||||||
* as well as management of connection state and flow control for both inbound and outbound data
|
* as well as management of connection state and flow control for both inbound and outbound data
|
||||||
@ -127,8 +116,8 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a local stream used for the HTTP cleartext upgrade.
|
// Create a local stream used for the HTTP cleartext upgrade.
|
||||||
createLocalStream(HTTP_UPGRADE_STREAM_ID, true, CONNECTION_STREAM_ID,
|
createLocalStream(HTTP_UPGRADE_STREAM_ID, true
|
||||||
DEFAULT_PRIORITY_WEIGHT, false);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -149,8 +138,8 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode
|
|||||||
applyRemoteSettings(settings);
|
applyRemoteSettings(settings);
|
||||||
|
|
||||||
// Create a stream in the half-closed state.
|
// Create a stream in the half-closed state.
|
||||||
createRemoteStream(HTTP_UPGRADE_STREAM_ID, true, CONNECTION_STREAM_ID,
|
createRemoteStream(HTTP_UPGRADE_STREAM_ID, true
|
||||||
DEFAULT_PRIORITY_WEIGHT, false);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -189,8 +178,9 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode
|
|||||||
@Override
|
@Override
|
||||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||||
ChannelFuture future = ctx.newSucceededFuture();
|
ChannelFuture future = ctx.newSucceededFuture();
|
||||||
for (Http2Stream stream : connection.activeStreams().toArray(new Http2Stream[0])) {
|
final Collection<Http2Stream> streams = connection.activeStreams();
|
||||||
close(stream, future);
|
for (Http2Stream s : streams.toArray(new Http2Stream[streams.size()])) {
|
||||||
|
close(s, future);
|
||||||
}
|
}
|
||||||
super.channelInactive(ctx);
|
super.channelInactive(ctx);
|
||||||
}
|
}
|
||||||
@ -239,7 +229,7 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers,
|
public final void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers,
|
||||||
int padding, boolean endStream, boolean endSegment) throws Http2Exception {
|
int padding, boolean endStream, boolean endSegment) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -392,7 +382,7 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode
|
|||||||
Http2Stream stream = connection.stream(streamId);
|
Http2Stream stream = connection.stream(streamId);
|
||||||
if (stream == null) {
|
if (stream == null) {
|
||||||
// Create a new locally-initiated stream.
|
// Create a new locally-initiated stream.
|
||||||
stream = createLocalStream(streamId, endStream, streamDependency, weight, exclusive);
|
createLocalStream(streamId, endStream);
|
||||||
} else {
|
} else {
|
||||||
// An existing stream...
|
// An existing stream...
|
||||||
if (stream.state() == RESERVED_LOCAL) {
|
if (stream.state() == RESERVED_LOCAL) {
|
||||||
@ -533,7 +523,8 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes the given exception. Depending on the type of exception, delegates to either
|
* Processes the given exception. Depending on the type of exception, delegates to either
|
||||||
* {@link #processConnectionError} or {@link #processStreamError}.
|
* {@link #onConnectionError(ChannelHandlerContext, Http2Exception)} or
|
||||||
|
* {@link #onStreamError(ChannelHandlerContext, Http2StreamException)}.
|
||||||
*/
|
*/
|
||||||
protected final void onHttp2Exception(ChannelHandlerContext ctx, Http2Exception e) {
|
protected final void onHttp2Exception(ChannelHandlerContext ctx, Http2Exception e) {
|
||||||
if (e instanceof Http2StreamException) {
|
if (e instanceof Http2StreamException) {
|
||||||
@ -693,26 +684,6 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Closes the remote side of the given stream. If this causes the stream to be closed, adds a
|
|
||||||
* hook to close the channel after the given future completes.
|
|
||||||
*
|
|
||||||
* @param stream the stream to be half closed.
|
|
||||||
* @param future If closing, the future after which to close the channel. If {@code null},
|
|
||||||
* ignored.
|
|
||||||
*/
|
|
||||||
private void closeRemoteSide(Http2Stream stream, ChannelFuture future) {
|
|
||||||
switch (stream.state()) {
|
|
||||||
case HALF_CLOSED_REMOTE:
|
|
||||||
case OPEN:
|
|
||||||
stream.closeRemoteSide();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
close(stream, future);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the given stream and adds a hook to close the channel after the given future completes.
|
* Closes the given stream and adds a hook to close the channel after the given future completes.
|
||||||
*
|
*
|
||||||
@ -729,19 +700,10 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the HTTP/2 connection preface has been received from the remote endpoint.
|
|
||||||
*/
|
|
||||||
private void verifyPrefaceReceived() throws Http2Exception {
|
|
||||||
if (!prefaceReceived) {
|
|
||||||
throw protocolError("Received non-SETTINGS as first frame.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the HTTP/2 connection preface upon establishment of the connection, if not already sent.
|
* Sends the HTTP/2 connection preface upon establishment of the connection, if not already sent.
|
||||||
*/
|
*/
|
||||||
private void sendPreface(final ChannelHandlerContext ctx) throws Http2Exception {
|
private void sendPreface(final ChannelHandlerContext ctx) {
|
||||||
if (prefaceSent || !ctx.channel().isActive()) {
|
if (prefaceSent || !ctx.channel().isActive()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -760,34 +722,6 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode
|
|||||||
ChannelFutureListener.CLOSE_ON_FAILURE);
|
ChannelFutureListener.CLOSE_ON_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Applies settings sent from the local endpoint.
|
|
||||||
*/
|
|
||||||
private void applyLocalSettings(Http2Settings settings) throws Http2Exception {
|
|
||||||
if (settings.hasPushEnabled()) {
|
|
||||||
if (connection.isServer()) {
|
|
||||||
throw protocolError("Server sending SETTINGS frame with ENABLE_PUSH specified");
|
|
||||||
}
|
|
||||||
connection.local().allowPushTo(settings.pushEnabled());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settings.hasAllowCompressedData()) {
|
|
||||||
connection.local().allowCompressedData(settings.allowCompressedData());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settings.hasMaxConcurrentStreams()) {
|
|
||||||
connection.remote().maxStreams(settings.maxConcurrentStreams());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settings.hasMaxHeaderTableSize()) {
|
|
||||||
frameReader.maxHeaderTableSize(settings.maxHeaderTableSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settings.hasInitialWindowSize()) {
|
|
||||||
inboundFlow.initialInboundWindowSize(settings.initialWindowSize());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies settings received from the remote endpoint.
|
* Applies settings received from the remote endpoint.
|
||||||
*/
|
*/
|
||||||
@ -819,16 +753,14 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode
|
|||||||
/**
|
/**
|
||||||
* Creates a new stream initiated by the local endpoint.
|
* Creates a new stream initiated by the local endpoint.
|
||||||
*/
|
*/
|
||||||
private Http2Stream createLocalStream(int streamId, boolean halfClosed, int streamDependency,
|
private Http2Stream createLocalStream(int streamId, boolean halfClosed) throws Http2Exception {
|
||||||
short weight, boolean exclusive) throws Http2Exception {
|
|
||||||
return connection.local().createStream(streamId, halfClosed);
|
return connection.local().createStream(streamId, halfClosed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new stream initiated by the remote endpoint.
|
* Creates a new stream initiated by the remote endpoint.
|
||||||
*/
|
*/
|
||||||
private Http2Stream createRemoteStream(int streamId, boolean halfClosed, int streamDependency,
|
private Http2Stream createRemoteStream(int streamId, boolean halfClosed) throws Http2Exception {
|
||||||
short weight, boolean exclusive) throws Http2Exception {
|
|
||||||
return connection.remote().createStream(streamId, halfClosed);
|
return connection.remote().createStream(streamId, halfClosed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -855,8 +787,7 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode
|
|||||||
compressed, new Http2InboundFlowController.FrameWriter() {
|
compressed, new Http2InboundFlowController.FrameWriter() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeFrame(int streamId, int windowSizeIncrement)
|
public void writeFrame(int streamId, int windowSizeIncrement) {
|
||||||
throws Http2Exception {
|
|
||||||
frameWriter.writeWindowUpdate(ctx, ctx.newPromise(), streamId,
|
frameWriter.writeWindowUpdate(ctx, ctx.newPromise(), streamId,
|
||||||
windowSizeIncrement);
|
windowSizeIncrement);
|
||||||
}
|
}
|
||||||
@ -877,6 +808,35 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode
|
|||||||
endOfSegment, compressed);
|
endOfSegment, compressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies that the HTTP/2 connection preface has been received from the remote endpoint.
|
||||||
|
*/
|
||||||
|
private void verifyPrefaceReceived() throws Http2Exception {
|
||||||
|
if (!prefaceReceived) {
|
||||||
|
throw protocolError("Received non-SETTINGS as first frame.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the remote side of the given stream. If this causes the stream to be closed, adds a
|
||||||
|
* hook to close the channel after the given future completes.
|
||||||
|
*
|
||||||
|
* @param stream the stream to be half closed.
|
||||||
|
* @param future If closing, the future after which to close the channel. If {@code null},
|
||||||
|
* ignored.
|
||||||
|
*/
|
||||||
|
private void closeRemoteSide(Http2Stream stream, ChannelFuture future) {
|
||||||
|
switch (stream.state()) {
|
||||||
|
case HALF_CLOSED_REMOTE:
|
||||||
|
case OPEN:
|
||||||
|
stream.closeRemoteSide();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
close(stream, future);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers,
|
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers,
|
||||||
int padding, boolean endStream, boolean endSegment) throws Http2Exception {
|
int padding, boolean endStream, boolean endSegment) throws Http2Exception {
|
||||||
@ -893,13 +853,13 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode
|
|||||||
Http2Stream stream = connection.stream(streamId);
|
Http2Stream stream = connection.stream(streamId);
|
||||||
verifyGoAwayNotReceived();
|
verifyGoAwayNotReceived();
|
||||||
verifyRstStreamNotReceived(stream);
|
verifyRstStreamNotReceived(stream);
|
||||||
if (connection.remote().isGoAwayReceived() || (stream != null && shouldIgnoreFrame(stream))) {
|
if (connection.remote().isGoAwayReceived() || stream != null && shouldIgnoreFrame(stream)) {
|
||||||
// Ignore this frame.
|
// Ignore this frame.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stream == null) {
|
if (stream == null) {
|
||||||
createRemoteStream(streamId, endStream, streamDependency, weight, exclusive);
|
createRemoteStream(streamId, endStream);
|
||||||
} else {
|
} else {
|
||||||
if (stream.state() == RESERVED_REMOTE) {
|
if (stream.state() == RESERVED_REMOTE) {
|
||||||
// Received headers for a reserved push stream ... open it for push to the
|
// Received headers for a reserved push stream ... open it for push to the
|
||||||
@ -979,6 +939,34 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode
|
|||||||
AbstractHttp2ConnectionHandler.this.onSettingsAckRead(ctx);
|
AbstractHttp2ConnectionHandler.this.onSettingsAckRead(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies settings sent from the local endpoint.
|
||||||
|
*/
|
||||||
|
private void applyLocalSettings(Http2Settings settings) throws Http2Exception {
|
||||||
|
if (settings.hasPushEnabled()) {
|
||||||
|
if (connection.isServer()) {
|
||||||
|
throw protocolError("Server sending SETTINGS frame with ENABLE_PUSH specified");
|
||||||
|
}
|
||||||
|
connection.local().allowPushTo(settings.pushEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.hasAllowCompressedData()) {
|
||||||
|
connection.local().allowCompressedData(settings.allowCompressedData());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.hasMaxConcurrentStreams()) {
|
||||||
|
connection.remote().maxStreams(settings.maxConcurrentStreams());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.hasMaxHeaderTableSize()) {
|
||||||
|
frameReader.maxHeaderTableSize(settings.maxHeaderTableSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.hasInitialWindowSize()) {
|
||||||
|
inboundFlow.initialInboundWindowSize(settings.initialWindowSize());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings)
|
public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings)
|
||||||
throws Http2Exception {
|
throws Http2Exception {
|
||||||
@ -1138,8 +1126,8 @@ public abstract class AbstractHttp2ConnectionHandler extends ByteToMessageDecode
|
|||||||
FlowControlWriter(ChannelHandlerContext ctx, ByteBuf data, ChannelPromise promise) {
|
FlowControlWriter(ChannelHandlerContext ctx, ByteBuf data, ChannelPromise promise) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
this.promise = promise;
|
this.promise = promise;
|
||||||
promises = new ArrayList<ChannelPromise>(
|
promises = new ArrayList<ChannelPromise>(4);
|
||||||
Arrays.asList(promise));
|
promises.add(promise);
|
||||||
remaining = data.readableBytes();
|
remaining = data.readableBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,31 +15,22 @@
|
|||||||
|
|
||||||
package io.netty.handler.codec.http2;
|
package io.netty.handler.codec.http2;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http2.Http2CodecUtil.CONNECTION_STREAM_ID;
|
|
||||||
import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_PRIORITY_WEIGHT;
|
|
||||||
import static io.netty.handler.codec.http2.Http2CodecUtil.MAX_WEIGHT;
|
|
||||||
import static io.netty.handler.codec.http2.Http2CodecUtil.MIN_WEIGHT;
|
|
||||||
import static io.netty.handler.codec.http2.Http2CodecUtil.immediateRemovalPolicy;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Exception.format;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Exception.protocolError;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Stream.State.CLOSED;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Stream.State.HALF_CLOSED_LOCAL;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Stream.State.HALF_CLOSED_REMOTE;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Stream.State.IDLE;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Stream.State.OPEN;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Stream.State.RESERVED_LOCAL;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Stream.State.RESERVED_REMOTE;
|
|
||||||
import io.netty.handler.codec.http2.Http2StreamRemovalPolicy.Action;
|
import io.netty.handler.codec.http2.Http2StreamRemovalPolicy.Action;
|
||||||
import io.netty.util.collection.PrimitiveCollections;
|
|
||||||
import io.netty.util.collection.IntObjectHashMap;
|
import io.netty.util.collection.IntObjectHashMap;
|
||||||
import io.netty.util.collection.IntObjectMap;
|
import io.netty.util.collection.IntObjectMap;
|
||||||
|
import io.netty.util.collection.PrimitiveCollections;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static io.netty.handler.codec.http2.Http2CodecUtil.*;
|
||||||
|
import static io.netty.handler.codec.http2.Http2Exception.*;
|
||||||
|
import static io.netty.handler.codec.http2.Http2Stream.State.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple implementation of {@link Http2Connection}.
|
* Simple implementation of {@link Http2Connection}.
|
||||||
*/
|
*/
|
||||||
@ -141,7 +132,7 @@ public class DefaultHttp2Connection implements Http2Connection {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Http2Stream> activeStreams() {
|
public Set<Http2Stream> activeStreams() {
|
||||||
return java.util.Collections.unmodifiableSet(activeStreams);
|
return Collections.unmodifiableSet(activeStreams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -159,17 +150,6 @@ public class DefaultHttp2Connection implements Http2Connection {
|
|||||||
return localEndpoint.isGoAwayReceived() || remoteEndpoint.isGoAwayReceived();
|
return localEndpoint.isGoAwayReceived() || remoteEndpoint.isGoAwayReceived();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addStream(DefaultStream stream) {
|
|
||||||
// Add the stream to the map and priority tree.
|
|
||||||
streamMap.put(stream.id(), stream);
|
|
||||||
connectionStream.addChild(stream, false);
|
|
||||||
|
|
||||||
// Notify the observers of the event.
|
|
||||||
for (Listener listener : listeners) {
|
|
||||||
listener.streamAdded(stream);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeStream(DefaultStream stream) {
|
private void removeStream(DefaultStream stream) {
|
||||||
// Notify the observers of the event first.
|
// Notify the observers of the event first.
|
||||||
for (Listener listener : listeners) {
|
for (Listener listener : listeners) {
|
||||||
@ -193,42 +173,6 @@ public class DefaultHttp2Connection implements Http2Connection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deactivate(DefaultStream stream) {
|
|
||||||
activeStreams.remove(stream);
|
|
||||||
|
|
||||||
// Update the number of active streams initiated by the endpoint.
|
|
||||||
stream.createdBy().numActiveStreams--;
|
|
||||||
|
|
||||||
// Notify the listeners.
|
|
||||||
for (Listener listener : listeners) {
|
|
||||||
listener.streamInactive(stream);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void notifyGoingAway() {
|
|
||||||
for (Listener listener : listeners) {
|
|
||||||
listener.goingAway();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void notifyHalfClosed(Http2Stream stream) {
|
|
||||||
for (Listener listener : listeners) {
|
|
||||||
listener.streamHalfClosed(stream);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void notifyPriorityChanged(Http2Stream stream, Http2Stream previousParent) {
|
|
||||||
for (Listener listener : listeners) {
|
|
||||||
listener.streamPriorityChanged(stream, previousParent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void notifyPrioritySubtreeChanged(Http2Stream stream, Http2Stream subtreeRoot) {
|
|
||||||
for (Listener listener : listeners) {
|
|
||||||
listener.streamPrioritySubtreeChanged(stream, subtreeRoot);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple stream implementation. Streams can be compared to each other by priority.
|
* Simple stream implementation. Streams can be compared to each other by priority.
|
||||||
*/
|
*/
|
||||||
@ -422,6 +366,18 @@ public class DefaultHttp2Connection implements Http2Connection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void notifyPriorityChanged(Http2Stream stream, Http2Stream previousParent) {
|
||||||
|
for (Listener listener : listeners) {
|
||||||
|
listener.streamPriorityChanged(stream, previousParent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void notifyPrioritySubtreeChanged(Http2Stream stream, Http2Stream subtreeRoot) {
|
||||||
|
for (Listener listener : listeners) {
|
||||||
|
listener.streamPrioritySubtreeChanged(stream, subtreeRoot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Http2Stream verifyState(Http2Error error, State... allowedStates)
|
public Http2Stream verifyState(Http2Error error, State... allowedStates)
|
||||||
throws Http2Exception {
|
throws Http2Exception {
|
||||||
@ -463,6 +419,18 @@ public class DefaultHttp2Connection implements Http2Connection {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void deactivate(DefaultStream stream) {
|
||||||
|
activeStreams.remove(stream);
|
||||||
|
|
||||||
|
// Update the number of active streams initiated by the endpoint.
|
||||||
|
stream.createdBy().numActiveStreams--;
|
||||||
|
|
||||||
|
// Notify the listeners.
|
||||||
|
for (Listener listener : listeners) {
|
||||||
|
listener.streamInactive(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Http2Stream closeLocalSide() {
|
public Http2Stream closeLocalSide() {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
@ -495,6 +463,12 @@ public class DefaultHttp2Connection implements Http2Connection {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void notifyHalfClosed(Http2Stream stream) {
|
||||||
|
for (Listener listener : listeners) {
|
||||||
|
listener.streamHalfClosed(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean remoteSideOpen() {
|
public final boolean remoteSideOpen() {
|
||||||
return state == HALF_CLOSED_LOCAL || state == OPEN || state == RESERVED_REMOTE;
|
return state == HALF_CLOSED_LOCAL || state == OPEN || state == RESERVED_REMOTE;
|
||||||
@ -575,7 +549,7 @@ public class DefaultHttp2Connection implements Http2Connection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> IntObjectMap<DefaultStream> newChildMap() {
|
private static IntObjectMap<DefaultStream> newChildMap() {
|
||||||
return new IntObjectHashMap<DefaultStream>(4);
|
return new IntObjectHashMap<DefaultStream>(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -583,24 +557,22 @@ public class DefaultHttp2Connection implements Http2Connection {
|
|||||||
* Stream class representing the connection, itself.
|
* Stream class representing the connection, itself.
|
||||||
*/
|
*/
|
||||||
private final class ConnectionStream extends DefaultStream {
|
private final class ConnectionStream extends DefaultStream {
|
||||||
public ConnectionStream() {
|
private ConnectionStream() {
|
||||||
super(CONNECTION_STREAM_ID);
|
super(CONNECTION_STREAM_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Http2Stream setPriority(int parentStreamId, short weight, boolean exclusive)
|
public Http2Stream setPriority(int parentStreamId, short weight, boolean exclusive) {
|
||||||
throws Http2Exception {
|
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Http2Stream verifyState(Http2Error error, State... allowedStates)
|
public Http2Stream verifyState(Http2Error error, State... allowedStates) {
|
||||||
throws Http2Exception {
|
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Http2Stream openForPush() throws Http2Exception {
|
public Http2Stream openForPush() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -727,6 +699,17 @@ public class DefaultHttp2Connection implements Http2Connection {
|
|||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addStream(DefaultStream stream) {
|
||||||
|
// Add the stream to the map and priority tree.
|
||||||
|
streamMap.put(stream.id(), stream);
|
||||||
|
connectionStream.addChild(stream, false);
|
||||||
|
|
||||||
|
// Notify the observers of the event.
|
||||||
|
for (Listener listener : listeners) {
|
||||||
|
listener.streamAdded(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void allowPushTo(boolean allow) {
|
public void allowPushTo(boolean allow) {
|
||||||
if (allow && server) {
|
if (allow && server) {
|
||||||
@ -789,6 +772,12 @@ public class DefaultHttp2Connection implements Http2Connection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void notifyGoingAway() {
|
||||||
|
for (Listener listener : listeners) {
|
||||||
|
listener.goingAway();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Endpoint opposite() {
|
public Endpoint opposite() {
|
||||||
return isLocal() ? remoteEndpoint : localEndpoint;
|
return isLocal() ? remoteEndpoint : localEndpoint;
|
||||||
|
@ -15,14 +15,6 @@
|
|||||||
|
|
||||||
package io.netty.handler.codec.http2;
|
package io.netty.handler.codec.http2;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http2.Http2CodecUtil.CONNECTION_STREAM_ID;
|
|
||||||
import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_FLOW_CONTROL_WINDOW_SIZE;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Error.FLOW_CONTROL_ERROR;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Error.STREAM_CLOSED;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Exception.format;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Exception.protocolError;
|
|
||||||
import static java.lang.Math.max;
|
|
||||||
import static java.lang.Math.min;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
@ -32,6 +24,11 @@ import java.util.Comparator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
|
import static io.netty.handler.codec.http2.Http2CodecUtil.*;
|
||||||
|
import static io.netty.handler.codec.http2.Http2Error.*;
|
||||||
|
import static io.netty.handler.codec.http2.Http2Exception.*;
|
||||||
|
import static java.lang.Math.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic implementation of {@link Http2OutboundFlowController}.
|
* Basic implementation of {@link Http2OutboundFlowController}.
|
||||||
*/
|
*/
|
||||||
@ -55,7 +52,7 @@ public class DefaultHttp2OutboundFlowController implements Http2OutboundFlowCont
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Scale the data by the weight.
|
// Scale the data by the weight.
|
||||||
return (o1Data * o1.weight()) - (o2Data * o2.weight());
|
return o1Data * o1.weight() - o2Data * o2.weight();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -247,10 +244,7 @@ public class DefaultHttp2OutboundFlowController implements Http2OutboundFlowCont
|
|||||||
* Recursively traverses the priority tree rooted at the given node. Attempts to write the
|
* Recursively traverses the priority tree rooted at the given node. Attempts to write the
|
||||||
* allowed bytes for the streams in this sub tree based on their weighted priorities.
|
* allowed bytes for the streams in this sub tree based on their weighted priorities.
|
||||||
*
|
*
|
||||||
* @param priority the sub tree to write to. On the first invocation, this will be the root of
|
* @param allowance an allowed number of bytes that may be written to the streams in this subtree
|
||||||
* the priority tree (i.e. the connection node).
|
|
||||||
* @param allowance an allowed number of bytes that may be written to the streams in this sub
|
|
||||||
* tree.
|
|
||||||
*/
|
*/
|
||||||
private void writeAllowedBytes(Http2Stream stream, int allowance) throws Http2Exception {
|
private void writeAllowedBytes(Http2Stream stream, int allowance) throws Http2Exception {
|
||||||
// Write the allowed bytes for this node. If not all of the allowance was used,
|
// Write the allowed bytes for this node. If not all of the allowance was used,
|
||||||
@ -388,7 +382,7 @@ public class DefaultHttp2OutboundFlowController implements Http2OutboundFlowCont
|
|||||||
* value.
|
* value.
|
||||||
*/
|
*/
|
||||||
int incrementStreamWindow(int delta) throws Http2Exception {
|
int incrementStreamWindow(int delta) throws Http2Exception {
|
||||||
if (delta > 0 && (Integer.MAX_VALUE - delta) < window) {
|
if (delta > 0 && Integer.MAX_VALUE - delta < window) {
|
||||||
throw new Http2StreamException(stream.id(), FLOW_CONTROL_ERROR,
|
throw new Http2StreamException(stream.id(), FLOW_CONTROL_ERROR,
|
||||||
"Window size overflow for stream: " + stream.id());
|
"Window size overflow for stream: " + stream.id());
|
||||||
}
|
}
|
||||||
@ -520,19 +514,6 @@ public class DefaultHttp2OutboundFlowController implements Http2OutboundFlowCont
|
|||||||
return bytesWritten;
|
return bytesWritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Increments the number of pending bytes for this node. If there was any change to the
|
|
||||||
* number of bytes that fit into the stream window, then {@link #incrementPriorityBytes} to
|
|
||||||
* recursively update this branch of the priority tree.
|
|
||||||
*/
|
|
||||||
private void incrementPendingBytes(int numBytes) {
|
|
||||||
int previouslyStreamable = streamableBytes();
|
|
||||||
pendingBytes += numBytes;
|
|
||||||
|
|
||||||
int delta = streamableBytes() - previouslyStreamable;
|
|
||||||
incrementPriorityBytes(delta);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively increments the priority bytes for this branch in the priority tree starting
|
* Recursively increments the priority bytes for this branch in the priority tree starting
|
||||||
* at the current node.
|
* at the current node.
|
||||||
@ -582,6 +563,19 @@ public class DefaultHttp2OutboundFlowController implements Http2OutboundFlowCont
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increments the number of pending bytes for this node. If there was any change to the
|
||||||
|
* number of bytes that fit into the stream window, then {@link #incrementPriorityBytes} to
|
||||||
|
* recursively update this branch of the priority tree.
|
||||||
|
*/
|
||||||
|
private void incrementPendingBytes(int numBytes) {
|
||||||
|
int previouslyStreamable = streamableBytes();
|
||||||
|
pendingBytes += numBytes;
|
||||||
|
|
||||||
|
int delta = streamableBytes() - previouslyStreamable;
|
||||||
|
incrementPriorityBytes(delta);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the frame and decrements the stream and connection window sizes. If the frame
|
* Writes the frame and decrements the stream and connection window sizes. If the frame
|
||||||
* is in the pending queue, the written bytes are removed from this branch of the
|
* is in the pending queue, the written bytes are removed from this branch of the
|
||||||
|
Loading…
Reference in New Issue
Block a user