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 longThe time in nanoseconds after which closed streams incloseWaitTimeoutare removed fromstreams.protected final WritableSocketThe underlying connection.protected intThe stream ID of the latest stream that was processed.protected final HPackContextTheHPackContextused for thisHTTP2Endpoint.protected final Set<MessageStream>The set ofMessageStreams initiated by the peer.protected final HTTP2SettingsThe 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 newHTTP2Endpointinstance.HTTP2Endpoint(WritableSocket connection, HTTP2Settings settings, HPackContext.Session hpackSession, boolean useHuffmanEncoding) Creates a newHTTP2Endpointinstance. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanChecks whether a newMessageStreamcan be initiated locally according to the remote MAX_CONCURRENT_STREAMS setting.protected voidChecks 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 ControlStreamReturns the connection control stream (stream with ID 0).intReturns the number of openMessageStreams initiated locally.intReturns the number of openMessageStreams.intReturns the number of openMessageStreams initiated by the peer.protected HTTP2StreamgetStream(int streamId) Returns the stream with the given ID.protected Collection<HTTP2Stream>Returns a set of all known streams, including recently closed streams.protected voidCallsMessageStream.windowUpdate()for each activeMessageStream.protected abstract HTTP2StreamnewStreamForFrame(int streamId, int type, int flags, byte[] payload) Processes a frame received on a previously nonexistent stream and creates a newHTTP2Streamfor it, if appropriate.voidprocessData(byte[] data) Data received on the underlying connection of thisHTTP2Endpointis passed to this method for further processing.protected final intprocessData0(byte[] data, int index) protected voidregisterStream(HTTP2Stream stream) Registers a locally created stream.protected voidregisterStream(HTTP2Stream stream, boolean initiatedByPeer) Registers a new stream.protected voidstreamClosed(MessageStream stream) Notifies thisHTTP2Endpointthat the given stream has closed.
-
Field Details
-
connection
The underlying connection. -
settings
The local settings. -
hpack
TheHPackContextused 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 ofMessageStreams initiated by the peer. May benullif the peer has not initiated any streams yet.- Since:
- 1.4.1
-
closeWaitTimeout
protected long closeWaitTimeoutThe time in nanoseconds after which closed streams incloseWaitTimeoutare removed fromstreams.
-
-
Constructor Details
-
HTTP2Endpoint
public HTTP2Endpoint(WritableSocket connection, HTTP2Settings settings, HPackContext.Session hpackSession, boolean useHuffmanEncoding) Creates a newHTTP2Endpointinstance.- Parameters:
connection- The underlying connectionsettings- The local settingshpackSession- The HPACK session to useuseHuffmanEncoding- Whether to enable HPACK Huffman Coding
-
HTTP2Endpoint
Creates a newHTTP2Endpointinstance.- Parameters:
connection- The underlying connectionsettings- The local settingshpack- TheHPackContextto 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 newHTTP2Streamfor it, if appropriate.The returned stream is registered automatically using
registerStream(HTTP2Stream, boolean). Ifnullis 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
nullif 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 thisHTTP2Endpointis 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-trueif the given stream was initiated by the peer. Ignored for any stream type other thanMessageStream- See Also:
-
streamClosed
Notifies thisHTTP2Endpointthat 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
nullif 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 openMessageStreams.- Returns:
- The number of open message streams
- Since:
- 1.2.4
-
getOpenPeerInitiatedMessageStreamCount
public int getOpenPeerInitiatedMessageStreamCount()Returns the number of openMessageStreams 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 openMessageStreams 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, aHTTP2ConnectionErrorstream error with status code REFUSED_STREAM is thrown.- Throws:
HTTP2ConnectionError- If no new stream may be created
-
checkLocalCreateStream
protected boolean checkLocalCreateStream()Checks whether a newMessageStreamcan be initiated locally according to the remote MAX_CONCURRENT_STREAMS setting.- Returns:
trueif a new local stream can be created
-
handleConnectionWindowUpdate
protected void handleConnectionWindowUpdate()CallsMessageStream.windowUpdate()for each activeMessageStream.This method should be called by the
ControlStreamonWindowUpdatecallback, 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