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 java.lang.Object implements Http2Connection.Endpoint<F>
Simple endpoint implementation.
-
-
Field Summary
Fields Modifier and Type Field Description private FflowControllerprivate intlastStreamKnownByPeerprivate intmaxActiveStreamsprivate intmaxReservedStreamsprivate intmaxStreamsprivate intnextReservationStreamIdUsed for reservation of stream IDs.private intnextStreamIdToCreateThe minimum stream ID allowed when creating the next stream.(package private) intnumActiveStreams(package private) intnumStreamsprivate booleanpushToAllowedprivate booleanserver
-
Constructor Summary
Constructors Constructor Description DefaultEndpoint(boolean server, int maxReservedStreams)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddStream(DefaultHttp2Connection.DefaultStream stream)booleanallowPushTo()This is the SETTINGS_ENABLE_PUSH value sent from the opposite endpoint.voidallowPushTo(boolean allow)This is the SETTINGS_ENABLE_PUSH value sent from the opposite endpoint.booleancanOpenStream()Indicates whether or a stream created by this endpoint can be opened without violatingHttp2Connection.Endpoint.maxActiveStreams().private voidcheckNewStreamAllowed(int streamId, Http2Stream.State state)booleancreated(Http2Stream stream)Indicates whether or not this endpoint created the given stream.DefaultHttp2Connection.DefaultStreamcreateStream(int streamId, boolean halfClosed)Creates a stream initiated by this endpoint.FflowController()Gets the flow controller for this endpoint.voidflowController(F flowController)Sets the flow controller for this endpoint.intincrementAndGetNextStreamId()Increment and get the next generated stream id this endpoint.private voidincrementExpectedStreamId(int streamId)private booleanisLocal()booleanisServer()Indicates whether or not this endpoint is the server-side of the connection.booleanisValidStreamId(int streamId)Indicates whether the given streamId is from the set of IDs used by this endpoint to create new streams.intlastStreamCreated()Gets the ID of the stream last successfully created by this endpoint.intlastStreamKnownByPeer()If a GOAWAY was received for this endpoint, this will be the last stream ID from the GOAWAY frame.private voidlastStreamKnownByPeer(int lastKnownStream)intmaxActiveStreams()Gets the maximum number of streams (created by this endpoint) that are allowed to be active at the same time.voidmaxActiveStreams(int maxActiveStreams)Sets the limit forSETTINGS_MAX_CONCURRENT_STREAMS.booleanmayHaveCreatedStream(int streamId)Indicates whether or not this endpoint may have created the given stream.intnumActiveStreams()Gets the number of active streams (i.e.Http2Connection.Endpoint<? extends Http2FlowController>opposite()Gets theHttp2Connection.Endpointopposite this one.DefaultHttp2Connection.DefaultStreamreservePushStream(int streamId, Http2Stream parent)Creates a push stream in the reserved state for this endpoint and notifies all listeners.private voidupdateMaxStreams()
-
-
-
Field Detail
-
server
private final boolean server
-
nextStreamIdToCreate
private int nextStreamIdToCreate
The 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 nextReservationStreamId
Used 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
private F extends Http2FlowController flowController
-
maxStreams
private int maxStreams
-
maxActiveStreams
private int maxActiveStreams
-
maxReservedStreams
private final int maxReservedStreams
-
numActiveStreams
int numActiveStreams
-
numStreams
int numStreams
-
-
Method Detail
-
incrementAndGetNextStreamId
public int incrementAndGetNextStreamId()
Description copied from interface:Http2Connection.EndpointIncrement 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:
incrementAndGetNextStreamIdin interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
incrementExpectedStreamId
private void incrementExpectedStreamId(int streamId)
-
isValidStreamId
public boolean isValidStreamId(int streamId)
Description copied from interface:Http2Connection.EndpointIndicates whether the given streamId is from the set of IDs used by this endpoint to create new streams.- Specified by:
isValidStreamIdin interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
mayHaveCreatedStream
public boolean mayHaveCreatedStream(int streamId)
Description copied from interface:Http2Connection.EndpointIndicates whether or not this endpoint may have created the given stream. This istrueifHttp2Connection.Endpoint.isValidStreamId(int)andstreamId<=Http2Connection.Endpoint.lastStreamCreated().- Specified by:
mayHaveCreatedStreamin interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
canOpenStream
public boolean canOpenStream()
Description copied from interface:Http2Connection.EndpointIndicates whether or a stream created by this endpoint can be opened without violatingHttp2Connection.Endpoint.maxActiveStreams().- Specified by:
canOpenStreamin interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
createStream
public DefaultHttp2Connection.DefaultStream createStream(int streamId, boolean halfClosed) throws Http2Exception
Description copied from interface:Http2Connection.EndpointCreates 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.Listeners. The state transition is sensitive tohalfClosedand is defined byHttp2Stream.open(boolean).- Specified by:
createStreamin interfaceHttp2Connection.Endpoint<F extends Http2FlowController>- Parameters:
streamId- The ID of the streamhalfClosed- seeHttp2Stream.open(boolean).- Throws:
Http2Exception- See Also:
Http2Stream.open(boolean)
-
created
public boolean created(Http2Stream stream)
Description copied from interface:Http2Connection.EndpointIndicates whether or not this endpoint created the given stream.- Specified by:
createdin interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
isServer
public boolean isServer()
Description copied from interface:Http2Connection.EndpointIndicates whether or not this endpoint is the server-side of the connection.- Specified by:
isServerin interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
reservePushStream
public DefaultHttp2Connection.DefaultStream reservePushStream(int streamId, Http2Stream parent) throws Http2Exception
Description copied from interface:Http2Connection.EndpointCreates 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
OPENfrom the side sending the push promise. - Could not set a valid priority for the new stream.
- Specified by:
reservePushStreamin 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
private void addStream(DefaultHttp2Connection.DefaultStream stream)
-
allowPushTo
public void allowPushTo(boolean allow)
Description copied from interface:Http2Connection.EndpointThis 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 aSETTINGSframe.- Specified by:
allowPushToin interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
allowPushTo
public boolean allowPushTo()
Description copied from interface:Http2Connection.EndpointThis is the SETTINGS_ENABLE_PUSH value sent from the opposite endpoint. The initial value must betruefor the client endpoint and always false for a server endpoint.- Specified by:
allowPushToin interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
numActiveStreams
public int numActiveStreams()
Description copied from interface:Http2Connection.EndpointGets the number of active streams (i.e.OPENorHALF CLOSED) that were created by this endpoint.- Specified by:
numActiveStreamsin interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
maxActiveStreams
public int maxActiveStreams()
Description copied from interface:Http2Connection.EndpointGets 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:
maxActiveStreamsin interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
maxActiveStreams
public void maxActiveStreams(int maxActiveStreams)
Description copied from interface:Http2Connection.EndpointSets the limit forSETTINGS_MAX_CONCURRENT_STREAMS.- Specified by:
maxActiveStreamsin 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.EndpointGets the ID of the stream last successfully created by this endpoint.- Specified by:
lastStreamCreatedin interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
lastStreamKnownByPeer
public int lastStreamKnownByPeer()
Description copied from interface:Http2Connection.EndpointIf 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:
lastStreamKnownByPeerin interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
lastStreamKnownByPeer
private void lastStreamKnownByPeer(int lastKnownStream)
-
flowController
public F flowController()
Description copied from interface:Http2Connection.EndpointGets the flow controller for this endpoint.- Specified by:
flowControllerin interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
flowController
public void flowController(F flowController)
Description copied from interface:Http2Connection.EndpointSets the flow controller for this endpoint.- Specified by:
flowControllerin interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
opposite
public Http2Connection.Endpoint<? extends Http2FlowController> opposite()
Description copied from interface:Http2Connection.EndpointGets theHttp2Connection.Endpointopposite this one.- Specified by:
oppositein interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
updateMaxStreams
private void updateMaxStreams()
-
checkNewStreamAllowed
private void checkNewStreamAllowed(int streamId, Http2Stream.State state) throws Http2Exception- Throws:
Http2Exception
-
isLocal
private boolean isLocal()
-
-