Class Http2ResponseWriter

java.lang.Object
dev.relism.flash.http2.message.Http2ResponseWriter
All Implemented Interfaces:
WriteIntent, ResponseSerializer.FieldConsumer

public final class Http2ResponseWriter extends Object implements WriteIntent, ResponseSerializer.FieldConsumer
Reusable per-stream HTTP/2 response serializer. It prepares a complete small response outside the connection write lock and exposes it as one WriteIntent.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    Http2ResponseWriter(int initialHeaderCapacity, int initialOutputCapacity)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes any in-flight streaming response body still open when the stream is abandoned before finishing (RST_STREAM from the peer, connection teardown) — see Http2Stream.cancel(), the abort-path caller.
    void
    accept(byte[] name, int nameOff, int nameLen, byte[] value, int valueOff, int valueLen)
     
    byte[]
    The buffer holding this intent's already-serialized bytes.
    void
    Called exactly once after this intent leaves the writer, whether the socket write succeeded or failed.
    void
     
    int
     
    boolean
     
    boolean
     
    boolean
     
    int
    Number of bytes to write, starting at WriteIntent.offset().
    Intrusive MPSC queue linkage — see IntrusiveMpscQueue.
    int
    Offset of the first byte to write, within WriteIntent.buffer().
    boolean
    prepare(Response response, int streamId, boolean headRequest, boolean sendDate, boolean sendContentLength, boolean huffmanDynamicValues, boolean emitTableSizeUpdate, int maxFrameSize, long maxHeaderListSize, int availableFlowWindow)
    Prepares a non-streaming response.
    int
    resume(int maxFrameSize, int availableFlowWindow)
    Serializes the next DATA batch after a WINDOW_UPDATE or previous write completion.
    void
    Intrusive MPSC queue linkage — see IntrusiveMpscQueue.
    int
    startFlowControlled(Response response, int streamId, boolean headRequest, boolean sendDate, boolean sendContentLength, boolean huffmanDynamicValues, boolean emitTableSizeUpdate, int maxFrameSize, long maxHeaderListSize, int availableFlowWindow)
    Starts a response whose DATA may span multiple flow-control windows.
    boolean
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Http2ResponseWriter

      public Http2ResponseWriter()
    • Http2ResponseWriter

      public Http2ResponseWriter(int initialHeaderCapacity, int initialOutputCapacity)
  • Method Details

    • completion

      public void completion(Http2ResponseWriter.Completion completion)
    • prepare

      public boolean prepare(Response response, int streamId, boolean headRequest, boolean sendDate, boolean sendContentLength, boolean huffmanDynamicValues, boolean emitTableSizeUpdate, int maxFrameSize, long maxHeaderListSize, int availableFlowWindow)
      Prepares a non-streaming response. Returns false when the body needs the deferred DATA flow-control path implemented by the stream scheduler.
    • startFlowControlled

      public int startFlowControlled(Response response, int streamId, boolean headRequest, boolean sendDate, boolean sendContentLength, boolean huffmanDynamicValues, boolean emitTableSizeUpdate, int maxFrameSize, long maxHeaderListSize, int availableFlowWindow) throws IOException
      Starts a response whose DATA may span multiple flow-control windows.
      Throws:
      IOException
    • resume

      public int resume(int maxFrameSize, int availableFlowWindow) throws IOException
      Serializes the next DATA batch after a WINDOW_UPDATE or previous write completion.
      Throws:
      IOException
    • abort

      public void abort()
      Closes any in-flight streaming response body still open when the stream is abandoned before finishing (RST_STREAM from the peer, connection teardown) — see Http2Stream.cancel(), the abort-path caller. Normal completion already closes streamBody itself, from appendData(int, int) once end is reached; this covers everything else. A no-op if the response never streamed a body, or already finished/closed.
    • finished

      public boolean finished()
    • headersInBatch

      public boolean headersInBatch()
    • endStreamInBatch

      public boolean endStreamInBatch()
    • dataBytesInBatch

      public int dataBytesInBatch()
    • trailerHeadersInBatch

      public boolean trailerHeadersInBatch()
    • accept

      public void accept(byte[] name, int nameOff, int nameLen, byte[] value, int valueOff, int valueLen)
      Specified by:
      accept in interface ResponseSerializer.FieldConsumer
    • buffer

      public byte[] buffer()
      Description copied from interface: WriteIntent
      The buffer holding this intent's already-serialized bytes.
      Specified by:
      buffer in interface WriteIntent
    • offset

      public int offset()
      Description copied from interface: WriteIntent
      Offset of the first byte to write, within WriteIntent.buffer().
      Specified by:
      offset in interface WriteIntent
    • length

      public int length()
      Description copied from interface: WriteIntent
      Number of bytes to write, starting at WriteIntent.offset().
      Specified by:
      length in interface WriteIntent
    • mpscNext

      public WriteIntent mpscNext()
      Description copied from interface: WriteIntent
      Intrusive MPSC queue linkage — see IntrusiveMpscQueue. Not for external use.
      Specified by:
      mpscNext in interface WriteIntent
    • setMpscNext

      public void setMpscNext(WriteIntent next)
      Description copied from interface: WriteIntent
      Intrusive MPSC queue linkage — see IntrusiveMpscQueue. Not for external use.
      Specified by:
      setMpscNext in interface WriteIntent
    • completed

      public void completed()
      Description copied from interface: WriteIntent
      Called exactly once after this intent leaves the writer, whether the socket write succeeded or failed. Pooled control-frame intents use this hook to return their slot to the owning connection without allocating a completion object.
      Specified by:
      completed in interface WriteIntent