Class HTTP2Stream

java.lang.Object
org.omegazero.http.h2.streams.HTTP2Stream
Direct Known Subclasses:
ControlStream, MessageStream

public abstract class HTTP2Stream extends Object
Represents a HTTP/2 stream where frames can be sent or received.
Since:
1.2.1
  • Field Details

    • streamId

      protected final int streamId
    • connection

      protected final WritableSocket connection
    • windowSizeLock

      protected Object windowSizeLock
    • receiverWindowSize

      protected int receiverWindowSize
    • localWindowSize

      protected int localWindowSize
  • Constructor Details

    • HTTP2Stream

      public HTTP2Stream(int streamId, WritableSocket connection)
      Creates a HTTP2Stream instance.
      Parameters:
      streamId - The stream ID
      connection - The underlying connection
  • Method Details

    • receiveFrame

      public void receiveFrame(int type, int flags, byte[] data) throws HTTP2ConnectionError
      This method is called if a frame is received on this HTTP/2 stream.
      Parameters:
      type - The frame type number
      flags - The frame flags
      data - 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 the WritableSocket passed in the constructor.
      Parameters:
      type - The frame type
      flags - The frame flags
      data - 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 the WritableSocket passed in the constructor.
      Parameters:
      type - The frame type
      flags - The frame flags
      data - The frame payload
      offset - The index in data to start reading from
      length - 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. The receiverWindowSize is updated before this method is called.
    • getStreamId

      public int getStreamId()
      Returns the ID of this HTTP2Stream.
      Returns:
      The stream ID
    • getConnection

      public WritableSocket getConnection()
      Returns the WritableSocket configured in the constructor.
      Returns:
      The WritableSocket
    • isFlowControlledFrameType

      public static boolean isFlowControlledFrameType(int type)
      Returns true 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 given WritableSocket.
      Parameters:
      connection - The WritableSocket to write the encoded frame to
      streamId - The stream ID to write the frame on
      type - The frame type
      flags - The frame flags
      data - The frame payload
      offset - The offset in data
      length - The number of bytes in data to write