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

public final Class BlockingReadTimeoutHandler

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

BlockingReadTimeoutHandler allows configurable blocking I/O timeouts for read operations within an exchange.

Unlike Options.READ_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 ReadTimeoutException 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<StreamSourceConduit>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static BlockingReadTimeoutHandler.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
streamSourceConduitWrapperback to summary
private final ConduitWrapper<StreamSourceConduit> streamSourceConduitWrapper

Constructor Detail

BlockingReadTimeoutHandlerback to summary
private BlockingReadTimeoutHandler(HttpHandler next, Duration readTimeout)

Method Detail

builderback to summary
public static BlockingReadTimeoutHandler.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 BlockingReadTimeoutHandler.Builder

extends Object
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.BlockingReadTimeoutHandler.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 BlockingReadTimeoutHandler.Builder
nextHandler(HttpHandler nextHandler)

public BlockingReadTimeoutHandler.Builder
readTimeout(Duration readTimeout)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nextHandlerback to summary
private HttpHandler nextHandler
readTimeoutback to summary
private Duration readTimeout

Constructor Detail

Builderback to summary
private Builder()

Method Detail

buildback to summary
public HttpHandler build()
nextHandlerback to summary
public BlockingReadTimeoutHandler.Builder nextHandler(HttpHandler nextHandler)
readTimeoutback to summary
public BlockingReadTimeoutHandler.Builder readTimeout(Duration readTimeout)
io.undertow.server.handlers back to summary

private final Class BlockingReadTimeoutHandler.TimeoutStreamSourceConduit

extends Object
implements StreamSourceConduit
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.BlockingReadTimeoutHandler.TimeoutStreamSourceConduit
All Implemented Interfaces
org.xnio.conduits.StreamSourceConduit, org.xnio.conduits.SourceConduit, org.xnio.conduits.Conduit

Field Summary

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

Constructor Summary

AccessConstructor and Description
pack-priv
TimeoutStreamSourceConduit(StreamSourceConduit delegate, ServerConnection serverConnection, long timeoutNanos)

Method Summary

Modifier and TypeMethod and Description
public void
awaitReadable()

Implements org.xnio.conduits.SourceConduit.awaitReadable.

Block until this channel becomes readable again.

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

Implements org.xnio.conduits.SourceConduit.awaitReadable.

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

public XnioIoThread
getReadThread()

Implements org.xnio.conduits.SourceConduit.getReadThread.

Get the XNIO read thread.

public XnioWorker
getWorker()

Implements org.xnio.conduits.Conduit.getWorker.

Get the XNIO worker associated with this conduit.

public boolean
isReadResumed()

Implements org.xnio.conduits.SourceConduit.isReadResumed.

Determine whether read notifications are currently enabled.

public boolean
isReadShutdown()

Implements org.xnio.conduits.SourceConduit.isReadShutdown.

Determine whether reads have been shut down on this conduit.

public int
read(ByteBuffer
the buffer to fill with data from the conduit
byteBuffer
)

Implements org.xnio.conduits.StreamSourceConduit.read.

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

public long
read(ByteBuffer[]
the buffers to fill with data from the conduit
byteBuffers
,
int
the offset into the buffer array
offset
,
int
the number of buffers to fill
length
)

Implements org.xnio.conduits.StreamSourceConduit.read.

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

private long
private int
public void
resumeReads()

Implements org.xnio.conduits.SourceConduit.resumeReads.

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

public void
setReadReadyHandler(ReadReadyHandler
the filter to receive readiness notifications
readReadyHandler
)

Implements org.xnio.conduits.SourceConduit.setReadReadyHandler.

Set the handler which should receive readiness notifications.

public void
suspendReads()

Implements org.xnio.conduits.SourceConduit.suspendReads.

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

public void
terminateReads()

Implements org.xnio.conduits.SourceConduit.terminateReads.

Indicate that no more data will be read from this conduit.

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

Implements org.xnio.conduits.StreamSourceConduit.transferTo.

Transfers bytes into the given file from this channel.

public long
transferTo(long
the number of bytes to be transferred
count
,
ByteBuffer
the buffer to copy through.
byteBuffer
,
StreamSinkChannel
the destination to write to
streamSinkChannel
)

Implements org.xnio.conduits.StreamSourceConduit.transferTo.

Transfers bytes into the given channel target.

public void
wakeupReads()

Implements org.xnio.conduits.SourceConduit.wakeupReads.

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

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

Constructor Detail

TimeoutStreamSourceConduitback to summary
pack-priv TimeoutStreamSourceConduit(StreamSourceConduit delegate, ServerConnection serverConnection, long timeoutNanos)

Method Detail

awaitReadableback to summary
public void awaitReadable() throws IOException

Implements org.xnio.conduits.SourceConduit.awaitReadable.

Doc from org.xnio.conduits.SourceConduit.awaitReadable.

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

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
awaitReadableback to summary
public void awaitReadable(long duration, TimeUnit unit) throws IOException

Implements org.xnio.conduits.SourceConduit.awaitReadable.

Doc from org.xnio.conduits.SourceConduit.awaitReadable.

Block until this conduit becomes readable again, or until the timeout expires. This method may return spuriously before the conduit becomes readable 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
getReadThreadback to summary
public XnioIoThread getReadThread()

Implements org.xnio.conduits.SourceConduit.getReadThread.

Doc from org.xnio.conduits.SourceConduit.getReadThread.

Get the XNIO read thread.

Returns:XnioIoThread

the XNIO read thread

Annotations
@Override
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
isReadResumedback to summary
public boolean isReadResumed()

Implements org.xnio.conduits.SourceConduit.isReadResumed.

Doc from org.xnio.conduits.SourceConduit.isReadResumed.

Determine whether read notifications are currently enabled.

Returns:boolean

true if read notifications are enabled

Annotations
@Override
isReadShutdownback to summary
public boolean isReadShutdown()

Implements org.xnio.conduits.SourceConduit.isReadShutdown.

Doc from org.xnio.conduits.SourceConduit.isReadShutdown.

Determine whether reads have been shut down on this conduit.

Returns:boolean

true if writes are shut down, false otherwise

Annotations
@Override
readback to summary
public int read(ByteBuffer byteBuffer) throws IOException

Implements org.xnio.conduits.StreamSourceConduit.read.

Doc from org.xnio.conduits.StreamSourceConduit.read.

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

Parameters
byteBuffer:ByteBuffer

the buffer to fill with data from the conduit

Returns:int

the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached or this conduit's terminateReads() method was previously called

Annotations
@Override
Exceptions
IOException:
if an error occurs
readback to summary
public long read(ByteBuffer[] byteBuffers, int offset, int length) throws IOException

Implements org.xnio.conduits.StreamSourceConduit.read.

Doc from org.xnio.conduits.StreamSourceConduit.read.

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

Parameters
byteBuffers:ByteBuffer[]

the buffers to fill with data from the conduit

offset:int

the offset into the buffer array

length:int

the number of buffers to fill

Returns:long

the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached or this conduit's terminateReads() method was previously called

Annotations
@Override
Exceptions
IOException:
if an error occurs
resetTimeoutIfReadSucceededback to summary
private long resetTimeoutIfReadSucceeded(long value)
resetTimeoutIfReadSucceededback to summary
private int resetTimeoutIfReadSucceeded(int value)
resumeReadsback to summary
public void resumeReads()

Implements org.xnio.conduits.SourceConduit.resumeReads.

Doc from org.xnio.conduits.SourceConduit.resumeReads.

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

Annotations
@Override
setReadReadyHandlerback to summary
public void setReadReadyHandler(ReadReadyHandler readReadyHandler)

Implements org.xnio.conduits.SourceConduit.setReadReadyHandler.

Doc from org.xnio.conduits.SourceConduit.setReadReadyHandler.

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
readReadyHandler:ReadReadyHandler

the filter to receive readiness notifications

Annotations
@Override
suspendReadsback to summary
public void suspendReads()

Implements org.xnio.conduits.SourceConduit.suspendReads.

Doc from org.xnio.conduits.SourceConduit.suspendReads.

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

Annotations
@Override
terminateReadsback to summary
public void terminateReads() throws IOException

Implements org.xnio.conduits.SourceConduit.terminateReads.

Doc from org.xnio.conduits.SourceConduit.terminateReads.

Indicate that no more data will be read from this conduit. If unread data exists, an exception may be thrown.

Annotations
@Override
Exceptions
IOException:
if there was a problem
transferToback to summary
public long transferTo(long position, long count, FileChannel fileChannel) throws IOException

Implements org.xnio.conduits.StreamSourceConduit.transferTo.

Doc from org.xnio.conduits.StreamSourceConduit.transferTo.

Transfers bytes into the given file from this channel.

Parameters
position:long

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

count:long

the number of bytes to be transferred

fileChannel:FileChannel

the file to write to

Returns:long

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

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
transferToback to summary
public long transferTo(long count, ByteBuffer byteBuffer, StreamSinkChannel streamSinkChannel) throws IOException

Implements org.xnio.conduits.StreamSourceConduit.transferTo.

Doc from org.xnio.conduits.StreamSourceConduit.transferTo.

Transfers bytes into the given channel target. On entry, throughBuffer will be cleared. On exit, the buffer will be flipped for emptying, and may possibly 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 this channel which must be written to target to complete the operation.

Parameters
count:long

the number of bytes to be transferred

byteBuffer:ByteBuffer

the buffer to copy through.

streamSinkChannel:StreamSinkChannel

the destination to write to

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
wakeupReadsback to summary
public void wakeupReads()

Implements org.xnio.conduits.SourceConduit.wakeupReads.

Doc from org.xnio.conduits.SourceConduit.wakeupReads.

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

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

private final Class BlockingReadTimeoutHandler.TimeoutStreamSourceConduitWrapper

extends Object
implements ConduitWrapper<StreamSourceConduit>
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.BlockingReadTimeoutHandler.TimeoutStreamSourceConduitWrapper
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 StreamSourceConduit
wrap(ConduitFactory<StreamSourceConduit>
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

TimeoutStreamSourceConduitWrapperback to summary
pack-priv TimeoutStreamSourceConduitWrapper(Duration readTimeout)

Method Detail

wrapback to summary
public StreamSourceConduit wrap(ConduitFactory<StreamSourceConduit> 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<StreamSourceConduit>

the original conduit

exchange:HttpServerExchange

the in-flight HTTP exchange

Returns:StreamSourceConduit

the replacement conduit

Annotations
@Override