Package io.netty.handler.codec.http2
Class DefaultHttp2Connection.DefaultEndpoint<F extends Http2FlowController>
java.lang.Object
io.netty.handler.codec.http2.DefaultHttp2Connection.DefaultEndpoint<F>
- All Implemented Interfaces:
Http2Connection.Endpoint<F>
- Enclosing class:
DefaultHttp2Connection
private final class DefaultHttp2Connection.DefaultEndpoint<F extends Http2FlowController>
extends Object
implements Http2Connection.Endpoint<F>
Simple endpoint implementation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate F
private long
This is an always increasing sequence number used to hashDefaultHttp2Connection.DefaultStream
instances.private int
private int
private final int
private int
private int
Used for reservation of stream IDs.private int
The minimum stream ID allowed when creating the next stream.(package private) int
(package private) int
private boolean
private final boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
boolean
This is the SETTINGS_ENABLE_PUSH value sent from the opposite endpoint.void
allowPushTo
(boolean allow) This is the SETTINGS_ENABLE_PUSH value sent from the opposite endpoint.boolean
Indicates whether or a stream created by this endpoint can be opened without violatingHttp2Connection.Endpoint.maxActiveStreams()
.private void
checkNewStreamAllowed
(int streamId, Http2Stream.State state) boolean
created
(Http2Stream stream) Indicates whether or not this endpoint created the given stream.createStream
(int streamId, boolean halfClosed) Creates a stream initiated by this endpoint.Gets the flow controller for this endpoint.void
flowController
(F flowController) Sets the flow controller for this endpoint.int
Increment and get the next generated stream id this endpoint.private void
incrementExpectedStreamId
(int streamId) private boolean
isLocal()
boolean
isServer()
Indicates whether or not this endpoint is the server-side of the connection.boolean
isValidStreamId
(int streamId) Indicates whether the given streamId is from the set of IDs used by this endpoint to create new streams.int
Gets the ID of the stream last successfully created by this endpoint.int
If a GOAWAY was received for this endpoint, this will be the last stream ID from the GOAWAY frame.private void
lastStreamKnownByPeer
(int lastKnownStream) int
Gets the maximum number of streams (created by this endpoint) that are allowed to be active at the same time.void
maxActiveStreams
(int maxActiveStreams) Sets the limit forSETTINGS_MAX_CONCURRENT_STREAMS
.boolean
mayHaveCreatedStream
(int streamId) Indicates whether or not this endpoint may have created the given stream.int
Gets the number of active streams (i.e.Http2Connection.Endpoint
<? extends Http2FlowController> opposite()
Gets theHttp2Connection.Endpoint
opposite this one.reservePushStream
(int streamId, Http2Stream parent) Creates a push stream in the reserved state for this endpoint and notifies all listeners.private void
-
Field Details
-
server
private final boolean server -
lastCreatedStreamIdentity
private long lastCreatedStreamIdentityThis is an always increasing sequence number used to hashDefaultHttp2Connection.DefaultStream
instances. -
nextStreamIdToCreate
private int nextStreamIdToCreateThe minimum stream ID allowed when creating the next stream. This only applies at the time the stream is created. If the ID of the stream being created is less than this value, stream creation will fail. Upon successful creation of a stream, this value is incremented to the next valid stream ID. -
nextReservationStreamId
private int nextReservationStreamIdUsed for reservation of stream IDs. Stream IDs can be reserved in advance by applications before the streams are actually created. For example, applications may choose to buffer stream creation attempts as a way of working aroundSETTINGS_MAX_CONCURRENT_STREAMS
, in which case they will reserve stream IDs for each buffered stream. -
lastStreamKnownByPeer
private int lastStreamKnownByPeer -
pushToAllowed
private boolean pushToAllowed -
flowController
-
maxStreams
private int maxStreams -
maxActiveStreams
private int maxActiveStreams -
maxReservedStreams
private final int maxReservedStreams -
numActiveStreams
int numActiveStreams -
numStreams
int numStreams
-
-
Constructor Details
-
DefaultEndpoint
DefaultEndpoint(boolean server, int maxReservedStreams)
-
-
Method Details
-
incrementAndGetNextStreamId
public int incrementAndGetNextStreamId()Description copied from interface:Http2Connection.Endpoint
Increment and get the next generated stream id this endpoint. If negative, the stream IDs are exhausted for this endpoint an no further streams may be created.- Specified by:
incrementAndGetNextStreamId
in interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
incrementExpectedStreamId
private void incrementExpectedStreamId(int streamId) -
isValidStreamId
public boolean isValidStreamId(int streamId) Description copied from interface:Http2Connection.Endpoint
Indicates whether the given streamId is from the set of IDs used by this endpoint to create new streams.- Specified by:
isValidStreamId
in interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
mayHaveCreatedStream
public boolean mayHaveCreatedStream(int streamId) Description copied from interface:Http2Connection.Endpoint
Indicates whether or not this endpoint may have created the given stream. This istrue
ifHttp2Connection.Endpoint.isValidStreamId(int)
andstreamId
invalid input: '<'=Http2Connection.Endpoint.lastStreamCreated()
.- Specified by:
mayHaveCreatedStream
in interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
canOpenStream
public boolean canOpenStream()Description copied from interface:Http2Connection.Endpoint
Indicates whether or a stream created by this endpoint can be opened without violatingHttp2Connection.Endpoint.maxActiveStreams()
.- Specified by:
canOpenStream
in interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
createStream
public DefaultHttp2Connection.DefaultStream createStream(int streamId, boolean halfClosed) throws Http2Exception Description copied from interface:Http2Connection.Endpoint
Creates a stream initiated by this endpoint. This could fail for the following reasons:- The requested stream ID is not the next sequential ID for this endpoint.
- The stream already exists.
Http2Connection.Endpoint.canOpenStream()
isfalse
.- The connection is marked as going away.
The initial state of the stream will be immediately set before notifying
Http2Connection.Listener
s. The state transition is sensitive tohalfClosed
and is defined byHttp2Stream.open(boolean)
.- Specified by:
createStream
in interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
- Parameters:
streamId
- The ID of the streamhalfClosed
- seeHttp2Stream.open(boolean)
.- Throws:
Http2Exception
- See Also:
-
created
Description copied from interface:Http2Connection.Endpoint
Indicates whether or not this endpoint created the given stream.- Specified by:
created
in interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
isServer
public boolean isServer()Description copied from interface:Http2Connection.Endpoint
Indicates whether or not this endpoint is the server-side of the connection.- Specified by:
isServer
in interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
reservePushStream
public DefaultHttp2Connection.DefaultStream reservePushStream(int streamId, Http2Stream parent) throws Http2Exception Description copied from interface:Http2Connection.Endpoint
Creates a push stream in the reserved state for this endpoint and notifies all listeners. This could fail for the following reasons:- Server push is not allowed to the opposite endpoint.
- The requested stream ID is not the next sequential stream ID for this endpoint.
- The number of concurrent streams is above the allowed threshold for this endpoint.
- The connection is marked as going away.
- The parent stream ID does not exist or is not
OPEN
from the side sending the push promise. - Could not set a valid priority for the new stream.
- Specified by:
reservePushStream
in interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
- Parameters:
streamId
- the ID of the push streamparent
- the parent stream used to initiate the push stream.- Throws:
Http2Exception
-
addStream
-
allowPushTo
public void allowPushTo(boolean allow) Description copied from interface:Http2Connection.Endpoint
This is the SETTINGS_ENABLE_PUSH value sent from the opposite endpoint. This method should only be called by Netty (not users) as a result of a receiving aSETTINGS
frame.- Specified by:
allowPushTo
in interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
allowPushTo
public boolean allowPushTo()Description copied from interface:Http2Connection.Endpoint
This is the SETTINGS_ENABLE_PUSH value sent from the opposite endpoint. The initial value must betrue
for the client endpoint and always false for a server endpoint.- Specified by:
allowPushTo
in interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
numActiveStreams
public int numActiveStreams()Description copied from interface:Http2Connection.Endpoint
Gets the number of active streams (i.e.OPEN
orHALF CLOSED
) that were created by this endpoint.- Specified by:
numActiveStreams
in interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
maxActiveStreams
public int maxActiveStreams()Description copied from interface:Http2Connection.Endpoint
Gets the maximum number of streams (created by this endpoint) that are allowed to be active at the same time. This is the SETTINGS_MAX_CONCURRENT_STREAMS value sent from the opposite endpoint to restrict stream creation by this endpoint.The default value returned by this method must be "unlimited".
- Specified by:
maxActiveStreams
in interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
maxActiveStreams
public void maxActiveStreams(int maxActiveStreams) Description copied from interface:Http2Connection.Endpoint
Sets the limit forSETTINGS_MAX_CONCURRENT_STREAMS
.- Specified by:
maxActiveStreams
in interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
- Parameters:
maxActiveStreams
- The maximum number of streams (created by this endpoint) that are allowed to be active at once. This is the SETTINGS_MAX_CONCURRENT_STREAMS value sent from the opposite endpoint to restrict stream creation by this endpoint.
-
lastStreamCreated
public int lastStreamCreated()Description copied from interface:Http2Connection.Endpoint
Gets the ID of the stream last successfully created by this endpoint.- Specified by:
lastStreamCreated
in interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
lastStreamKnownByPeer
public int lastStreamKnownByPeer()Description copied from interface:Http2Connection.Endpoint
If a GOAWAY was received for this endpoint, this will be the last stream ID from the GOAWAY frame. Otherwise, this will be-1
.- Specified by:
lastStreamKnownByPeer
in interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
lastStreamKnownByPeer
private void lastStreamKnownByPeer(int lastKnownStream) -
flowController
Description copied from interface:Http2Connection.Endpoint
Gets the flow controller for this endpoint.- Specified by:
flowController
in interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
flowController
Description copied from interface:Http2Connection.Endpoint
Sets the flow controller for this endpoint.- Specified by:
flowController
in interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
opposite
Description copied from interface:Http2Connection.Endpoint
Gets theHttp2Connection.Endpoint
opposite this one.- Specified by:
opposite
in interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
updateMaxStreams
private void updateMaxStreams() -
checkNewStreamAllowed
- Throws:
Http2Exception
-
isLocal
private boolean isLocal()
-