Top Description Inners Fields Constructors Methods
io.undertow.server.handlers

public final Class BlockingWriteTimeoutHandler

extends Object
implements HttpHandler
Class Inheritance
All Implemented Interfaces
io.undertow.server.HttpHandler
Static Imports
org.wildfly.common.Assert.checkNotNullParam, .Assert.checkNotNullParamWithNullPointerException

BlockingTimeoutHandler allows configurable blocking I/O timeouts for write operations within an exchange.

Unlike Options.WRITE_TIMEOUT this only applies to blocking operations which can be helpful to prevent the worker pool from becoming saturated when clients stop responding.

When a timeout occurs, a WriteTimeoutException is thrown, and the ServerConnection is closed.

Author
Carter Kozak

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private final HttpHandler
private final ConduitWrapper<StreamSinkConduit>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static BlockingWriteTimeoutHandler.Builder
public void
handleRequest(HttpServerExchange
the HTTP request/response exchange
exchange
)

Implements io.undertow.server.HttpHandler.handleRequest.

Handle the request.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nextback to summary
private final HttpHandler next
streamSinkConduitWrapperback to summary
private final ConduitWrapper<StreamSinkConduit> streamSinkConduitWrapper

Constructor Detail

BlockingWriteTimeoutHandlerback to summary
private BlockingWriteTimeoutHandler(HttpHandler next, Duration writeTimeout)

Method Detail

builderback to summary
public static BlockingWriteTimeoutHandler.Builder builder()
handleRequestback to summary
public void handleRequest(HttpServerExchange exchange) throws Exception

Implements io.undertow.server.HttpHandler.handleRequest.

Doc from io.undertow.server.HttpHandler.handleRequest.

Handle the request.

Parameters
exchange:HttpServerExchange

the HTTP request/response exchange

Annotations
@Override
io.undertow.server.handlers back to summary

public final Class BlockingWriteTimeoutHandler.Builder

extends Object
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.BlockingWriteTimeoutHandler.Builder

Field Summary

Modifier and TypeField and Description
private HttpHandler
private Duration

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public HttpHandler
public BlockingWriteTimeoutHandler.Builder
nextHandler(HttpHandler nextHandler)

public BlockingWriteTimeoutHandler.Builder
writeTimeout(Duration writeTimeout)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nextHandlerback to summary
private HttpHandler nextHandler
writeTimeoutback to summary
private Duration writeTimeout

Constructor Detail

Builderback to summary
private Builder()

Method Detail

buildback to summary
public HttpHandler build()
nextHandlerback to summary
public BlockingWriteTimeoutHandler.Builder nextHandler(HttpHandler nextHandler)
writeTimeoutback to summary
public BlockingWriteTimeoutHandler.Builder writeTimeout(Duration writeTimeout)
io.undertow.server.handlers back to summary

private final Class BlockingWriteTimeoutHandler.TimeoutStreamSinkConduit

extends Object
implements StreamSinkConduit
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.BlockingWriteTimeoutHandler.TimeoutStreamSinkConduit
All Implemented Interfaces
org.xnio.conduits.StreamSinkConduit, org.xnio.conduits.SinkConduit, org.xnio.conduits.Conduit

Field Summary

Modifier and TypeField and Description
private final StreamSinkConduit
private long
private final ServerConnection
private final long

Constructor Summary

AccessConstructor and Description
pack-priv
TimeoutStreamSinkConduit(StreamSinkConduit delegate, ServerConnection serverConnection, long timeoutNanos)

Method Summary

Modifier and TypeMethod and Description
public void
awaitWritable()

Implements org.xnio.conduits.SinkConduit.awaitWritable.

Block until this channel becomes writable again.

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

Implements org.xnio.conduits.SinkConduit.awaitWritable.

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

public boolean
flush()

Implements org.xnio.conduits.SinkConduit.flush.

Flush out any unwritten, buffered output.

public XnioWorker
getWorker()

Implements org.xnio.conduits.Conduit.getWorker.

Get the XNIO worker associated with this conduit.

public XnioIoThread
getWriteThread()

Implements org.xnio.conduits.SinkConduit.getWriteThread.

Get the write thread for this conduit.

public boolean
isWriteResumed()

Implements org.xnio.conduits.SinkConduit.isWriteResumed.

Determine whether write notifications are currently enabled.

public boolean
isWriteShutdown()

Implements org.xnio.conduits.SinkConduit.isWriteShutdown.

Determine whether writes have been fully shut down on this conduit.

private long
private int
private boolean
public void
resumeWrites()

Implements org.xnio.conduits.SinkConduit.resumeWrites.

Indicate that the conduit's WriteReadyHandler should be invoked as soon as data can be written without blocking.

public void
setWriteReadyHandler(WriteReadyHandler
the filter to receive readiness notifications
writeReadyHandler
)

Implements org.xnio.conduits.SinkConduit.setWriteReadyHandler.

Set the handler which should receive readiness notifications.

public void
suspendWrites()

Implements org.xnio.conduits.SinkConduit.suspendWrites.

Indicate that calling the conduit's WriteReadyHandler should be suspended.

public void
terminateWrites()

Implements org.xnio.conduits.SinkConduit.terminateWrites.

Signal that no more write data is forthcoming.

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

Implements org.xnio.conduits.StreamSinkConduit.transferFrom.

Transfer bytes into this conduit from the given file.

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

Implements org.xnio.conduits.StreamSinkConduit.transferFrom.

Transfers bytes from the given channel source.

public void
truncateWrites()

Implements org.xnio.conduits.SinkConduit.truncateWrites.

Terminate writes and discard any outstanding write data.

public void
wakeupWrites()

Implements org.xnio.conduits.SinkConduit.wakeupWrites.

Indicate that the conduit's WriteReadyHandler should be invoked immediately, and then again as soon as data can be written without blocking.

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

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
byteBuffers
,
int
the offset into the buffer array
offset
,
int
the number of buffers to write
length
)

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
byteBuffer
)

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
byteBuffers
,
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.conduits.StreamSinkConduit.writeFinal.

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

delegateback to summary
private final StreamSinkConduit delegate
remainingback to summary
private long remaining
serverConnectionback to summary
private final ServerConnection serverConnection
timeoutNanosback to summary
private final long timeoutNanos

Constructor Detail

TimeoutStreamSinkConduitback to summary
pack-priv TimeoutStreamSinkConduit(StreamSinkConduit delegate, ServerConnection serverConnection, long timeoutNanos)

Method Detail

awaitWritableback to summary
public void awaitWritable() throws IOException

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
awaitWritableback to summary
public void awaitWritable(long duration, TimeUnit unit) throws IOException

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
duration:long

the time to wait

unit:TimeUnit

the time unit

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
flushback to summary
public boolean flush() throws IOException

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
getWorkerback to summary
public XnioWorker getWorker()

Implements org.xnio.conduits.Conduit.getWorker.

Doc from org.xnio.conduits.Conduit.getWorker.

Get the XNIO worker associated with this conduit.

Returns:XnioWorker

the XNIO worker associated with this conduit

Annotations
@Override
getWriteThreadback to summary
public XnioIoThread getWriteThread()

Implements org.xnio.conduits.SinkConduit.getWriteThread.

Doc from org.xnio.conduits.SinkConduit.getWriteThread.

Get the write thread for this conduit.

Returns:XnioIoThread

the thread, or null if none is configured or available

Annotations
@Override
isWriteResumedback to summary
public boolean isWriteResumed()

Implements org.xnio.conduits.SinkConduit.isWriteResumed.

Doc from org.xnio.conduits.SinkConduit.isWriteResumed.

Determine whether write notifications are currently enabled.

Returns:boolean

true if write notifications are enabled

Annotations
@Override
isWriteShutdownback to summary
public boolean isWriteShutdown()

Implements org.xnio.conduits.SinkConduit.isWriteShutdown.

Doc from org.xnio.conduits.SinkConduit.isWriteShutdown.

Determine whether writes have been fully shut down on this conduit.

Returns:boolean

true if writes are fully shut down, false otherwise

Annotations
@Override
resetTimeoutIfWriteSucceededback to summary
private long resetTimeoutIfWriteSucceeded(long value)
resetTimeoutIfWriteSucceededback to summary
private int resetTimeoutIfWriteSucceeded(int value)
resetTimeoutIfWriteSucceededback to summary
private boolean resetTimeoutIfWriteSucceeded(boolean value)
resumeWritesback to summary
public void resumeWrites()

Implements org.xnio.conduits.SinkConduit.resumeWrites.

Doc from org.xnio.conduits.SinkConduit.resumeWrites.

Indicate that the conduit's WriteReadyHandler should be invoked as soon as data can be written without blocking.

Annotations
@Override
setWriteReadyHandlerback to summary
public void setWriteReadyHandler(WriteReadyHandler writeReadyHandler)

Implements org.xnio.conduits.SinkConduit.setWriteReadyHandler.

Doc from org.xnio.conduits.SinkConduit.setWriteReadyHandler.

Set the handler which should receive readiness notifications. A filter may pass this invocation on to the filter it wraps, or it may substitute itself.

Parameters
writeReadyHandler:WriteReadyHandler

the filter to receive readiness notifications

Annotations
@Override
suspendWritesback to summary
public void suspendWrites()

Implements org.xnio.conduits.SinkConduit.suspendWrites.

Doc from org.xnio.conduits.SinkConduit.suspendWrites.

Indicate that calling the conduit's WriteReadyHandler should be suspended.

Annotations
@Override
terminateWritesback to summary
public void terminateWrites() throws IOException

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 fileChannel, long position, long count) throws IOException

Implements org.xnio.conduits.StreamSinkConduit.transferFrom.

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

Transfer bytes into this conduit from the given file.

Parameters
fileChannel: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 streamSourceChannel, long count, ByteBuffer byteBuffer) throws IOException

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
streamSourceChannel:StreamSourceChannel

the source to read from

count:long

the number of bytes to be transferred

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

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

Implements org.xnio.conduits.SinkConduit.wakeupWrites.

Doc from org.xnio.conduits.SinkConduit.wakeupWrites.

Indicate that the conduit's WriteReadyHandler should be invoked immediately, and then again as soon as data can be written without blocking.

Annotations
@Override
writeback to summary
public int write(ByteBuffer byteBuffer) throws IOException

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
byteBuffer: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[] byteBuffers, int offset, int length) throws IOException

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
byteBuffers: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
writeFinalback to summary
public int writeFinal(ByteBuffer byteBuffer) throws IOException

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
byteBuffer:ByteBuffer

The data to write

Returns:int

The amount of data that was actually written.

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

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
byteBuffers: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
io.undertow.server.handlers back to summary

private final Class BlockingWriteTimeoutHandler.TimeoutStreamSinkConduitWrapper

extends Object
implements ConduitWrapper<StreamSinkConduit>
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.BlockingWriteTimeoutHandler.TimeoutStreamSinkConduitWrapper
All Implemented Interfaces
io.undertow.server.ConduitWrapper

Field Summary

Modifier and TypeField and Description
private final long

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public StreamSinkConduit
wrap(ConduitFactory<StreamSinkConduit>
the original conduit
factory
,
HttpServerExchange
the in-flight HTTP exchange
exchange
)

Implements io.undertow.server.ConduitWrapper.wrap.

Wrap the conduit.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

timeoutNanosecondsback to summary
private final long timeoutNanoseconds

Constructor Detail

TimeoutStreamSinkConduitWrapperback to summary
pack-priv TimeoutStreamSinkConduitWrapper(Duration writeTimeout)

Method Detail

wrapback to summary
public StreamSinkConduit wrap(ConduitFactory<StreamSinkConduit> factory, HttpServerExchange exchange)

Implements io.undertow.server.ConduitWrapper.wrap.

Doc from io.undertow.server.ConduitWrapper.wrap.

Wrap the conduit. The wrapper should not return null. If no wrapping is desired, the original conduit should be returned.

Parameters
factory:ConduitFactory<StreamSinkConduit>

the original conduit

exchange:HttpServerExchange

the in-flight HTTP exchange

Returns:StreamSinkConduit

the replacement conduit

Annotations
@Override