Package dev.relism.flash.http2.message
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(byte[] name, int nameOff, int nameLen, byte[] value, int valueOff, int valueLen) byte[]buffer()The buffer holding this intent's already-serialized bytes.voidCalled exactly once after this intent leaves the writer, whether the socket write succeeded or failed.voidcompletion(Http2ResponseWriter.Completion completion) intbooleanbooleanfinished()booleanintlength()Number of bytes to write, starting atWriteIntent.offset().mpscNext()Intrusive MPSC queue linkage — seeIntrusiveMpscQueue.intoffset()Offset of the first byte to write, withinWriteIntent.buffer().booleanprepare(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.intresume(int maxFrameSize, int availableFlowWindow) Serializes the next DATA batch after a WINDOW_UPDATE or previous write completion.voidsetMpscNext(WriteIntent next) Intrusive MPSC queue linkage — seeIntrusiveMpscQueue.intstartFlowControlled(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
-
Constructor Details
-
Http2ResponseWriter
public Http2ResponseWriter() -
Http2ResponseWriter
public Http2ResponseWriter(int initialHeaderCapacity, int initialOutputCapacity)
-
-
Method Details
-
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. Returnsfalsewhen 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
Serializes the next DATA batch after a WINDOW_UPDATE or previous write completion.- Throws:
IOException
-
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:
acceptin interfaceResponseSerializer.FieldConsumer
-
buffer
public byte[] buffer()Description copied from interface:WriteIntentThe buffer holding this intent's already-serialized bytes.- Specified by:
bufferin interfaceWriteIntent
-
offset
public int offset()Description copied from interface:WriteIntentOffset of the first byte to write, withinWriteIntent.buffer().- Specified by:
offsetin interfaceWriteIntent
-
length
public int length()Description copied from interface:WriteIntentNumber of bytes to write, starting atWriteIntent.offset().- Specified by:
lengthin interfaceWriteIntent
-
mpscNext
Description copied from interface:WriteIntentIntrusive MPSC queue linkage — seeIntrusiveMpscQueue. Not for external use.- Specified by:
mpscNextin interfaceWriteIntent
-
setMpscNext
Description copied from interface:WriteIntentIntrusive MPSC queue linkage — seeIntrusiveMpscQueue. Not for external use.- Specified by:
setMpscNextin interfaceWriteIntent
-
completed
public void completed()Description copied from interface:WriteIntentCalled 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:
completedin interfaceWriteIntent
-