Top Description Inners Fields Constructors Methods
io.undertow.channels

public abstract Class DetachableStreamSinkChannel

extends Object
implements StreamSinkChannel
Class Inheritance
All Implemented Interfaces
org.xnio.channels.StreamSinkChannel, org.xnio.channels.SuspendableWriteChannel, org.xnio.channels.CloseableChannel, org.xnio.channels.Configurable, java.nio.channels.InterruptibleChannel, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.GatheringByteChannel, java.nio.channels.WritableByteChannel
Known Direct Subclasses
io.undertow.server.HttpServerExchange.WriteDispatchChannel
Imports
io.undertow.UndertowLogger, .UndertowMessages, org.xnio.ChannelListener, .ChannelListeners, .Option, .XnioExecutor, .XnioIoThread, .XnioWorker, org.xnio.channels.StreamSinkChannel, .StreamSourceChannel, org.xnio.conduits.ConduitStreamSinkChannel, java.io.IOException, java.nio.ByteBuffer, java.nio.channels.FileChannel, java.util.concurrent.TimeUnit

Stream sink channel. When this channel is considered detached it will no longer forward calls to the delegate
Author
Stuart Douglas

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
protected ChannelListener.SimpleSetter<DetachableStreamSinkChannel>
protected final StreamSinkChannel
protected ChannelListener.SimpleSetter<DetachableStreamSinkChannel>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
awaitWritable()

Implements org.xnio.channels.SuspendableWriteChannel.awaitWritable.

Block until this channel becomes writable again.

public void
awaitWritable(final long
the time to wait
time
,
final TimeUnit
the time unit
timeUnit
)

Implements org.xnio.channels.SuspendableWriteChannel.awaitWritable.

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

public void
public boolean
flush()

Implements org.xnio.channels.SuspendableWriteChannel.flush.

Flush any waiting partial send or write.

public ChannelListener.Setter<? extends StreamSinkChannel>
getCloseSetter()

Implements org.xnio.channels.StreamSinkChannel.getCloseSetter.

Get the setter which can be used to change the close listener for this channel.

public XnioIoThread
getIoThread()

Implements org.xnio.channels.CloseableChannel.getIoThread.

Get the I/O thread associated with this channel.

public <T> T
getOption(final Option<T>
the option to get
option
)

Implements org.xnio.channels.Configurable.getOption.

Get the value of a channel option.

public XnioWorker
getWorker()

Implements org.xnio.channels.CloseableChannel.getWorker.

Get the worker for this channel.

public ChannelListener.Setter<? extends StreamSinkChannel>
getWriteSetter()

Implements org.xnio.channels.StreamSinkChannel.getWriteSetter.

Get the setter which can be used to change the write listener for this channel.

public XnioExecutor
getWriteThread()

Implements org.xnio.channels.SuspendableWriteChannel.getWriteThread.

Get the write thread for this channel.

protected abstract boolean
public boolean
public boolean
isWriteResumed()

Implements org.xnio.channels.SuspendableWriteChannel.isWriteResumed.

Determine whether writes are resumed.

public void
public void
resumeWrites()

Implements org.xnio.channels.SuspendableWriteChannel.resumeWrites.

Resume writes on this channel.

public <T> T
setOption(final Option<T>
the option to set
option
,
final T
the value of the option to set
value
)

Implements org.xnio.channels.Configurable.setOption.

Set an option for this channel.

public void
shutdownWrites()

Implements org.xnio.channels.SuspendableWriteChannel.shutdownWrites.

Indicate that writing is complete for this channel.

public boolean
supportsOption(final Option<?>
the option
option
)

Implements org.xnio.channels.Configurable.supportsOption.

Determine whether an option is supported on this channel.

public void
suspendWrites()

Implements org.xnio.channels.SuspendableWriteChannel.suspendWrites.

Suspend further write notifications on this channel.

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
)

Implements org.xnio.channels.StreamSinkChannel.transferFrom.

Transfer bytes into this channel 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
)

Implements org.xnio.channels.StreamSinkChannel.transferFrom.

Transfers bytes from the given channel source.

public void
wakeupWrites()

Implements org.xnio.channels.SuspendableWriteChannel.wakeupWrites.

Resume writes on this channel, and force the write listener to be triggered even if the channel isn't actually writable.

public long
write(final ByteBuffer[]
The buffers from which bytes are to be retrieved
srcs
,
final 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
,
final int
The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offset
length
)

Implements java.nio.channels.GatheringByteChannel.write.

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

public long
write(final ByteBuffer[]
The buffers from which bytes are to be retrieved
srcs
)

Implements java.nio.channels.GatheringByteChannel.write.

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

public int
write(final ByteBuffer
The buffer from which bytes are to be retrieved
src
)

Implements java.nio.channels.WritableByteChannel.write.

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

public int
writeFinal(ByteBuffer
The data to write
src
)

Implements org.xnio.channels.StreamSinkChannel.writeFinal.

Writes some data to the channel, 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
)

Implements org.xnio.channels.StreamSinkChannel.writeFinal.

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

public long
writeFinal(ByteBuffer[]
The buffers from which bytes are to be retrieved
srcs
)

Implements org.xnio.channels.StreamSinkChannel.writeFinal.

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

closeSetterback to summary
protected ChannelListener.SimpleSetter<DetachableStreamSinkChannel> closeSetter
delegateback to summary
protected final StreamSinkChannel delegate
writeSetterback to summary
protected ChannelListener.SimpleSetter<DetachableStreamSinkChannel> writeSetter

Constructor Detail

DetachableStreamSinkChannelback to summary
public DetachableStreamSinkChannel(final StreamSinkChannel delegate)

Method Detail

awaitWritableback to summary
public void awaitWritable() throws IOException

Implements org.xnio.channels.SuspendableWriteChannel.awaitWritable.

Doc from org.xnio.channels.SuspendableWriteChannel.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
awaitWritableback to summary
public void awaitWritable(final long time, final TimeUnit timeUnit) throws IOException

Implements org.xnio.channels.SuspendableWriteChannel.awaitWritable.

Doc from org.xnio.channels.SuspendableWriteChannel.awaitWritable.

Block until this channel becomes writable again, or until the timeout expires. This method may return spuriously before the channel 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
closeback to summary
public void close() throws IOException

Implements java.nio.channels.Channel.close, org.xnio.channels.SuspendableWriteChannel.close.

Doc from org.xnio.channels.SuspendableWriteChannel.close.

Close this channel. If data has been written but not flushed, that data may be discarded, depending on the channel implementation. When a channel is closed, its close listener is invoked. Invoking this method more than once has no additional effect.

Annotations
@Override
Exceptions
IOException:
if the close failed
flushback to summary
public boolean flush() throws IOException

Implements org.xnio.channels.SuspendableWriteChannel.flush.

Doc from org.xnio.channels.SuspendableWriteChannel.flush.

Flush any waiting partial send or write. If there is no data to flush, or if the flush completed successfully, this method will return true. If there is data to flush which cannot be immediately written, this method will return false. If this method returns true after shutdownWrites() was called on this channel, the write listener will no longer be invoked on this channel. If this is case and additionally this is a write-only channel or the read side was previously shut down, then the channel will automatically be closed.

Returns:boolean

true if the message was flushed, or false if the result would block

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
getCloseSetterback to summary
public ChannelListener.Setter<? extends StreamSinkChannel> getCloseSetter()

Implements org.xnio.channels.StreamSinkChannel.getCloseSetter.

Doc from org.xnio.channels.StreamSinkChannel.getCloseSetter.

Get the setter which can be used to change the close listener for this channel. If the channel is already closed, then the listener will not be called.

Returns:ChannelListener.Setter<? extends StreamSinkChannel>

Doc from org.xnio.channels.CloseableChannel.getCloseSetter.

the setter

Annotations
@Override
getIoThreadback to summary
public XnioIoThread getIoThread()

Implements org.xnio.channels.CloseableChannel.getIoThread.

Doc from org.xnio.channels.CloseableChannel.getIoThread.

Get the I/O thread associated with this channel.

Returns:XnioIoThread

the I/O thread associated with this channel

Annotations
@Override
getOptionback to summary
public <T> T getOption(final Option<T> option) throws IOException

Implements org.xnio.channels.Configurable.getOption.

Doc from org.xnio.channels.Configurable.getOption.

Get the value of a channel option.

Parameters
<T>
the type of the option value
option:Option<T>

the option to get

Returns:T

the value of the option, or null if it is not set

Annotations
@Override
Exceptions
IOException:
if an I/O error occurred when reading the option
getWorkerback to summary
public XnioWorker getWorker()

Implements org.xnio.channels.CloseableChannel.getWorker.

Doc from org.xnio.channels.CloseableChannel.getWorker.

Get the worker for this channel.

Returns:XnioWorker

the worker

Annotations
@Override
getWriteSetterback to summary
public ChannelListener.Setter<? extends StreamSinkChannel> getWriteSetter()

Implements org.xnio.channels.StreamSinkChannel.getWriteSetter.

Doc from org.xnio.channels.StreamSinkChannel.getWriteSetter.

Get the setter which can be used to change the write listener for this channel.

Returns:ChannelListener.Setter<? extends StreamSinkChannel>

Doc from org.xnio.channels.SuspendableWriteChannel.getWriteSetter.

the setter

Annotations
@Override
getWriteThreadback to summary
public XnioExecutor getWriteThread()

Implements org.xnio.channels.SuspendableWriteChannel.getWriteThread.

Doc from org.xnio.channels.SuspendableWriteChannel.getWriteThread.

Get the write thread for this channel.

Returns:XnioExecutor

the thread, or null if none is configured or available

Annotations
@Override
isFinishedback to summary
protected abstract boolean isFinished()
isOpenback to summary
public boolean isOpen()

Implements java.nio.channels.Channel.isOpen, org.xnio.channels.SuspendableWriteChannel.isOpen.

Doc from org.xnio.channels.SuspendableWriteChannel.isOpen.

Determine whether this channel is open. This method will return false if all directions are shut down, even if there is unflushed write data pending.

Returns:boolean

true if the channel is open, false otherwise

Annotations
@Override
isWriteResumedback to summary
public boolean isWriteResumed()

Implements org.xnio.channels.SuspendableWriteChannel.isWriteResumed.

Doc from org.xnio.channels.SuspendableWriteChannel.isWriteResumed.

Determine whether writes are resumed.

Returns:boolean

true if writes are resumed, false if writes are suspended

Annotations
@Override
responseDoneback to summary
public void responseDone()
resumeWritesback to summary
public void resumeWrites()

Implements org.xnio.channels.SuspendableWriteChannel.resumeWrites.

Doc from org.xnio.channels.SuspendableWriteChannel.resumeWrites.

Resume writes on this channel. The write listener will be called as soon as the channel becomes writable.

Annotations
@Override
setOptionback to summary
public <T> T setOption(final Option<T> option, final T value) throws IllegalArgumentException, IOException

Implements org.xnio.channels.Configurable.setOption.

Doc from org.xnio.channels.Configurable.setOption.

Set an option for this channel. Unsupported options are ignored.

Parameters
<T>
the type of the option value
option:Option<T>

the option to set

value:T

the value of the option to set

Returns:T

the previous option value, if any

Annotations
@Override
Exceptions
IllegalArgumentException:
if the value is not acceptable for this option
IOException:
if an I/O error occurred when modifying the option
shutdownWritesback to summary
public void shutdownWrites() throws IOException

Implements org.xnio.channels.SuspendableWriteChannel.shutdownWrites.

Doc from org.xnio.channels.SuspendableWriteChannel.shutdownWrites.

Indicate that writing is complete for this channel. Further attempts to write data to this channel after this method is invoked will result in an exception. If this method was already called, calling this method again will have no additional effect. After this method is called, any remaining data still must be flushed out via the flush() method; once this is done, if the read side of the channel was shut down, the channel will automatically close.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
supportsOptionback to summary
public boolean supportsOption(final Option<?> option)

Implements org.xnio.channels.Configurable.supportsOption.

Doc from org.xnio.channels.Configurable.supportsOption.

Determine whether an option is supported on this channel.

Parameters
option:Option<?>

the option

Returns:boolean

true if it is supported

Annotations
@Override
suspendWritesback to summary
public void suspendWrites()

Implements org.xnio.channels.SuspendableWriteChannel.suspendWrites.

Doc from org.xnio.channels.SuspendableWriteChannel.suspendWrites.

Suspend further write notifications on this channel.

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

Implements org.xnio.channels.StreamSinkChannel.transferFrom.

Doc from org.xnio.channels.StreamSinkChannel.transferFrom.

Transfer bytes into this channel from the given file. Using this method in preference to FileChannel#transferTo(long, long, WritableByteChannel) may provide a performance advantage on some platforms.

If the current thread is interrupted when this method is called, it may throw a java.io.InterruptedIOException; however, if this exception is thrown, the java.io.InterruptedIOException#bytesTransferred field is guaranteed to be 0.

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(final StreamSourceChannel source, final long count, final ByteBuffer throughBuffer) throws IOException

Implements org.xnio.channels.StreamSinkChannel.transferFrom.

Doc from org.xnio.channels.StreamSinkChannel.transferFrom.

Transfers bytes from the given channel source. On some platforms, this may avoid copying bytes between user and kernel space. On other platforms, bytes are passed through the throughBuffer parameter's buffer space. 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. Note that using a direct buffer may provide an intermediate performance gain on platforms without zero-copy facilities.

If the current thread is interrupted when this method is called, it may throw a java.io.InterruptedIOException; however, if this exception is thrown, the java.io.InterruptedIOException#bytesTransferred field is guaranteed to be 0.

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
wakeupWritesback to summary
public void wakeupWrites()

Implements org.xnio.channels.SuspendableWriteChannel.wakeupWrites.

Doc from org.xnio.channels.SuspendableWriteChannel.wakeupWrites.

Resume writes on this channel, and force the write listener to be triggered even if the channel isn't actually writable.

Annotations
@Override
writeback to summary
public long write(final ByteBuffer[] srcs, final int offset, final int length) throws IOException

Implements java.nio.channels.GatheringByteChannel.write.

Doc from java.nio.channels.GatheringByteChannel.write.

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

An attempt is made to write up to r bytes to this channel, where r is the total number of bytes remaining in the specified subsequence of the given buffer array, that is,

srcs[offset].remaining() + srcs[offset+1].remaining() + ... + srcs[offset+length-1].remaining()
srcs[offset].remaining()
    + srcs[offset+1].remaining()
    + ... + srcs[offset+length-1].remaining()
at the moment that this method is invoked.

Suppose that a byte sequence of length n is written, where 0 <= n <= r. Up to the first srcs[offset].remaining() bytes of this sequence are written from buffer srcs[offset], up to the next srcs[offset+1].remaining() bytes are written from buffer srcs[offset+1], and so forth, until the entire byte sequence is written. As many bytes as possible are written from each buffer, hence the final position of each updated buffer, except the last updated buffer, is guaranteed to be equal to that buffer's limit.

Unless otherwise specified, a write operation will return only after writing all of the r requested bytes. Some types of channels, depending upon their state, may write only some of the bytes or possibly none at all. A socket channel in non-blocking mode, for example, cannot write any more bytes than are free in the socket's output buffer.

This method may be invoked at any time. If another thread has already initiated a write operation upon this channel, however, then an invocation of this method will block until the first operation is complete.

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 number of bytes written, possibly zero

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
writeback to summary
public long write(final ByteBuffer[] srcs) throws IOException

Implements java.nio.channels.GatheringByteChannel.write.

Doc from java.nio.channels.GatheringByteChannel.write.

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

An invocation of this method of the form c.write(srcs) behaves in exactly the same manner as the invocation

c.write(srcs, 0, srcs.length);
c.write(srcs, 0, srcs.length);
Parameters
srcs:ByteBuffer[]

The buffers from which bytes are to be retrieved

Returns:long

The number of bytes written, possibly zero

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
writeback to summary
public int write(final ByteBuffer src) throws IOException

Implements java.nio.channels.WritableByteChannel.write.

Doc from java.nio.channels.WritableByteChannel.write.

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

An attempt is made to write up to r bytes to the channel, where r is the number of bytes remaining in the buffer, that is, src.remaining(), at the moment this method is invoked.

Suppose that a byte sequence of length n is written, where 0 <= n <= r. This byte sequence will be transferred from the buffer starting at index p, where p is the buffer's position at the moment this method is invoked; the index of the last byte written will be p + n - 1. Upon return the buffer's position will be equal to p + n; its limit will not have changed.

Unless otherwise specified, a write operation will return only after writing all of the r requested bytes. Some types of channels, depending upon their state, may write only some of the bytes or possibly none at all. A socket channel in non-blocking mode, for example, cannot write any more bytes than are free in the socket's output buffer.

This method may be invoked at any time. If another thread has already initiated a write operation upon this channel, however, then an invocation of this method will block until the first operation is complete.

Parameters
src:ByteBuffer

The buffer from which bytes are to be retrieved

Returns:int

The number of bytes written, possibly zero

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
writeFinalback to summary
public int writeFinal(ByteBuffer src) throws IOException

Implements org.xnio.channels.StreamSinkChannel.writeFinal.

Doc from org.xnio.channels.StreamSinkChannel.writeFinal.

Writes some data to the channel, with the same semantics as write(java.nio.ByteBuffer). If all the data is written out then the channel will have its writes shutdown. Semantically this method is equivalent to: int rem = src.remaining(); int written = channel.write(src); if(written == rem) { channel.shutdownWrites() } If an exception is thrown the caller is still responsible for closing the channel.

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

Implements org.xnio.channels.StreamSinkChannel.writeFinal.

Doc from org.xnio.channels.StreamSinkChannel.writeFinal.

Writes some data to the channel, with the same semantics as write(java.nio.ByteBuffer[], int, int). If all the data is written out then the channel will have its writes shutdown. If an exception is thrown the caller is still responsible for closing the channel.

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
writeFinalback to summary
public long writeFinal(ByteBuffer[] srcs) throws IOException

Implements org.xnio.channels.StreamSinkChannel.writeFinal.

Doc from org.xnio.channels.StreamSinkChannel.writeFinal.

Writes some data to the channel, with the same semantics as write(java.nio.ByteBuffer[]). If all the data is written out then the channel will have its writes shutdown. If an exception is thrown the caller is still responsible for closing the channel.

Parameters
srcs:ByteBuffer[]

The buffers from which bytes are to be retrieved

Returns:long

The amount of data that was actually written

Annotations
@Override
io.undertow.channels back to summary

private Class DetachableStreamSinkChannel.SetterDelegatingListener

extends Object
implements ChannelListener<StreamSinkChannel>
Class Inheritance
  • java.lang.Object
  • io.undertow.channels.DetachableStreamSinkChannel.SetterDelegatingListener
All Implemented Interfaces
org.xnio.ChannelListener, java.util.EventListener

Field Summary

Modifier and TypeField and Description
private final StreamSinkChannel
private final ChannelListener.SimpleSetter<StreamSinkChannel>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
handleEvent(final StreamSinkChannel
the channel event
channel
)

Implements org.xnio.ChannelListener.handleEvent.

Handle the event on this channel.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

channelback to summary
private final StreamSinkChannel channel
setterback to summary
private final ChannelListener.SimpleSetter<StreamSinkChannel> setter

Constructor Detail

SetterDelegatingListenerback to summary
pack-priv SetterDelegatingListener(final ChannelListener.SimpleSetter<StreamSinkChannel> setter, final StreamSinkChannel channel)

Method Detail

handleEventback to summary
public void handleEvent(final StreamSinkChannel channel)

Implements org.xnio.ChannelListener.handleEvent.

Doc from org.xnio.ChannelListener.handleEvent.

Handle the event on this channel.

Parameters
channel:StreamSinkChannel

the channel event

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object