Package org.omegazero.http.h2.streams
Class HTTP2Stream
java.lang.Object
org.omegazero.http.h2.streams.HTTP2Stream
- Direct Known Subclasses:
ControlStream
,MessageStream
Represents a HTTP/2 stream where frames can be sent or received.
- Since:
- 1.2.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final WritableSocket
protected int
protected int
protected final int
protected Object
-
Constructor Summary
ConstructorsConstructorDescriptionHTTP2Stream
(int streamId, WritableSocket connection) Creates aHTTP2Stream
instance. -
Method Summary
Modifier and TypeMethodDescriptionReturns theWritableSocket
configured in the constructor.int
Returns the ID of thisHTTP2Stream
.static boolean
isFlowControlledFrameType
(int type) Returnstrue
if the given frame type is a flow-controlled frame type.void
receiveFrame
(int type, int flags, byte[] data) This method is called if a frame is received on this HTTP/2 stream.void
sendWindowSizeUpdate
(int increment) Writes a window update frame on this stream and updates internal window size information.protected void
This method is called when a window update frame is received.void
writeFrame
(int type, int flags, byte[] data) Writes a frame with the given properties to theWritableSocket
passed in the constructor.void
writeFrame
(int type, int flags, byte[] data, int offset, int length) Writes a frame with the given properties to theWritableSocket
passed in the constructor.static void
writeFrame
(WritableSocket connection, int streamId, int type, int flags, byte[] data, int offset, int length) Writes a frame with the given properties to the givenWritableSocket
.
-
Field Details
-
streamId
protected final int streamId -
connection
-
windowSizeLock
-
receiverWindowSize
protected int receiverWindowSize -
localWindowSize
protected int localWindowSize
-
-
Constructor Details
-
HTTP2Stream
Creates aHTTP2Stream
instance.- Parameters:
streamId
- The stream IDconnection
- The underlying connection
-
-
Method Details
-
receiveFrame
This method is called if a frame is received on this HTTP/2 stream.- Parameters:
type
- The frame type numberflags
- The frame flagsdata
- The frame payload- Throws:
HTTP2ConnectionError
- If a HTTP/2 connection error occurs, for example because the frame payload is invalid
-
writeFrame
public void writeFrame(int type, int flags, byte[] data) Writes a frame with the given properties to theWritableSocket
passed in the constructor.- Parameters:
type
- The frame typeflags
- The frame flagsdata
- The frame payload
-
writeFrame
public void writeFrame(int type, int flags, byte[] data, int offset, int length) Writes a frame with the given properties to theWritableSocket
passed in the constructor.- Parameters:
type
- The frame typeflags
- The frame flagsdata
- The frame payloadoffset
- The index in data to start reading fromlength
- The total amount of bytes in data to write- Throws:
IndexOutOfBoundsException
- If offset or length is invalid
-
sendWindowSizeUpdate
public void sendWindowSizeUpdate(int increment) Writes a window update frame on this stream and updates internal window size information.- Parameters:
increment
- The window size increment
-
windowUpdate
protected void windowUpdate()This method is called when a window update frame is received. ThereceiverWindowSize
is updated before this method is called. -
getStreamId
public int getStreamId()Returns the ID of thisHTTP2Stream
.- Returns:
- The stream ID
-
getConnection
Returns theWritableSocket
configured in the constructor.- Returns:
- The
WritableSocket
-
isFlowControlledFrameType
public static boolean isFlowControlledFrameType(int type) Returnstrue
if the given frame type is a flow-controlled frame type.- Parameters:
type
- The frame type- Returns:
true
if the given frame type is a flow-controlled frame type
-
writeFrame
public static void writeFrame(WritableSocket connection, int streamId, int type, int flags, byte[] data, int offset, int length) Writes a frame with the given properties to the givenWritableSocket
.- Parameters:
connection
- TheWritableSocket
to write the encoded frame tostreamId
- The stream ID to write the frame ontype
- The frame typeflags
- The frame flagsdata
- The frame payloadoffset
- The offset in datalength
- The number of bytes in data to write
-