Top Description Inners Methods
io.netty5.handler.codec.http2

public Interface Http2Connection

Known Direct Implementers
io.netty5.handler.codec.http2.DefaultHttp2Connection
Annotations
@UnstableApi
Imports
io.netty5.buffer.Buffer, io.netty5.util.concurrent.Promise, io.netty5.util.internal.UnstableApi

Manager for the state of an HTTP/2 connection with the remote end-point.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
Http2Connection.Endpoint<F extends Http2FlowController>

A view of the connection from one endpoint (local or remote).

public static interface
Http2Connection.Listener

Listener for life-cycle events for streams in this connection.

public static interface
Http2Connection.PropertyKey

A key to be used for associating application-defined properties with streams within this connection.

Method Summary

Modifier and TypeMethod and Description
public void
addListener(Http2Connection.Listener listener)

Adds a listener of stream life-cycle events.

public void
close(Promise<Void>
Will be completed when all streams have been removed, and listeners have been notified.
promise
)

Close this connection.

public Http2Stream
connectionStream()

Gets the stream object representing the connection, itself (i.e. stream zero).

public Http2Stream

Returns:

The stream before iteration stopped or null if iteration went past the end.
forEachActiveStream
(Http2StreamVisitor
The visitor which will visit each active stream.
visitor
)

Provide a means of iterating over the collection of active streams.

public boolean
goAwayReceived()

Indicates whether or not a GOAWAY was received from the remote endpoint.

public void
goAwayReceived(int
The Last-Stream-ID in the GOAWAY frame.
lastKnownStream
,
long
the Error Code in the GOAWAY frame.
errorCode
,
Buffer
The Additional Debug Data in the GOAWAY frame. Note that reference count ownership belongs to the caller (ownership is not transferred to this method).
message
)

Indicates that a GOAWAY was received from the remote endpoint and sets the last known stream.

public boolean
goAwaySent()

Indicates whether or not a GOAWAY was sent to the remote endpoint.

public boolean

Returns:

true if the corresponding GOAWAY frame should be sent to the remote endpoint.
goAwaySent
(int
The Last-Stream-ID in the GOAWAY frame.
lastKnownStream
,
long
the Error Code in the GOAWAY frame.
errorCode
,
Buffer
The Additional Debug Data in the GOAWAY frame. Note that reference count ownership belongs to the caller (ownership is not transferred to this method).
message
)

Updates the local state of this Http2Connection as a result of a GOAWAY to send to the remote endpoint.

public boolean
isServer()

Indicates whether or not the local endpoint for this connection is the server.

public Http2Connection.Endpoint<Http2LocalFlowController>
local()

Gets a view of this connection from the local Endpoint.

public Http2Connection.PropertyKey
newKey()

Creates a new key that is unique within this Http2Connection.

public int
numActiveStreams()

Gets the number of streams that are actively in use (i.e. OPEN or HALF CLOSED).

public Http2Connection.Endpoint<Http2RemoteFlowController>
remote()

Gets a view of this connection from the remote Endpoint.

public void
removeListener(Http2Connection.Listener listener)

Removes a listener of stream life-cycle events.

public Http2Stream
stream(int streamId)

Gets the stream if it exists.

public boolean
streamMayHaveExisted(int streamId)

Indicates whether or not the given stream may have existed within this connection.

Method Detail

addListenerback to summary
public void addListener(Http2Connection.Listener listener)

Adds a listener of stream life-cycle events.

closeback to summary
public void close(Promise<Void> promise)

Close this connection. No more new streams can be created after this point and all streams that exists (active or otherwise) will be closed and removed.

Note if iterating active streams via forEachActiveStream(Http2StreamVisitor) and an exception is thrown it is necessary to call this method again to ensure the close completes.

Parameters
promise:Promise<Void>

Will be completed when all streams have been removed, and listeners have been notified.

connectionStreamback to summary
public Http2Stream connectionStream()

Gets the stream object representing the connection, itself (i.e. stream zero). This object always exists.

forEachActiveStreamback to summary
public Http2Stream forEachActiveStream(Http2StreamVisitor visitor) throws Http2Exception

Provide a means of iterating over the collection of active streams.

Parameters
visitor:Http2StreamVisitor

The visitor which will visit each active stream.

Returns:Http2Stream

The stream before iteration stopped or null if iteration went past the end.

goAwayReceivedback to summary
public boolean goAwayReceived()

Indicates whether or not a GOAWAY was received from the remote endpoint.

goAwayReceivedback to summary
public void goAwayReceived(int lastKnownStream, long errorCode, Buffer message) throws Http2Exception

Indicates that a GOAWAY was received from the remote endpoint and sets the last known stream.

Parameters
lastKnownStream:int

The Last-Stream-ID in the GOAWAY frame.

errorCode:long

the Error Code in the GOAWAY frame.

message:Buffer

The Additional Debug Data in the GOAWAY frame. Note that reference count ownership belongs to the caller (ownership is not transferred to this method).

goAwaySentback to summary
public boolean goAwaySent()

Indicates whether or not a GOAWAY was sent to the remote endpoint.

goAwaySentback to summary
public boolean goAwaySent(int lastKnownStream, long errorCode, Buffer message) throws Http2Exception

Updates the local state of this Http2Connection as a result of a GOAWAY to send to the remote endpoint.

Parameters
lastKnownStream:int

The Last-Stream-ID in the GOAWAY frame.

errorCode:long

the Error Code in the GOAWAY frame.

message:Buffer

The Additional Debug Data in the GOAWAY frame. Note that reference count ownership belongs to the caller (ownership is not transferred to this method).

Returns:boolean

true if the corresponding GOAWAY frame should be sent to the remote endpoint.

isServerback to summary
public boolean isServer()

Indicates whether or not the local endpoint for this connection is the server.

localback to summary
public Http2Connection.Endpoint<Http2LocalFlowController> local()

Gets a view of this connection from the local Endpoint.

newKeyback to summary
public Http2Connection.PropertyKey newKey()

Creates a new key that is unique within this Http2Connection.

numActiveStreamsback to summary
public int numActiveStreams()

Gets the number of streams that are actively in use (i.e. OPEN or HALF CLOSED).

remoteback to summary
public Http2Connection.Endpoint<Http2RemoteFlowController> remote()

Gets a view of this connection from the remote Endpoint.

removeListenerback to summary
public void removeListener(Http2Connection.Listener listener)

Removes a listener of stream life-cycle events. If the same listener was added multiple times then only the first occurrence gets removed.

streamback to summary
public Http2Stream stream(int streamId)

Gets the stream if it exists. If not, returns null.

streamMayHaveExistedback to summary
public boolean streamMayHaveExisted(int streamId)

Indicates whether or not the given stream may have existed within this connection. This is a short form for calling Endpoint#mayHaveCreatedStream(int) on both endpoints.

io.netty5.handler.codec.http2 back to summary

public Interface Http2Connection.Endpoint<F extends Http2FlowController>

Known Direct Implementers
io.netty5.handler.codec.http2.DefaultHttp2Connection.DefaultEndpoint

A view of the connection from one endpoint (local or remote).

Method Summary

Modifier and TypeMethod and Description
public void
allowPushTo(boolean allow)

This is the SETTINGS_ENABLE_PUSH value sent from the opposite endpoint.

public boolean
allowPushTo()

This is the SETTINGS_ENABLE_PUSH value sent from the opposite endpoint.

public boolean
canOpenStream()

Indicates whether or a stream created by this endpoint can be opened without violating maxActiveStreams().

public boolean
created(Http2Stream stream)

Indicates whether or not this endpoint created the given stream.

public Http2Stream
createStream(int
The ID of the stream
streamId
,
boolean halfClosed)

Creates a stream initiated by this endpoint.

public F
flowController()

Gets the flow controller for this endpoint.

public void
flowController(F flowController)

Sets the flow controller for this endpoint.

public int
incrementAndGetNextStreamId()

Increment and get the next generated stream id this endpoint.

public boolean
isServer()

Indicates whether or not this endpoint is the server-side of the connection.

public boolean
isValidStreamId(int streamId)

Indicates whether the given streamId is from the set of IDs used by this endpoint to create new streams.

public int
lastStreamCreated()

Gets the ID of the stream last successfully created by this endpoint.

public int
lastStreamKnownByPeer()

If a GOAWAY was received for this endpoint, this will be the last stream ID from the GOAWAY frame.

public int
maxActiveStreams()

Gets the maximum number of streams (created by this endpoint) that are allowed to be active at the same time.

public void
maxActiveStreams(int
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.
maxActiveStreams
)

Sets the limit for SETTINGS_MAX_CONCURRENT_STREAMS.

public boolean
mayHaveCreatedStream(int streamId)

Indicates whether or not this endpoint may have created the given stream.

public int
numActiveStreams()

Gets the number of active streams (i.e. OPEN or HALF CLOSED) that were created by this endpoint.

public Http2Connection.Endpoint<? extends Http2FlowController>
opposite()

Gets the Endpoint opposite this one.

public Http2Stream
reservePushStream(int
the ID of the push stream
streamId
,
Http2Stream
the parent stream used to initiate the push stream.
parent
)

Creates a push stream in the reserved state for this endpoint and notifies all listeners.

Method Detail

allowPushToback to summary
public void allowPushTo(boolean allow)

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 a SETTINGS frame.

allowPushToback to summary
public boolean allowPushTo()

This is the SETTINGS_ENABLE_PUSH value sent from the opposite endpoint. The initial value must be true for the client endpoint and always false for a server endpoint.

canOpenStreamback to summary
public boolean canOpenStream()

Indicates whether or a stream created by this endpoint can be opened without violating maxActiveStreams().

createdback to summary
public boolean created(Http2Stream stream)

Indicates whether or not this endpoint created the given stream.

createStreamback to summary
public Http2Stream createStream(int streamId, boolean halfClosed) throws Http2Exception

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.
  • canOpenStream() is false.
  • The connection is marked as going away.

The initial state of the stream will be immediately set before notifying Listeners. The state transition is sensitive to halfClosed and is defined by Http2Stream#open(boolean).

Parameters
streamId:int

The ID of the stream

halfClosed:boolean

see Http2Stream#open(boolean).

See Also
Http2Stream#open(boolean)
flowControllerback to summary
public F flowController()

Gets the flow controller for this endpoint.

flowControllerback to summary
public void flowController(F flowController)

Sets the flow controller for this endpoint.

incrementAndGetNextStreamIdback to summary
public int incrementAndGetNextStreamId()

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.

isServerback to summary
public boolean isServer()

Indicates whether or not this endpoint is the server-side of the connection.

isValidStreamIdback to summary
public boolean isValidStreamId(int streamId)

Indicates whether the given streamId is from the set of IDs used by this endpoint to create new streams.

lastStreamCreatedback to summary
public int lastStreamCreated()

Gets the ID of the stream last successfully created by this endpoint.

lastStreamKnownByPeerback to summary
public int lastStreamKnownByPeer()

If a GOAWAY was received for this endpoint, this will be the last stream ID from the GOAWAY frame. Otherwise, this will be -1.

maxActiveStreamsback to summary
public int maxActiveStreams()

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".

maxActiveStreamsback to summary
public void maxActiveStreams(int maxActiveStreams)

Sets the limit for SETTINGS_MAX_CONCURRENT_STREAMS.

Parameters
maxActiveStreams:int

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.

mayHaveCreatedStreamback to summary
public boolean mayHaveCreatedStream(int streamId)

Indicates whether or not this endpoint may have created the given stream. This is true if isValidStreamId(int) and streamId <= lastStreamCreated().

numActiveStreamsback to summary
public int numActiveStreams()

Gets the number of active streams (i.e. OPEN or HALF CLOSED) that were created by this endpoint.

oppositeback to summary
public Http2Connection.Endpoint<? extends Http2FlowController> opposite()

Gets the Endpoint opposite this one.

reservePushStreamback to summary
public Http2Stream reservePushStream(int streamId, Http2Stream parent) throws Http2Exception

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.
Parameters
streamId:int

the ID of the push stream

parent:Http2Stream

the parent stream used to initiate the push stream.

io.netty5.handler.codec.http2 back to summary

public Interface Http2Connection.Listener

Known Direct Implementers
io.netty5.handler.codec.http2.Http2ConnectionAdapter, io.netty5.handler.codec.http2.Http2EventAdapter

Listener for life-cycle events for streams in this connection.

Method Summary

Modifier and TypeMethod and Description
public void
onGoAwayReceived(int
the last known stream of the remote endpoint.
lastStreamId
,
long
the error code, if abnormal closure.
errorCode
,
Buffer
application-defined debug data.
debugData
)

Called when a GOAWAY was received from the remote endpoint.

public void
onGoAwaySent(int
the last known stream of the remote endpoint.
lastStreamId
,
long
the error code, if abnormal closure.
errorCode
,
Buffer
application-defined debug data.
debugData
)

Called when a GOAWAY frame was sent for the connection.

public void
onStreamActive(Http2Stream stream)

Notifies the listener that the given stream was made active (i.e. OPEN or HALF CLOSED).

public void
onStreamAdded(Http2Stream stream)

Notifies the listener that the given stream was added to the connection.

public void
onStreamClosed(Http2Stream stream)

Notifies the listener that the given stream is now CLOSED in both directions and will no longer be accessible via forEachActiveStream(Http2StreamVisitor).

public void
onStreamHalfClosed(Http2Stream stream)

Notifies the listener that the given stream has transitioned from OPEN to HALF CLOSED.

public void
onStreamRemoved(Http2Stream stream)

Notifies the listener that the given stream has now been removed from the connection and will no longer be returned via Http2Connection#stream(int).

Method Detail

onGoAwayReceivedback to summary
public void onGoAwayReceived(int lastStreamId, long errorCode, Buffer debugData)

Called when a GOAWAY was received from the remote endpoint. This event handler duplicates Http2FrameListener#onGoAwayRead(io.netty5.channel.ChannelHandlerContext, int, long, Buffer) but is added here in order to simplify application logic for handling GOAWAY in a uniform way. An application should generally not handle both events, but if it does this method is called second, after notifying the Http2FrameListener.

If a RuntimeException is thrown it will be logged and not propagated. Throwing from this method is not supported and is considered a programming error.

Parameters
lastStreamId:int

the last known stream of the remote endpoint.

errorCode:long

the error code, if abnormal closure.

debugData:Buffer

application-defined debug data.

onGoAwaySentback to summary
public void onGoAwaySent(int lastStreamId, long errorCode, Buffer debugData)

Called when a GOAWAY frame was sent for the connection.

If a RuntimeException is thrown it will be logged and not propagated. Throwing from this method is not supported and is considered a programming error.

Parameters
lastStreamId:int

the last known stream of the remote endpoint.

errorCode:long

the error code, if abnormal closure.

debugData:Buffer

application-defined debug data.

onStreamActiveback to summary
public void onStreamActive(Http2Stream stream)

Notifies the listener that the given stream was made active (i.e. OPEN or HALF CLOSED).

If a RuntimeException is thrown it will be logged and not propagated. Throwing from this method is not supported and is considered a programming error.

onStreamAddedback to summary
public void onStreamAdded(Http2Stream stream)

Notifies the listener that the given stream was added to the connection. This stream may not yet be active (i.e. OPEN or HALF CLOSED).

If a RuntimeException is thrown it will be logged and not propagated. Throwing from this method is not supported and is considered a programming error.

onStreamClosedback to summary
public void onStreamClosed(Http2Stream stream)

Notifies the listener that the given stream is now CLOSED in both directions and will no longer be accessible via forEachActiveStream(Http2StreamVisitor).

If a RuntimeException is thrown it will be logged and not propagated. Throwing from this method is not supported and is considered a programming error.

onStreamHalfClosedback to summary
public void onStreamHalfClosed(Http2Stream stream)

Notifies the listener that the given stream has transitioned from OPEN to HALF CLOSED. This method will not be called until a state transition occurs from when onStreamActive(Http2Stream) was called. The stream can be inspected to determine which side is HALF CLOSED.

If a RuntimeException is thrown it will be logged and not propagated. Throwing from this method is not supported and is considered a programming error.

onStreamRemovedback to summary
public void onStreamRemoved(Http2Stream stream)

Notifies the listener that the given stream has now been removed from the connection and will no longer be returned via Http2Connection#stream(int). The connection may maintain inactive streams for some time before removing them.

If a RuntimeException is thrown it will be logged and not propagated. Throwing from this method is not supported and is considered a programming error.

io.netty5.handler.codec.http2 back to summary

public Interface Http2Connection.PropertyKey

Known Direct Implementers
io.netty5.handler.codec.http2.DefaultHttp2Connection.DefaultPropertyKey

A key to be used for associating application-defined properties with streams within this connection.