Top Description Inners Fields Constructors Methods
io.undertow.conduits

public Class AbstractFramedStreamSinkConduit

extends AbstractStreamSinkConduit<StreamSinkConduit>
Class Inheritance
Known Direct Subclasses
io.undertow.server.protocol.ajp.AjpServerResponseConduit
Imports
io.undertow.UndertowMessages, org.xnio.Buffers, .IoUtils, io.undertow.connector.PooledByteBuffer, org.xnio.channels.StreamSourceChannel, org.xnio.conduits.AbstractStreamSinkConduit, .ConduitWritableByteChannel, .Conduits, .StreamSinkConduit, java.io.IOException, java.nio.ByteBuffer, java.nio.channels.FileChannel, java.util.ArrayDeque, .Deque

Utility class to ease the implementation of framed protocols. This call provides a queue of frames, and a callback that can be invoked when a frame event occurs.

When a write takes place all frames are attempted to be written out at once via a gathering write. Frames can be queued via queueFrame(io.undertow.conduits.AbstractFramedStreamSinkConduit.FrameCallBack, java.nio.ByteBuffer...).

Author
Stuart Douglas

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
public static interface
AbstractFramedStreamSinkConduit.FrameCallBack

Interface that is called when a frame event takes place.

protected static class
protected static class

Field Summary

Modifier and TypeField and Description
private int
bufferCount

The total number of buffers that have been queued to be written out

private static final int
private static final int
private final Deque<AbstractFramedStreamSinkConduit.Frame>
private long
queuedData

The total amount of data that has been queued to be written out

private int

Constructor Summary

AccessConstructor and Description
protected
AbstractFramedStreamSinkConduit(StreamSinkConduit
the delegate conduit to set
next
)

Construct a new instance.

Method Summary

Modifier and TypeMethod and Description
protected void
private long
doWrite(ByteBuffer[] additionalData, int offs, int len)

protected void
protected boolean
protected boolean
protected void
protected long
protected void
queueFrame(AbstractFramedStreamSinkConduit.FrameCallBack callback, ByteBuffer... data)

Queues a frame for sending.

public void
public long
transferFrom(final FileChannel
the file to read from
src
,
final long
the position within the file from which the transfer is to begin
position
,
final 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(final StreamSourceChannel
the source to read from
source
,
final long
the number of bytes to be transferred
count
,
final 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 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 long
write(ByteBuffer[]
the buffers containing data to write
srcs
,
int
the offset into the buffer array
offs
,
int
the number of buffers to write
len
)

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
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
offs
,
int
The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offset
len
)

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

bufferCountback to summary
private int bufferCount

The total number of buffers that have been queued to be written out

FLAG_DELEGATE_SHUTDOWNback to summary
private static final int FLAG_DELEGATE_SHUTDOWN
FLAG_WRITES_TERMINATEDback to summary
private static final int FLAG_WRITES_TERMINATED
frameQueueback to summary
private final Deque<AbstractFramedStreamSinkConduit.Frame> frameQueue
queuedDataback to summary
private long queuedData

The total amount of data that has been queued to be written out

stateback to summary
private int state

Constructor Detail

AbstractFramedStreamSinkConduitback to summary
protected AbstractFramedStreamSinkConduit(StreamSinkConduit next)

Construct a new instance.

Parameters
next:StreamSinkConduit

the delegate conduit to set

Method Detail

doTerminateWritesback to summary
protected void doTerminateWrites() throws IOException
doWriteback to summary
private long doWrite(ByteBuffer[] additionalData, int offs, int len) throws IOException
finishedback to summary
protected void finished()
flushQueuedDataback to summary
protected boolean flushQueuedData() throws IOException
isWritesTerminatedback to summary
protected boolean isWritesTerminated()
queueCloseFramesback to summary
protected void queueCloseFrames()
queuedDataLengthback to summary
protected long queuedDataLength()
queueFrameback to summary
protected void queueFrame(AbstractFramedStreamSinkConduit.FrameCallBack callback, ByteBuffer... data)

Queues a frame for sending.

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(final FileChannel src, final long position, final 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

Exceptions
IOException:
if an I/O error occurs
transferFromback to summary
public long transferFrom(final StreamSourceChannel source, final long count, final 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

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.

Annotations
@Override
Exceptions
IOException:
if channel termination failed for some reason
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
writeback to summary
public long write(ByteBuffer[] srcs, int offs, int len) 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

offs:int

the offset into the buffer array

len:int

the number of buffers to write

Returns:long

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 offs, int len) 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

offs: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

len: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
io.undertow.conduits back to summary

private Class AbstractFramedStreamSinkConduit.Frame

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final AbstractFramedStreamSinkConduit.FrameCallBack
pack-priv final ByteBuffer[]
pack-priv final int
pack-priv final int
pack-priv long

Constructor Summary

AccessConstructor and Description
private
Frame(AbstractFramedStreamSinkConduit.FrameCallBack callback, ByteBuffer[] data, int offs, int len)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

callbackback to summary
pack-priv final AbstractFramedStreamSinkConduit.FrameCallBack callback
databack to summary
pack-priv final ByteBuffer[] data
lenback to summary
pack-priv final int len
offsback to summary
pack-priv final int offs
remainingback to summary
pack-priv long remaining

Constructor Detail

Frameback to summary
private Frame(AbstractFramedStreamSinkConduit.FrameCallBack callback, ByteBuffer[] data, int offs, int len)
io.undertow.conduits back to summary

public Interface AbstractFramedStreamSinkConduit.FrameCallBack

Known Direct Implementers
io.undertow.conduits.AbstractFramedStreamSinkConduit.PooledBufferFrameCallback, io.undertow.conduits.AbstractFramedStreamSinkConduit.PooledBuffersFrameCallback

Interface that is called when a frame event takes place. The events are:

Method Summary

Modifier and TypeMethod and Description
public void
done()

public void

Method Detail

doneback to summary
public void done()
failedback to summary
public void failed(final IOException e)
io.undertow.conduits back to summary

protected Class AbstractFramedStreamSinkConduit.PooledBufferFrameCallback

extends Object
implements FrameCallBack
Class Inheritance
  • java.lang.Object
  • io.undertow.conduits.AbstractFramedStreamSinkConduit.PooledBufferFrameCallback
All Implemented Interfaces
io.undertow.conduits.AbstractFramedStreamSinkConduit.FrameCallBack

Field Summary

Modifier and TypeField and Description
private final PooledByteBuffer

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferback to summary
private final PooledByteBuffer buffer

Constructor Detail

PooledBufferFrameCallbackback to summary
public PooledBufferFrameCallback(PooledByteBuffer buffer)

Method Detail

doneback to summary
public void done()

Implements io.undertow.conduits.AbstractFramedStreamSinkConduit.FrameCallBack.done.

Annotations
@Override
failedback to summary
public void failed(IOException e)

Implements io.undertow.conduits.AbstractFramedStreamSinkConduit.FrameCallBack.failed.

Annotations
@Override
io.undertow.conduits back to summary

protected Class AbstractFramedStreamSinkConduit.PooledBuffersFrameCallback

extends Object
implements FrameCallBack
Class Inheritance
  • java.lang.Object
  • io.undertow.conduits.AbstractFramedStreamSinkConduit.PooledBuffersFrameCallback
All Implemented Interfaces
io.undertow.conduits.AbstractFramedStreamSinkConduit.FrameCallBack

Field Summary

Modifier and TypeField and Description
private final PooledByteBuffer[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

buffersback to summary
private final PooledByteBuffer[] buffers

Constructor Detail

PooledBuffersFrameCallbackback to summary
public PooledBuffersFrameCallback(PooledByteBuffer... buffers)

Method Detail

doneback to summary
public void done()

Implements io.undertow.conduits.AbstractFramedStreamSinkConduit.FrameCallBack.done.

Annotations
@Override
failedback to summary
public void failed(IOException e)

Implements io.undertow.conduits.AbstractFramedStreamSinkConduit.FrameCallBack.failed.

Annotations
@Override