Top Description Inners Fields Constructors Methods
org.glassfish.grizzly.http2

pack-priv Class DefaultOutputSink

extends Object
implements StreamOutputSink
Class Inheritance
All Implemented Interfaces
org.glassfish.grizzly.http2.StreamOutputSink
Static Imports
org.glassfish.grizzly.http2.Termination.OUT_FIN_TERMINATION, java.util.logging.Level.FINE, .Level.WARNING

Default implementation of an output sink, which is associated with specific Http2Stream. The implementation is aligned with HTTP/2 requirements with regards to message flow control.
Author
Alexey Stashok

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
DefaultOutputSink.FlushCompletionHandler

Flush CompletionHandler, which will be passed on each Http2Stream write to make sure the data reached the wires.

private static class

Field Summary

Modifier and TypeField and Description
private final AtomicInteger
private BundleQueue<CompletionHandler<Http2Stream>>
private final Object
private final Http2Session
private volatile boolean
private static final Logger
private static final int
pack-priv final TaskQueue<DefaultOutputSink.OutputQueueRecord>
private final Http2Stream
private static final DefaultOutputSink.OutputQueueRecord
private Termination
private final AtomicInteger
private static final int

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private void
private void
public boolean
private int

Returns:

the amount of data that may be written.
checkOutputWindow
(final long
check the provided size against the window size limit.
size
)

The method is responsible for checking the current output window size.

public synchronized void
close()

Implements org.glassfish.grizzly.http2.StreamOutputSink.close.

Closes the output sink by adding last DataFrame with the FIN flag to a queue.

private DefaultOutputSink.OutputQueueRecord
createOutputQueueRecord(final Buffer data, final HttpContent httpContent, final DefaultOutputSink.FlushCompletionHandler flushCompletionHandler, boolean isLast, final boolean isZeroSizeData)

public void
flush(final CompletionHandler<Http2Stream>
CompletionHandler to be notified
completionHandler
)

Implements org.glassfish.grizzly.http2.StreamOutputSink.flush.

Flush Http2Stream output and notify CompletionHandler once all output data has been flushed.

private void
flushToConnectionOutputSink(final List<Http2Frame> headerFrames, final CompletionHandler<WriteResult<K, L>> completionHandler, final MessageCloner<Buffer> messageCloner, final boolean sendFIN)

private void
flushToConnectionOutputSink(final Buffer data, final DefaultOutputSink.FlushCompletionHandler flushCompletionHandler, final boolean sendFIN)

private void
flushToConnectionOutputSink(final List<Http2Frame> headerFrames, final Buffer data, final CompletionHandler<WriteResult<K, L>> completionHandler, final MessageCloner<Buffer> messageCloner, final boolean sendFIN)

public int
getUnflushedWritesCount()

Implements org.glassfish.grizzly.http2.StreamOutputSink.getUnflushedWritesCount.

Returns: the number of writes (not bytes), that haven't reached network layer

public boolean
private boolean
private boolean
public void
public void
onPeerWindowUpdate(final int
the delta.
delta
)

Implements org.glassfish.grizzly.http2.StreamOutputSink.onPeerWindowUpdate.

The method is called by HTTP2 Filter once WINDOW_UPDATE message comes for this Http2Stream.

private Buffer
prepareDataToSend(final boolean isRecordNull, final boolean isLast, final Buffer data, final boolean isZeroSizeData)

private void
releaseWriteQueueSpace(final int justSentBytes, final boolean isAtomic, final boolean isEndOfChunk)

private int
reserveWriteQueueSpace(final int spaceToReserve)

private void
sendTrailers(final CompletionHandler<WriteResult<K, L>> completionHandler, final HttpTrailer httpContent)

private Buffer
splitOutputBufferIfNeeded(final Buffer buffer, final int length)

public synchronized void
terminate(final Termination terminationFlag)

Implements org.glassfish.grizzly.http2.StreamOutputSink.terminate.

Unlike close() this method forces the output sink termination by setting termination flag and canceling all the pending writes.

public synchronized void
writeDownStream(final HttpPacket
HttpPacket to send
httpPacket
,
final FilterChainContext ctx, final CompletionHandler<WriteResult<K, L>>
the CompletionHandler, which will be notified about write progress.
completionHandler
,
final MessageCloner<Buffer>
the MessageCloner, which will be able to clone the message in case it can't be completely written in the current thread.
messageCloner
)

Implements org.glassfish.grizzly.http2.StreamOutputSink.writeDownStream.

Send an HttpPacket to the Http2Stream.

private DefaultOutputSink.OutputQueueRecord
writeDownStream0(final HttpPacket httpPacket, final FilterChainContext ctx, final CompletionHandler<WriteResult<K, L>> completionHandler, final MessageCloner<Buffer> messageCloner)

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

availStreamWindowSizeback to summary
private final AtomicInteger availStreamWindowSize
flushHandlersQueueback to summary
private BundleQueue<CompletionHandler<Http2Stream>> flushHandlersQueue
flushHandlersSyncback to summary
private final Object flushHandlersSync
http2Sessionback to summary
private final Http2Session http2Session
isLastFrameQueuedback to summary
private volatile boolean isLastFrameQueued
LOGGERback to summary
private static final Logger LOGGER
MAX_OUTPUT_QUEUE_SIZEback to summary
private static final int MAX_OUTPUT_QUEUE_SIZE
outputQueueback to summary
pack-priv final TaskQueue<DefaultOutputSink.OutputQueueRecord> outputQueue
streamback to summary
private final Http2Stream stream
TERMINATING_QUEUE_RECORDback to summary
private static final DefaultOutputSink.OutputQueueRecord TERMINATING_QUEUE_RECORD
terminationFlagback to summary
private Termination terminationFlag
unflushedWritesCounterback to summary
private final AtomicInteger unflushedWritesCounter
ZERO_QUEUE_RECORD_SIZEback to summary
private static final int ZERO_QUEUE_RECORD_SIZE

Constructor Detail

DefaultOutputSinkback to summary
pack-priv DefaultOutputSink(final Http2Stream stream)

Method Detail

addOutputQueueRecordback to summary
private void addOutputQueueRecord(DefaultOutputSink.OutputQueueRecord outputQueueRecord) throws Http2StreamException
assertReadyback to summary
private void assertReady() throws IOException
canWriteback to summary
public boolean canWrite()

Implements org.glassfish.grizzly.http2.StreamOutputSink.canWrite.

Annotations
@Override
checkOutputWindowback to summary
private int checkOutputWindow(final long size)

The method is responsible for checking the current output window size. The returned integer value is the size of the data, which could be sent now.

Parameters
size:long

check the provided size against the window size limit.

Returns:int

the amount of data that may be written.

closeback to summary
public synchronized void close()

Implements org.glassfish.grizzly.http2.StreamOutputSink.close.

Closes the output sink by adding last DataFrame with the FIN flag to a queue. If the output sink is already closed - method does nothing.

Annotations
@Override
createOutputQueueRecordback to summary
private DefaultOutputSink.OutputQueueRecord createOutputQueueRecord(final Buffer data, final HttpContent httpContent, final DefaultOutputSink.FlushCompletionHandler flushCompletionHandler, boolean isLast, final boolean isZeroSizeData)
flushback to summary
public void flush(final CompletionHandler<Http2Stream> completionHandler)

Implements org.glassfish.grizzly.http2.StreamOutputSink.flush.

Flush Http2Stream output and notify CompletionHandler once all output data has been flushed.

Parameters
completionHandler:CompletionHandler<Http2Stream>

CompletionHandler to be notified

Annotations
@Override
flushToConnectionOutputSinkback to summary
private void flushToConnectionOutputSink(final List<Http2Frame> headerFrames, final CompletionHandler<WriteResult<K, L>> completionHandler, final MessageCloner<Buffer> messageCloner, final boolean sendFIN)
flushToConnectionOutputSinkback to summary
private void flushToConnectionOutputSink(final Buffer data, final DefaultOutputSink.FlushCompletionHandler flushCompletionHandler, final boolean sendFIN)
flushToConnectionOutputSinkback to summary
private void flushToConnectionOutputSink(final List<Http2Frame> headerFrames, final Buffer data, final CompletionHandler<WriteResult<K, L>> completionHandler, final MessageCloner<Buffer> messageCloner, final boolean sendFIN)
getUnflushedWritesCountback to summary
public int getUnflushedWritesCount()

Implements org.glassfish.grizzly.http2.StreamOutputSink.getUnflushedWritesCount.

Returns:int

the number of writes (not bytes), that haven't reached network layer

Annotations
@Override
isClosedback to summary
public boolean isClosed()

Implements org.glassfish.grizzly.http2.StreamOutputSink.isClosed.

Annotations
@Override
isTerminatedback to summary
private boolean isTerminated()
isWantToWriteback to summary
private boolean isWantToWrite()
notifyWritePossibleback to summary
public void notifyWritePossible(final WriteHandler writeHandler)

Implements org.glassfish.grizzly.http2.StreamOutputSink.notifyWritePossible.

Annotations
@Override
onPeerWindowUpdateback to summary
public void onPeerWindowUpdate(final int delta) throws Http2StreamException

Implements org.glassfish.grizzly.http2.StreamOutputSink.onPeerWindowUpdate.

The method is called by HTTP2 Filter once WINDOW_UPDATE message comes for this Http2Stream.

Parameters
delta:int

the delta.

Annotations
@Override
Exceptions
Http2StreamException:
if an error occurs processing the window update.
prepareDataToSendback to summary
private Buffer prepareDataToSend(final boolean isRecordNull, final boolean isLast, final Buffer data, final boolean isZeroSizeData)
releaseWriteQueueSpaceback to summary
private void releaseWriteQueueSpace(final int justSentBytes, final boolean isAtomic, final boolean isEndOfChunk)
reserveWriteQueueSpaceback to summary
private int reserveWriteQueueSpace(final int spaceToReserve)
sendTrailersback to summary
private void sendTrailers(final CompletionHandler<WriteResult<K, L>> completionHandler, final HttpTrailer httpContent)
splitOutputBufferIfNeededback to summary
private Buffer splitOutputBufferIfNeeded(final Buffer buffer, final int length)
terminateback to summary
public synchronized void terminate(final Termination terminationFlag)

Implements org.glassfish.grizzly.http2.StreamOutputSink.terminate.

Unlike close() this method forces the output sink termination by setting termination flag and canceling all the pending writes.

Annotations
@Override
writeDownStreamback to summary
public synchronized void writeDownStream(final HttpPacket httpPacket, final FilterChainContext ctx, final CompletionHandler<WriteResult<K, L>> completionHandler, final MessageCloner<Buffer> messageCloner) throws IOException

Implements org.glassfish.grizzly.http2.StreamOutputSink.writeDownStream.

Send an HttpPacket to the Http2Stream. The writeDownStream(...) methods have to be synchronized with shutdown().

Parameters
httpPacket:HttpPacket

HttpPacket to send

completionHandler:CompletionHandler<WriteResult<K, L>>

the CompletionHandler, which will be notified about write progress.

messageCloner:MessageCloner<Buffer>

the MessageCloner, which will be able to clone the message in case it can't be completely written in the current thread.

Annotations
@Override
Exceptions
IOException:
if an error occurs with the write operation.
writeDownStream0back to summary
private DefaultOutputSink.OutputQueueRecord writeDownStream0(final HttpPacket httpPacket, final FilterChainContext ctx, final CompletionHandler<WriteResult<K, L>> completionHandler, final MessageCloner<Buffer> messageCloner) throws IOException
writeEmptyFinback to summary
private void writeEmptyFin()
org.glassfish.grizzly.http2 back to summary

private final Class DefaultOutputSink.FlushCompletionHandler

extends ChunkedCompletionHandler
Class Inheritance

Flush CompletionHandler, which will be passed on each Http2Stream write to make sure the data reached the wires. Usually FlushCompletionHandler is also used as a wrapper for custom CompletionHandler provided by users. The parent class has an internal state, so be careful with reuses of the same instance!

Constructor Summary

AccessConstructor and Description
public
FlushCompletionHandler(final CompletionHandler<WriteResult<K, L>> parentCompletionHandler)

Method Summary

Modifier and TypeMethod and Description
protected void
done0()

Overrides org.glassfish.grizzly.http2.utils.ChunkedCompletionHandler.done0.

Notifies all flush handlers about the completition.

Inherited from org.glassfish.grizzly.http2.utils.ChunkedCompletionHandler:
cancelledcompletedfailedincChunksupdated

Constructor Detail

FlushCompletionHandlerback to summary
public FlushCompletionHandler(final CompletionHandler<WriteResult<K, L>> parentCompletionHandler)

Method Detail

done0back to summary
protected void done0()

Overrides org.glassfish.grizzly.http2.utils.ChunkedCompletionHandler.done0.

Notifies all flush handlers about the completition.

Annotations
@Override
org.glassfish.grizzly.http2 back to summary

private Class DefaultOutputSink.OutputQueueRecord

extends AsyncQueueRecord<WriteResult<K, L>>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private DefaultOutputSink.FlushCompletionHandler
private boolean
private final boolean
private Source
private final HttpTrailer
Inherited from org.glassfish.grizzly.asyncqueue.AsyncQueueRecord:
completionHandlerconnectionisRecycledmessagerecycleTrack

Constructor Summary

AccessConstructor and Description
public
OutputQueueRecord(final Source resource, final DefaultOutputSink.FlushCompletionHandler completionHandler, final boolean isLast, final boolean isZeroSizeData)

public
OutputQueueRecord(final Source resource, final DefaultOutputSink.FlushCompletionHandler completionHandler, final HttpTrailer trailer, final boolean isZeroDataSize)

Method Summary

Modifier and TypeMethod and Description
public WriteResult<K, L>
getCurrentResult()

Implements abstract org.glassfish.grizzly.asyncqueue.AsyncQueueRecord.getCurrentResult.

Returns the current record result object.

private void
public void
public void
public void
private void
reset(final Source resource, final DefaultOutputSink.FlushCompletionHandler completionHandler, final boolean last)

Inherited from org.glassfish.grizzly.asyncqueue.AsyncQueueRecord:
checkRecycledgetConnectiongetMessagenotifyIncompletesetsetMessage

Field Detail

chunkedCompletionHandlerback to summary
private DefaultOutputSink.FlushCompletionHandler chunkedCompletionHandler
isLastback to summary
private boolean isLast
isZeroSizeDataback to summary
private final boolean isZeroSizeData
resourceback to summary
private Source resource
trailerback to summary
private final HttpTrailer trailer

Constructor Detail

OutputQueueRecordback to summary
public OutputQueueRecord(final Source resource, final DefaultOutputSink.FlushCompletionHandler completionHandler, final boolean isLast, final boolean isZeroSizeData)
OutputQueueRecordback to summary
public OutputQueueRecord(final Source resource, final DefaultOutputSink.FlushCompletionHandler completionHandler, final HttpTrailer trailer, final boolean isZeroDataSize)

Method Detail

getCurrentResultback to summary
public WriteResult<K, L> getCurrentResult()

Implements abstract org.glassfish.grizzly.asyncqueue.AsyncQueueRecord.getCurrentResult.

Doc from org.glassfish.grizzly.asyncqueue.AsyncQueueRecord.getCurrentResult.

Returns the current record result object.

Annotations
@Override
incChunksCounterback to summary
private void incChunksCounter()
notifyFailureback to summary
public void notifyFailure(final Throwable e)

Overrides org.glassfish.grizzly.asyncqueue.AsyncQueueRecord.notifyFailure.

Annotations
@Override
recycleback to summary
public void recycle()

Implements org.glassfish.grizzly.Cacheable.recycle.

Annotations
@Override
releaseback to summary
public void release()
resetback to summary
private void reset(final Source resource, final DefaultOutputSink.FlushCompletionHandler completionHandler, final boolean last)