Top Description Fields Constructors Methods
io.undertow.server.protocol.http

public Class PipeliningBufferingStreamSinkConduit

extends AbstractStreamSinkConduit<StreamSinkConduit>
Class Inheritance
Imports
java.io.IOException, java.nio.ByteBuffer, java.nio.channels.Channel, .ClosedChannelException, .FileChannel, java.util.concurrent.TimeUnit, io.undertow.UndertowLogger, io.undertow.server.HttpServerExchange, org.xnio.Buffers, .ChannelListener, .IoUtils, .StreamConnection, io.undertow.connector.ByteBufferPool, .PooledByteBuffer, org.xnio.channels.StreamSourceChannel, org.xnio.conduits.AbstractStreamSinkConduit, .ConduitWritableByteChannel, .Conduits, .StreamSinkConduit

A buffer that is used when processing pipelined requests, that allows the server to buffer multiple responses into a single write() call.

This can improve performance when pipelining requests.

Author
Stuart Douglas

Field Summary

Modifier and TypeField and Description
private PooledByteBuffer
private static final int
private static final int
private final ByteBufferPool
private static final int
SHUTDOWN

If this channel is shutdown

private int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
awaitWritable(long
the time to wait
time
,
TimeUnit
the time unit
timeUnit
)

Overrides org.xnio.conduits.AbstractSinkConduit.awaitWritable.

Implements org.xnio.conduits.SinkConduit.awaitWritable.

Block until this conduit becomes writable again, or until the timeout expires.

public void
awaitWritable()

Overrides org.xnio.conduits.AbstractSinkConduit.awaitWritable.

Implements org.xnio.conduits.SinkConduit.awaitWritable.

Block until this channel becomes writable again.

public void
public boolean
flush()

Overrides org.xnio.conduits.AbstractSinkConduit.flush.

Implements org.xnio.conduits.SinkConduit.flush.

Flush out any unwritten, buffered output.

private boolean
private long
flushBufferWithUserData(final ByteBuffer[] byteBuffers, int offset, int length)

public boolean

Returns:

true If the flush succeeded, false otherwise
flushPipelinedData
()

Flushes the cached data.

pack-priv void
performFlush(final HttpServerExchange exchange, final HttpServerConnection connection)

public void
setupPipelineBuffer(final HttpServerExchange exchange)

Gets the channel wrapper that implements the buffering

public void
public long
transferFrom(FileChannel
the file to read from
src
,
long
the position within the file from which the transfer is to begin
position
,
long
the number of bytes to be transferred
count
)

Overrides org.xnio.conduits.AbstractStreamSinkConduit.transferFrom.

Implements org.xnio.conduits.StreamSinkConduit.transferFrom.

Transfer bytes into this conduit from the given file.

public long
transferFrom(StreamSourceChannel
the source to read from
source
,
long
the number of bytes to be transferred
count
,
ByteBuffer
the buffer to copy through.
throughBuffer
)

Overrides org.xnio.conduits.AbstractStreamSinkConduit.transferFrom.

Implements org.xnio.conduits.StreamSinkConduit.transferFrom.

Transfers bytes from the given channel source.

public void
truncateWrites()

Overrides org.xnio.conduits.AbstractSinkConduit.truncateWrites.

Implements org.xnio.conduits.SinkConduit.truncateWrites.

Terminate writes and discard any outstanding write data.

public long
write(ByteBuffer[]
the buffers containing data to write
srcs
,
int
the offset into the buffer array
offset
,
int
the number of buffers to write
length
)

Overrides org.xnio.conduits.AbstractStreamSinkConduit.write.

Implements org.xnio.conduits.StreamSinkConduit.write.

Writes a sequence of bytes to this conduit from the given buffers.

public int
write(ByteBuffer
the buffer containing data to write
src
)

Overrides org.xnio.conduits.AbstractStreamSinkConduit.write.

Implements org.xnio.conduits.StreamSinkConduit.write.

Writes a sequence of bytes to this conduit from the given buffer.

public int
writeFinal(ByteBuffer
The data to write
src
)

Overrides org.xnio.conduits.AbstractStreamSinkConduit.writeFinal.

Implements org.xnio.conduits.StreamSinkConduit.writeFinal.

Writes some data to the conduit, with the same semantics as write(java.nio.ByteBuffer).

public long
writeFinal(ByteBuffer[]
The buffers from which bytes are to be retrieved
srcs
,
int
The offset within the buffer array of the first buffer from which bytes are to be retrieved; must be non-negative and no larger than srcs.length
offset
,
int
The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offset
length
)

Overrides org.xnio.conduits.AbstractStreamSinkConduit.writeFinal.

Implements org.xnio.conduits.StreamSinkConduit.writeFinal.

Writes some data to the conduit, with the same semantics as write(java.nio.ByteBuffer[], int, int).

Field Detail

bufferback to summary
private PooledByteBuffer buffer
DELEGATE_SHUTDOWNback to summary
private static final int DELEGATE_SHUTDOWN
FLUSHINGback to summary
private static final int FLUSHING
poolback to summary
private final ByteBufferPool pool
SHUTDOWNback to summary
private static final int SHUTDOWN

If this channel is shutdown

stateback to summary
private int state

Constructor Detail

PipeliningBufferingStreamSinkConduitback to summary
public PipeliningBufferingStreamSinkConduit(StreamSinkConduit next, final ByteBufferPool pool)

Method Detail

awaitWritableback to summary
public void awaitWritable(long time, TimeUnit timeUnit) throws IOException

Overrides org.xnio.conduits.AbstractSinkConduit.awaitWritable.

Implements org.xnio.conduits.SinkConduit.awaitWritable.

Doc from org.xnio.conduits.SinkConduit.awaitWritable.

Block until this conduit becomes writable again, or until the timeout expires. This method may return spuriously before the conduit becomes writable or the timeout expires.

Parameters
time:long

the time to wait

timeUnit:TimeUnit

the time unit

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
awaitWritableback to summary
public void awaitWritable() throws IOException

Overrides org.xnio.conduits.AbstractSinkConduit.awaitWritable.

Implements org.xnio.conduits.SinkConduit.awaitWritable.

Doc from org.xnio.conduits.SinkConduit.awaitWritable.

Block until this channel becomes writable again. This method may return spuriously before the channel becomes writable.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
exchangeCompleteback to summary
public void exchangeComplete(final HttpServerExchange exchange)
flushback to summary
public boolean flush() throws IOException

Overrides org.xnio.conduits.AbstractSinkConduit.flush.

Implements org.xnio.conduits.SinkConduit.flush.

Doc from org.xnio.conduits.SinkConduit.flush.

Flush out any unwritten, buffered output.

Returns:boolean

true if everything is flushed, false otherwise

Annotations
@Override
Exceptions
IOException:
if flush fails
flushBufferback to summary
private boolean flushBuffer() throws IOException
flushBufferWithUserDataback to summary
private long flushBufferWithUserData(final ByteBuffer[] byteBuffers, int offset, int length) throws IOException
flushPipelinedDataback to summary
public boolean flushPipelinedData() throws IOException

Flushes the cached data.

This should be called when a read thread fails to read any more request data, to make sure that any buffered data is flushed after the last pipelined request.

If this returns false the read thread should suspend reads and resume writes

Returns:boolean

true If the flush succeeded, false otherwise

performFlushback to summary
pack-priv void performFlush(final HttpServerExchange exchange, final HttpServerConnection connection)
setupPipelineBufferback to summary
public void setupPipelineBuffer(final HttpServerExchange exchange)

Gets the channel wrapper that implements the buffering

terminateWritesback to summary
public void terminateWrites() throws IOException

Overrides org.xnio.conduits.AbstractSinkConduit.terminateWrites.

Implements org.xnio.conduits.SinkConduit.terminateWrites.

Doc from org.xnio.conduits.SinkConduit.terminateWrites.

Signal that no more write data is forthcoming. The conduit must be flush()ed before it is considered to be shut down.

Annotations
@Override
transferFromback to summary
public long transferFrom(FileChannel src, long position, long count) throws IOException

Overrides org.xnio.conduits.AbstractStreamSinkConduit.transferFrom.

Implements org.xnio.conduits.StreamSinkConduit.transferFrom.

Doc from org.xnio.conduits.StreamSinkConduit.transferFrom.

Transfer bytes into this conduit from the given file.

Parameters
src:FileChannel

the file to read from

position:long

the position within the file from which the transfer is to begin

count:long

the number of bytes to be transferred

Returns:long

the number of bytes (possibly 0) that were actually transferred

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
transferFromback to summary
public long transferFrom(StreamSourceChannel source, long count, ByteBuffer throughBuffer) throws IOException

Overrides org.xnio.conduits.AbstractStreamSinkConduit.transferFrom.

Implements org.xnio.conduits.StreamSinkConduit.transferFrom.

Doc from org.xnio.conduits.StreamSinkConduit.transferFrom.

Transfers bytes from the given channel source. On entry, throughBuffer will be cleared. On exit, the buffer will be flipped for emptying, and may be empty or may contain data. If this method returns a value less than count, then the remaining data in throughBuffer may contain data read from source which must be written to this channel to complete the operation.

Parameters
source:StreamSourceChannel

the source to read from

count:long

the number of bytes to be transferred

throughBuffer:ByteBuffer

the buffer to copy through.

Returns:long

the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
truncateWritesback to summary
public void truncateWrites() throws IOException

Overrides org.xnio.conduits.AbstractSinkConduit.truncateWrites.

Implements org.xnio.conduits.SinkConduit.truncateWrites.

Doc from org.xnio.conduits.SinkConduit.truncateWrites.

Terminate writes and discard any outstanding write data. The conduit is terminated and flushed regardless of the outcome of this method.

Exceptions
IOException:
if channel termination failed for some reason
writeback to summary
public long write(ByteBuffer[] srcs, int offset, int length) throws IOException

Overrides org.xnio.conduits.AbstractStreamSinkConduit.write.

Implements org.xnio.conduits.StreamSinkConduit.write.

Doc from org.xnio.conduits.StreamSinkConduit.write.

Writes a sequence of bytes to this conduit from the given buffers.

Parameters
srcs:ByteBuffer[]

the buffers containing data to write

offset:int

the offset into the buffer array

length:int

the number of buffers to write

Returns:long

the number of bytes written, possibly 0

Annotations
@Override
Exceptions
IOException:
if an error occurs
writeback to summary
public int write(ByteBuffer src) throws IOException

Overrides org.xnio.conduits.AbstractStreamSinkConduit.write.

Implements org.xnio.conduits.StreamSinkConduit.write.

Doc from org.xnio.conduits.StreamSinkConduit.write.

Writes a sequence of bytes to this conduit from the given buffer.

Parameters
src:ByteBuffer

the buffer containing data to write

Returns:int

the number of bytes written, possibly 0

Annotations
@Override
Exceptions
IOException:
if an error occurs
writeFinalback to summary
public int writeFinal(ByteBuffer src) throws IOException

Overrides org.xnio.conduits.AbstractStreamSinkConduit.writeFinal.

Implements org.xnio.conduits.StreamSinkConduit.writeFinal.

Doc from org.xnio.conduits.StreamSinkConduit.writeFinal.

Writes some data to the conduit, with the same semantics as write(java.nio.ByteBuffer). If all the data is written out then the conduit will have its writes terminated. Semantically this method is equivalent to: int rem = src.remaining(); int written = conduit.write(src); if(written == rem) { conduit.terminateWrites() }

Parameters
src:ByteBuffer

The data to write

Returns:int

The amount of data that was actually written.

Annotations
@Override
writeFinalback to summary
public long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException

Overrides org.xnio.conduits.AbstractStreamSinkConduit.writeFinal.

Implements org.xnio.conduits.StreamSinkConduit.writeFinal.

Doc from org.xnio.conduits.StreamSinkConduit.writeFinal.

Writes some data to the conduit, with the same semantics as write(java.nio.ByteBuffer[], int, int). If all the data is written out then the conduit will have its writes terminated.

Parameters
srcs:ByteBuffer[]

The buffers from which bytes are to be retrieved

offset:int

The offset within the buffer array of the first buffer from which bytes are to be retrieved; must be non-negative and no larger than srcs.length

length:int

The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offset

Returns:long

The amount of data that was actually written

Annotations
@Override