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 WritableSocketprotected intprotected intprotected final intprotected Object -
Constructor Summary
ConstructorsConstructorDescriptionHTTP2Stream(int streamId, WritableSocket connection) Creates aHTTP2Streaminstance. -
Method Summary
Modifier and TypeMethodDescriptionReturns theWritableSocketconfigured in the constructor.intReturns the ID of thisHTTP2Stream.static booleanisFlowControlledFrameType(int type) Returnstrueif the given frame type is a flow-controlled frame type.voidreceiveFrame(int type, int flags, byte[] data) This method is called if a frame is received on this HTTP/2 stream.voidsendWindowSizeUpdate(int increment) Writes a window update frame on this stream and updates internal window size information.protected voidThis method is called when a window update frame is received.voidwriteFrame(int type, int flags, byte[] data) Writes a frame with the given properties to theWritableSocketpassed in the constructor.voidwriteFrame(int type, int flags, byte[] data, int offset, int length) Writes a frame with the given properties to theWritableSocketpassed in the constructor.static voidwriteFrame(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 aHTTP2Streaminstance.- 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 theWritableSocketpassed 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 theWritableSocketpassed 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. ThereceiverWindowSizeis updated before this method is called. -
getStreamId
public int getStreamId()Returns the ID of thisHTTP2Stream.- Returns:
- The stream ID
-
getConnection
Returns theWritableSocketconfigured in the constructor.- Returns:
- The
WritableSocket
-
isFlowControlledFrameType
public static boolean isFlowControlledFrameType(int type) Returnstrueif the given frame type is a flow-controlled frame type.- Parameters:
type- The frame type- Returns:
trueif 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- TheWritableSocketto 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
-