Class TimeoutLayer
java.lang.Object
org.apache.opendal.Layer
org.apache.opendal.layer.TimeoutLayer
Applies deadlines to control operations and individual I/O calls.
When a deadline expires, the layer cancels the in-flight call and reports an OpenDAL error.
Add this layer before
RetryLayer to apply the deadline to each attempt.
Use builder() to set timeouts for individual operations.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumIdentifies an operation that can have its own timeout.static final classConfigures the default and per-operation timeouts for a timeout layer. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a layer with a 60-second timeout for control operations and a 10-second timeout for I/O calls.TimeoutLayer(Duration timeout, Duration ioTimeout) Creates a layer with the supplied timeouts. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Creates a builder with the default control operation and I/O timeouts.protected longlayer(long nativeOp) withIoTimeout(Duration ioTimeout) Returns a new layer with the specified I/O timeout.withOperationTimeout(TimeoutLayer.Operation operation, Duration timeout) Returns a new layer with a timeout override for the specified operation.withTimeout(Duration timeout) Returns a new layer with the specified control operation timeout.
-
Constructor Details
-
TimeoutLayer
public TimeoutLayer()Creates a layer with a 60-second timeout for control operations and a 10-second timeout for I/O calls. -
TimeoutLayer
Creates a layer with the supplied timeouts.- Parameters:
timeout- the timeout for control operations such as statioTimeout- the timeout for individual I/O calls such as reading or writing a buffer- Throws:
IllegalArgumentException- if either duration is negative or exceedsLong.MAX_VALUEnanoseconds
-
-
Method Details
-
builder
Creates a builder with the default control operation and I/O timeouts.- Returns:
- a new builder
-
withTimeout
Returns a new layer with the specified control operation timeout.- Parameters:
timeout- the timeout for control operations- Returns:
- a new layer with the same I/O timeout and per-operation overrides
- Throws:
IllegalArgumentException- if the duration is negative or exceedsLong.MAX_VALUEnanoseconds
-
withIoTimeout
Returns a new layer with the specified I/O timeout.- Parameters:
ioTimeout- the timeout for individual I/O calls- Returns:
- a new layer with the same control operation timeout and per-operation overrides
- Throws:
IllegalArgumentException- if the duration is negative or exceedsLong.MAX_VALUEnanoseconds
-
withOperationTimeout
Returns a new layer with a timeout override for the specified operation. The override replaces the control operation default for operations such as stat and rename. For read, write, list, delete, copy, and compose, it replaces the I/O default for each individual I/O call and concurrent I/O task. Each call replaces the previous override for the same operation.- Parameters:
operation- the operation whose timeout to overridetimeout- the timeout, which may be zero- Returns:
- a new layer with the specified override
- Throws:
NullPointerException- if either argument is nullIllegalArgumentException- if the duration is negative or exceedsLong.MAX_VALUEnanoseconds
-
layer
-