Async 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 exit afterward. 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.
Functions
Waits on monitor
until it is signaled. Throws InterruptedIOException if either the thread is interrupted or if this timeout elapses before monitor
is signaled. The caller must hold the lock that monitor is bound to.
Clears the deadline.
Clears the timeout. Operating system timeouts may still apply.
Returns true if a deadline is enabled.
Applies the minimum intersection between this timeout and other
, run block
, then finally rollback this timeout's values.
Throws an InterruptedIOException if the deadline has been reached or if the current thread has been interrupted. This method doesn't detect timeouts; that should be implemented to asynchronously abort an in-progress operation.
Returns the timeout in nanoseconds, or 0
for no timeout.
Waits on monitor
until it is notified. Throws InterruptedIOException if either the thread is interrupted or if this timeout elapses before monitor
is notified. The caller must be synchronized on monitor
.