-
public class AsyncTimeout extends Timeout
This timeout uses a background thread to take action exactly when the timeout occurs. Use this to implement timeouts where they aren't supported natively, such as to sockets that are blocked on writing.
Subclasses should override timedOut to take action when a timeout occurs. This method will be invoked by the shared watchdog thread so it should not do any long-running operations. Otherwise we risk starving other timeouts from being triggered.
Use sink and source to apply this timeout to a stream. The returned value will apply the timeout to each operation on the wrapped stream.
Callers should call enter before doing work that is subject to timeouts, and afterwards. The return value of exit indicates whether a timeout was triggered. Note that the call to timedOut is asynchronous, and may be called after exit.
-
-
Method Summary
Modifier and Type Method Description final voidenter()final booleanexit()Returns true if the timeout occurred. final Sinksink(Sink sink)Returns a new sink that delegates to {@code sink}, using this to implement timeouts.final Sourcesource(Source source)Returns a new source that delegates to {@code source}, using this to implement timeouts.-
Methods inherited from class com.mobwith.httpmodule.Timeout
clearDeadline, clearTimeout, deadline, deadlineNanoTime, deadlineNanoTime, hasDeadline, throwIfReached, timeout, timeoutNanos, waitUntilNotified -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
enter
final void enter()
-
exit
final boolean exit()
Returns true if the timeout occurred.
-
sink
final Sink sink(Sink sink)
Returns a new sink that delegates to
{@code sink}, using this to implement timeouts. This worksbest if timedOut is overridden to interrupt{@code sink}'s current operation.
-
-
-
-