Class HTTP2Endpoint
- Direct Known Subclasses:
HTTP2Client
A HTTP2Endpoint
is initialized with a WritableSocket
representing the underlying connection where frames are exchanged. Incoming data on this connection must be
passed to processData(byte[])
.
- Since:
- 1.2.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Deque<MessageStream>
Deprecated.protected long
The time in nanoseconds after which closed streams incloseWaitTimeout
are removed fromstreams
.protected final WritableSocket
The underlying connection.protected int
The stream ID of the latest stream that was processed.protected final HPackContext
TheHPackContext
used for thisHTTP2Endpoint
.protected final Set<MessageStream>
The set ofMessageStream
s initiated by the peer.protected final HTTP2Settings
The local settings.protected final Map<Integer,
HTTP2Stream> Deprecated.Since 1.2.4, direct access is discouraged; useregisterStream(HTTP2Stream)
andgetStream(int)
instead -
Constructor Summary
ConstructorsConstructorDescriptionHTTP2Endpoint
(WritableSocket connection, HTTP2Settings settings, HPackContext hpack) Creates a newHTTP2Endpoint
instance.HTTP2Endpoint
(WritableSocket connection, HTTP2Settings settings, HPackContext.Session hpackSession, boolean useHuffmanEncoding) Creates a newHTTP2Endpoint
instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
Checks whether a newMessageStream
can be initiated locally according to the remote MAX_CONCURRENT_STREAMS setting.protected void
Checks whether the remote endpoint may cause a new stream to be created according to the local MAX_CONCURRENT_STREAMS setting.Returns the underlying connection as aWritableSocket
.protected ControlStream
Returns the connection control stream (stream with ID 0).int
Returns the number of openMessageStream
s initiated locally.int
Returns the number of openMessageStream
s.int
Returns the number of openMessageStream
s initiated by the peer.protected HTTP2Stream
getStream
(int streamId) Returns the stream with the given ID.protected Collection<HTTP2Stream>
Returns a set of all known streams, including recently closed streams.protected void
CallsMessageStream.windowUpdate()
for each activeMessageStream
.protected abstract HTTP2Stream
newStreamForFrame
(int streamId, int type, int flags, byte[] payload) Processes a frame received on a previously nonexistent stream and creates a newHTTP2Stream
for it, if appropriate.void
processData
(byte[] data) Data received on the underlying connection of thisHTTP2Endpoint
is passed to this method for further processing.protected final int
processData0
(byte[] data, int index) protected void
registerStream
(HTTP2Stream stream) Registers a locally created stream.protected void
registerStream
(HTTP2Stream stream, boolean initiatedByPeer) Registers a new stream.protected void
streamClosed
(MessageStream stream) Notifies thisHTTP2Endpoint
that the given stream has closed.
-
Field Details
-
connection
The underlying connection. -
settings
The local settings. -
hpack
TheHPackContext
used for thisHTTP2Endpoint
. -
streams
Deprecated.Since 1.2.4, direct access is discouraged; useregisterStream(HTTP2Stream)
andgetStream(int)
insteadContains active and recently closed streams of thisHTTP2Endpoint
. -
closeWaitStreams
Deprecated.Since 1.2.4, direct access is discouraged; usestreamClosed(MessageStream)
insteadContains closed streams which will soon be removed fromstreams
. -
highestStreamId
protected int highestStreamIdThe stream ID of the latest stream that was processed. -
peerInitiatedStreams
The set ofMessageStream
s initiated by the peer. May benull
if the peer has not initiated any streams yet.- Since:
- 1.4.1
-
closeWaitTimeout
protected long closeWaitTimeoutThe time in nanoseconds after which closed streams incloseWaitTimeout
are removed fromstreams
.
-
-
Constructor Details
-
HTTP2Endpoint
public HTTP2Endpoint(WritableSocket connection, HTTP2Settings settings, HPackContext.Session hpackSession, boolean useHuffmanEncoding) Creates a newHTTP2Endpoint
instance.- Parameters:
connection
- The underlying connectionsettings
- The local settingshpackSession
- The HPACK session to useuseHuffmanEncoding
- Whether to enable HPACK Huffman Coding
-
HTTP2Endpoint
Creates a newHTTP2Endpoint
instance.- Parameters:
connection
- The underlying connectionsettings
- The local settingshpack
- TheHPackContext
to use
-
-
Method Details
-
newStreamForFrame
protected abstract HTTP2Stream newStreamForFrame(int streamId, int type, int flags, byte[] payload) throws HTTP2ConnectionError Processes a frame received on a previously nonexistent stream and creates a newHTTP2Stream
for it, if appropriate.The returned stream is registered automatically using
registerStream(HTTP2Stream, boolean)
. Ifnull
is returned (no stream was created), and the frame type is not PRIORITY, it will be treated as a connection error of type PROTOCOL_ERROR.When creating a stream, the implementation should call
checkRemoteCreateStream()
first.- Parameters:
streamId
- The stream ID of the new streamtype
- The frame typeflags
- The frame flagspayload
- The frame payload- Returns:
- The new stream, or
null
if no stream is appropriate - Throws:
HTTP2ConnectionError
- If the received frame is invalid or unexpected
-
processData
public void processData(byte[] data) Data received on the underlying connection of thisHTTP2Endpoint
is passed to this method for further processing.- Parameters:
data
- The received data
-
processData0
protected final int processData0(byte[] data, int index) -
registerStream
Registers a locally created stream.Calls
.registerStream
(stream, false)- Parameters:
stream
- The stream- See Also:
-
registerStream
Registers a new stream.If applicable,
streamClosed(MessageStream)
must be called with this stream when it closes.- Parameters:
stream
- The streaminitiatedByPeer
-true
if the given stream was initiated by the peer. Ignored for any stream type other thanMessageStream
- See Also:
-
streamClosed
Notifies thisHTTP2Endpoint
that the given stream has closed. This method must be called for all message streams added usingregisterStream(HTTP2Stream)
or returned bynewStreamForFrame(int, int, int, byte[])
when the stream closes.- Parameters:
stream
- The stream- Throws:
IllegalStateException
- If the stream is not closed- Since:
- 1.2.4
-
getControlStream
Returns the connection control stream (stream with ID 0).Equivalent to:
(ControlStream)
getStream
(0);- Returns:
- The control stream
-
getStream
Returns the stream with the given ID.- Parameters:
streamId
- The stream ID- Returns:
- The stream, or
null
if no stream with the given ID exists - Since:
- 1.2.4
- See Also:
-
getStreams
Returns a set of all known streams, including recently closed streams.- Returns:
- A set of all streams
- Since:
- 1.2.4
- See Also:
-
getOpenMessageStreamCount
public int getOpenMessageStreamCount()Returns the number of openMessageStream
s.- Returns:
- The number of open message streams
- Since:
- 1.2.4
-
getOpenPeerInitiatedMessageStreamCount
public int getOpenPeerInitiatedMessageStreamCount()Returns the number of openMessageStream
s initiated by the peer.- Returns:
- The number of open message streams initiated by the peer
- Since:
- 1.4.1
-
getOpenLocallyInitiatedMessageStreamCount
public int getOpenLocallyInitiatedMessageStreamCount()Returns the number of openMessageStream
s initiated locally.- Returns:
- The number of open message streams initiated locally
- Since:
- 1.4.1
-
checkRemoteCreateStream
Checks whether the remote endpoint may cause a new stream to be created according to the local MAX_CONCURRENT_STREAMS setting. If not, aHTTP2ConnectionError
stream error with status code REFUSED_STREAM is thrown.- Throws:
HTTP2ConnectionError
- If no new stream may be created
-
checkLocalCreateStream
protected boolean checkLocalCreateStream()Checks whether a newMessageStream
can be initiated locally according to the remote MAX_CONCURRENT_STREAMS setting.- Returns:
true
if a new local stream can be created
-
handleConnectionWindowUpdate
protected void handleConnectionWindowUpdate()CallsMessageStream.windowUpdate()
for each activeMessageStream
.This method should be called by the
ControlStream
onWindowUpdate
callback, and if the underlying connection is writable again, after being unwritable previously. -
getConnection
Returns the underlying connection as aWritableSocket
.- Returns:
- The connection
-
streamClosed(MessageStream)
instead