Top Description Inners Fields Constructors Methods
org.eclipse.jetty.io.content

public Class BufferedContentSink

extends Object
implements Sink
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.io.Content.Sink
Imports
java.io.IOException, java.nio.ByteBuffer, java.nio.channels.WritePendingException, org.eclipse.jetty.io.ByteBufferAggregator, .ByteBufferPool, .Content, .RetainableByteBuffer, org.eclipse.jetty.util.BufferUtil, .Callback, .IteratingCallback, org.slf4j.Logger, .LoggerFactory

A Content.Sink backed by another Content.Sink. Any content written to this Content.Sink is buffered, then written to the delegate using Content.Sink#write(boolean, ByteBuffer, Callback).

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private ByteBufferAggregator
private final ByteBufferPool
private final Content.Sink
private final boolean
private boolean
private final BufferedContentSink.Flusher
private boolean
private final int
private final int
public static final ByteBuffer
FLUSH_BUFFER

An empty ByteBuffer, which if written will invoke a flush(Callback) operation.

private static final Logger
private static final int

Constructor Summary

AccessConstructor and Description
public
BufferedContentSink(Content.Sink delegate, ByteBufferPool bufferPool, boolean direct, int maxAggregationSize, int maxBufferSize)

Method Summary

Modifier and TypeMethod and Description
private void
aggregateAndFlush(boolean last, ByteBuffer currentBuffer, Callback callback)

Aggregates the given buffer, flushing the aggregated buffer if necessary.

public void
flush(Callback
Callback completed when the flush is complete
callback
)

Flush the buffered content.

private void
flush(boolean last, ByteBuffer currentBuffer, Callback callback)

Flushes the aggregated buffer if something was aggregated, then flushes the given buffer, bypassing the aggregator.

public void
write(boolean
whether the ByteBuffer is the last to write
last
,
ByteBuffer
the ByteBuffer to write
byteBuffer
,
Callback
the callback to notify when the write operation is complete
callback
)

Implements org.eclipse.jetty.io.Content.Sink.write.

Writes the given ByteBuffer, notifying the Callback when the write is complete.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_aggregatorback to summary
private ByteBufferAggregator _aggregator
_bufferPoolback to summary
private final ByteBufferPool _bufferPool
_delegateback to summary
private final Content.Sink _delegate
_directback to summary
private final boolean _direct
_firstWriteback to summary
private boolean _firstWrite
_flusherback to summary
private final BufferedContentSink.Flusher _flusher
_lastWrittenback to summary
private boolean _lastWritten
_maxAggregationSizeback to summary
private final int _maxAggregationSize
_maxBufferSizeback to summary
private final int _maxBufferSize
FLUSH_BUFFERback to summary
public static final ByteBuffer FLUSH_BUFFER

An empty ByteBuffer, which if written will invoke a flush(Callback) operation.

LOGback to summary
private static final Logger LOG
START_BUFFER_SIZEback to summary
private static final int START_BUFFER_SIZE

Constructor Detail

BufferedContentSinkback to summary
public BufferedContentSink(Content.Sink delegate, ByteBufferPool bufferPool, boolean direct, int maxAggregationSize, int maxBufferSize)

Method Detail

aggregateAndFlushback to summary
private void aggregateAndFlush(boolean last, ByteBuffer currentBuffer, Callback callback)

Aggregates the given buffer, flushing the aggregated buffer if necessary.

flushback to summary
public void flush(Callback callback)

Flush the buffered content.

Parameters
callback:Callback

Callback completed when the flush is complete

flushback to summary
private void flush(boolean last, ByteBuffer currentBuffer, Callback callback)

Flushes the aggregated buffer if something was aggregated, then flushes the given buffer, bypassing the aggregator.

writeback to summary
public void write(boolean last, ByteBuffer byteBuffer, Callback callback)

Implements org.eclipse.jetty.io.Content.Sink.write.

Doc from org.eclipse.jetty.io.Content.Sink.write.

Writes the given ByteBuffer, notifying the Callback when the write is complete.

Implementations guarantee that calls to this method are safely reentrant so that stack overflows are avoided in the case of mutual recursion between the execution of the Callback and a call to this method.

Parameters
last:boolean

whether the ByteBuffer is the last to write

byteBuffer:ByteBuffer

the ByteBuffer to write

callback:Callback

the callback to notify when the write operation is complete

Annotations
@Override
org.eclipse.jetty.io.content back to summary

private Class BufferedContentSink.Flusher

extends IteratingCallback
Class Inheritance

Field Summary

Modifier and TypeField and Description
private ByteBuffer
private Callback
private boolean
private boolean
private final Content.Sink
private static final ByteBuffer

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv void
offer(Callback callback)

pack-priv void
offer(boolean last, ByteBuffer byteBuffer, Callback callback)

protected void
onCompleteFailure(Throwable
the throwable to indicate cause of failure
cause
)

Overrides org.eclipse.jetty.util.IteratingCallback.onCompleteFailure.

Invoked when the overall task has completed with a failure.
protected IteratingCallback.Action
process()

Implements abstract org.eclipse.jetty.util.IteratingCallback.process.

Method called by iterate() to process the asynchronous sub-task.
public void
succeeded()

Overrides org.eclipse.jetty.util.IteratingCallback.succeeded.

Overrides default org.eclipse.jetty.util.Callback.succeeded.

Method to invoke when the asynchronous sub-task succeeds.
Inherited from org.eclipse.jetty.util.IteratingCallback:
abortclosefailedisAbortedisClosedisFailedisSucceedediterateonCompleteSuccessresettoString

Field Detail

_bufferback to summary
private ByteBuffer _buffer
_callbackback to summary
private Callback _callback
_lastback to summary
private boolean _last
_lastWrittenback to summary
private boolean _lastWritten
_sinkback to summary
private final Content.Sink _sink
COMPLETE_CALLBACKback to summary
private static final ByteBuffer COMPLETE_CALLBACK

Constructor Detail

Flusherback to summary
pack-priv Flusher(Content.Sink sink)

Method Detail

offerback to summary
pack-priv void offer(Callback callback)
offerback to summary
pack-priv void offer(boolean last, ByteBuffer byteBuffer, Callback callback)
onCompleteFailureback to summary
protected void onCompleteFailure(Throwable cause)

Overrides org.eclipse.jetty.util.IteratingCallback.onCompleteFailure.

Doc from org.eclipse.jetty.util.IteratingCallback.onCompleteFailure.

Invoked when the overall task has completed with a failure.

Parameters
cause:Throwable

the throwable to indicate cause of failure

Annotations
@Override
processback to summary
protected IteratingCallback.Action process()

Implements abstract org.eclipse.jetty.util.IteratingCallback.process.

Doc from org.eclipse.jetty.util.IteratingCallback.process.

Method called by iterate() to process the asynchronous sub-task.

Implementations must initiate the asynchronous execution of the sub-task (if any) and return an appropriate action:

  • Action#IDLE when no sub tasks are available for execution but the overall job is not completed yet
  • Action#SCHEDULED when the sub task asynchronous execution has been started
  • Action#SUCCEEDED when the overall job is completed
Returns:IteratingCallback.Action

the appropriate Action

Annotations
@Override
succeededback to summary
public void succeeded()

Overrides org.eclipse.jetty.util.IteratingCallback.succeeded.

Overrides default org.eclipse.jetty.util.Callback.succeeded.

Doc from org.eclipse.jetty.util.IteratingCallback.succeeded.

Method to invoke when the asynchronous sub-task succeeds.

Subclasses that override this method must always remember to call super.succeeded().

Annotations
@Override