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 F
flowController
private int
lastStreamKnownByPeer
private int
maxActiveStreams
private int
maxReservedStreams
private int
maxStreams
private int
nextReservationStreamId
Used for reservation of stream IDs.private int
nextStreamIdToCreate
The minimum stream ID allowed when creating the next stream.(package private) int
numActiveStreams
(package private) int
numStreams
private boolean
pushToAllowed
private boolean
server
-
Constructor Summary
Constructors Constructor Description DefaultEndpoint(boolean server, int maxReservedStreams)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addStream(DefaultHttp2Connection.DefaultStream stream)
boolean
allowPushTo()
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
canOpenStream()
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.DefaultHttp2Connection.DefaultStream
createStream(int streamId, boolean halfClosed)
Creates a stream initiated by this endpoint.F
flowController()
Gets the flow controller for this endpoint.void
flowController(F flowController)
Sets the flow controller for this endpoint.int
incrementAndGetNextStreamId()
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
lastStreamCreated()
Gets the ID of the stream last successfully created by this endpoint.int
lastStreamKnownByPeer()
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
maxActiveStreams()
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
numActiveStreams()
Gets the number of active streams (i.e.Http2Connection.Endpoint<? extends Http2FlowController>
opposite()
Gets theHttp2Connection.Endpoint
opposite this one.DefaultHttp2Connection.DefaultStream
reservePushStream(int streamId, Http2Stream parent)
Creates a push stream in the reserved state for this endpoint and notifies all listeners.private void
updateMaxStreams()
-
-
-
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.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
<=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:
Http2Stream.open(boolean)
-
created
public boolean created(Http2Stream stream)
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
private void addStream(DefaultHttp2Connection.DefaultStream stream)
-
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
public F flowController()
Description copied from interface:Http2Connection.Endpoint
Gets the flow controller for this endpoint.- Specified by:
flowController
in interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
flowController
public void flowController(F flowController)
Description copied from interface:Http2Connection.Endpoint
Sets the flow controller for this endpoint.- Specified by:
flowController
in interfaceHttp2Connection.Endpoint<F extends Http2FlowController>
-
opposite
public Http2Connection.Endpoint<? 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
private void checkNewStreamAllowed(int streamId, Http2Stream.State state) throws Http2Exception
- Throws:
Http2Exception
-
isLocal
private boolean isLocal()
-
-