Class TimeoutLayer

java.lang.Object
org.apache.opendal.Layer
org.apache.opendal.layer.TimeoutLayer

public class TimeoutLayer extends Layer
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:
  • 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

      public TimeoutLayer(Duration timeout, Duration ioTimeout)
      Creates a layer with the supplied timeouts.
      Parameters:
      timeout - the timeout for control operations such as stat
      ioTimeout - the timeout for individual I/O calls such as reading or writing a buffer
      Throws:
      IllegalArgumentException - if either duration is negative or exceeds Long.MAX_VALUE nanoseconds
  • Method Details

    • builder

      public static TimeoutLayer.TimeoutLayerBuilder builder()
      Creates a builder with the default control operation and I/O timeouts.
      Returns:
      a new builder
    • withTimeout

      public TimeoutLayer withTimeout(Duration timeout)
      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 exceeds Long.MAX_VALUE nanoseconds
    • withIoTimeout

      public TimeoutLayer withIoTimeout(Duration ioTimeout)
      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 exceeds Long.MAX_VALUE nanoseconds
    • withOperationTimeout

      public TimeoutLayer withOperationTimeout(TimeoutLayer.Operation operation, Duration timeout)
      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 override
      timeout - the timeout, which may be zero
      Returns:
      a new layer with the specified override
      Throws:
      NullPointerException - if either argument is null
      IllegalArgumentException - if the duration is negative or exceeds Long.MAX_VALUE nanoseconds
    • layer

      protected long layer(long nativeOp)
      Specified by:
      layer in class Layer