Top Inners Fields Constructors Methods
io.undertow.io

public Class AsyncSenderImpl

extends Object
implements Sender
Class Inheritance
All Implemented Interfaces
io.undertow.io.Sender
Imports
java.io.IOException, java.nio.ByteBuffer, java.nio.channels.ClosedChannelException, .FileChannel, java.nio.charset.Charset, .StandardCharsets, org.xnio.Buffers, .ChannelExceptionHandler, .ChannelListener, .ChannelListeners, .IoUtils, org.xnio.channels.StreamSinkChannel, io.undertow.UndertowLogger, .UndertowMessages, io.undertow.connector.PooledByteBuffer, io.undertow.server.HttpServerExchange, io.undertow.util.Headers

Author
Stuart Douglas

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class

Field Summary

Modifier and TypeField and Description
private ByteBuffer[]
private IoCallback
private StreamSinkChannel
private final HttpServerExchange
private FileChannel
private volatile Thread
private PooledByteBuffer[]
private AsyncSenderImpl.TransferTask
private ChannelListener<StreamSinkChannel>
private volatile Thread
writeThread

This object is not intended to be used in a multi threaded manner however as we run code after the callback it is possible that another thread may call send while we are still running we use the 'writeThread' state guard to protect against this happening.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close(final IoCallback
The callback that is notified when all data has been flushed and the channel is closed
callback
)

Implements io.undertow.io.Sender.close.

Closes this sender asynchronously.

public void
close()

Implements io.undertow.io.Sender.close.

Closes this sender asynchronously

private void
private void
invokeOnComplete()

Invokes the onComplete method.

private void
public void
send(final ByteBuffer
The buffer to send.
buffer
,
final IoCallback
The callback
callback
)

Implements io.undertow.io.Sender.send.

Write the given buffer using async IO, and calls the given callback on completion or error.

public void
send(final ByteBuffer[]
The buffers to send.
buffer
,
final IoCallback
The callback
callback
)

Implements io.undertow.io.Sender.send.

Write the given buffers using async IO, and calls the given callback on completion or error.

public void
send(final ByteBuffer
The buffer to send.
buffer
)

Implements io.undertow.io.Sender.send.

Write the given buffer using async IO, and ends the exchange when done

public void
send(final ByteBuffer[]
The buffers to send.
buffer
)

Implements io.undertow.io.Sender.send.

Write the given buffers using async IO, and ends the exchange when done

public void
send(final String
The data to send
data
,
final IoCallback
The callback
callback
)

Implements io.undertow.io.Sender.send.

Write the given String using async IO, and calls the given callback on completion or error.

public void
send(final String
The buffer to end.
data
,
final Charset
The charset to use
charset
,
final IoCallback
The callback
callback
)

Implements io.undertow.io.Sender.send.

Write the given String using async IO, and calls the given callback on completion or error.

public void
send(final String
The data to send
data
)

Implements io.undertow.io.Sender.send.

Write the given String using async IO, and ends the exchange when done

The CharSequence is encoded to UTF8

public void
send(final String
The buffer to end.
data
,
final Charset
The charset to use
charset
)

Implements io.undertow.io.Sender.send.

Write the given String using async IO, and ends the exchange when done

public void
transferFrom(FileChannel
the file channel to transfer
source
,
IoCallback
The callback
callback
)

Implements io.undertow.io.Sender.transferFrom.

Transfers all content from the specified file

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferback to summary
private ByteBuffer[] buffer
callbackback to summary
private IoCallback callback
channelback to summary
private StreamSinkChannel channel
exchangeback to summary
private final HttpServerExchange exchange
fileChannelback to summary
private FileChannel fileChannel
inCallbackback to summary
private volatile Thread inCallback
pooledBuffersback to summary
private PooledByteBuffer[] pooledBuffers
transferTaskback to summary
private AsyncSenderImpl.TransferTask transferTask
writeListenerback to summary
private ChannelListener<StreamSinkChannel> writeListener
writeThreadback to summary
private volatile Thread writeThread

This object is not intended to be used in a multi threaded manner however as we run code after the callback it is possible that another thread may call send while we are still running we use the 'writeThread' state guard to protect against this happening. During a send() call the 'writeThread' object is set first, followed by the buffer. The inCallback variable is used to determine if the current thread is in the process of running a callback. After the callback has been invoked the thread that initiated the callback will only continue to process if it is the writeThread.

Constructor Detail

AsyncSenderImplback to summary
public AsyncSenderImpl(final HttpServerExchange exchange)

Method Detail

closeback to summary
public void close(final IoCallback callback)

Implements io.undertow.io.Sender.close.

Doc from io.undertow.io.Sender.close.

Closes this sender asynchronously. The given callback is notified on completion

Parameters
callback:IoCallback

The callback that is notified when all data has been flushed and the channel is closed

Annotations
@Override
closeback to summary
public void close()

Implements io.undertow.io.Sender.close.

Doc from io.undertow.io.Sender.close.

Closes this sender asynchronously

Annotations
@Override
initWriteListenerback to summary
private void initWriteListener()
invokeOnCompleteback to summary
private void invokeOnComplete()

Invokes the onComplete method. If send is called again in onComplete then we loop and write it out. This prevents possible stack overflows due to recursion

invokeOnExceptionback to summary
private void invokeOnException(IoCallback callback, IOException e)
sendback to summary
public void send(final ByteBuffer buffer, final IoCallback callback)

Implements io.undertow.io.Sender.send.

Doc from io.undertow.io.Sender.send.

Write the given buffer using async IO, and calls the given callback on completion or error.

Parameters
buffer:ByteBuffer

The buffer to send.

callback:IoCallback

The callback

Annotations
@Override
sendback to summary
public void send(final ByteBuffer[] buffer, final IoCallback callback)

Implements io.undertow.io.Sender.send.

Doc from io.undertow.io.Sender.send.

Write the given buffers using async IO, and calls the given callback on completion or error.

Parameters
buffer:ByteBuffer[]

The buffers to send.

callback:IoCallback

The callback

Annotations
@Override
sendback to summary
public void send(final ByteBuffer buffer)

Implements io.undertow.io.Sender.send.

Doc from io.undertow.io.Sender.send.

Write the given buffer using async IO, and ends the exchange when done

Parameters
buffer:ByteBuffer

The buffer to send.

Annotations
@Override
sendback to summary
public void send(final ByteBuffer[] buffer)

Implements io.undertow.io.Sender.send.

Doc from io.undertow.io.Sender.send.

Write the given buffers using async IO, and ends the exchange when done

Parameters
buffer:ByteBuffer[]

The buffers to send.

Annotations
@Override
sendback to summary
public void send(final String data, final IoCallback callback)

Implements io.undertow.io.Sender.send.

Doc from io.undertow.io.Sender.send.

Write the given String using async IO, and calls the given callback on completion or error.

The CharSequence is encoded to UTF8

Parameters
data:String

The data to send

callback:IoCallback

The callback

Annotations
@Override
sendback to summary
public void send(final String data, final Charset charset, final IoCallback callback)

Implements io.undertow.io.Sender.send.

Doc from io.undertow.io.Sender.send.

Write the given String using async IO, and calls the given callback on completion or error.

Parameters
data:String

The buffer to end.

charset:Charset

The charset to use

callback:IoCallback

The callback

Annotations
@Override
sendback to summary
public void send(final String data)

Implements io.undertow.io.Sender.send.

Doc from io.undertow.io.Sender.send.

Write the given String using async IO, and ends the exchange when done

The CharSequence is encoded to UTF8

Parameters
data:String

The data to send

Annotations
@Override
sendback to summary
public void send(final String data, final Charset charset)

Implements io.undertow.io.Sender.send.

Doc from io.undertow.io.Sender.send.

Write the given String using async IO, and ends the exchange when done

Parameters
data:String

The buffer to end.

charset:Charset

The charset to use

Annotations
@Override
transferFromback to summary
public void transferFrom(FileChannel source, IoCallback callback)

Implements io.undertow.io.Sender.transferFrom.

Doc from io.undertow.io.Sender.transferFrom.

Transfers all content from the specified file

Parameters
source:FileChannel

the file channel to transfer

callback:IoCallback

The callback

Annotations
@Override
io.undertow.io back to summary

public Class AsyncSenderImpl.TransferTask

extends Object
implements Runnable, ChannelListener<StreamSinkChannel>
Class Inheritance
All Implemented Interfaces
org.xnio.ChannelListener, java.util.EventListener, java.lang.Runnable

Constructor Summary

AccessConstructor and Description
public

Method Summary

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

Implements org.xnio.ChannelListener.handleEvent.

Handle the event on this channel.

public boolean
run(boolean complete)

public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

TransferTaskback to summary
public TransferTask()

Method Detail

handleEventback to summary
public void handleEvent(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

Annotations
@Override
runback to summary
public boolean run(boolean complete)
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override