Class ErrorRecoveryManager

java.lang.Object
com.lucimber.dbus.util.ErrorRecoveryManager

public class ErrorRecoveryManager extends Object
Comprehensive error recovery manager for D-Bus operations.

Provides sophisticated error handling mechanisms including:

  • Exponential backoff with jitter for retry operations
  • Circuit breaker pattern for failing operations
  • Error classification for appropriate recovery strategies
  • Adaptive timeout based on historical performance
  • Resource cleanup and leak prevention

This manager is designed to be thread-safe and can be shared across multiple connection instances and operation types.

  • Constructor Details

    • ErrorRecoveryManager

      public ErrorRecoveryManager()
      Creates a new ErrorRecoveryManager with its own scheduler.
    • ErrorRecoveryManager

      public ErrorRecoveryManager(ScheduledExecutorService scheduler)
      Creates a new ErrorRecoveryManager using the provided scheduler.
      Parameters:
      scheduler - the scheduler to use for retry operations
  • Method Details

    • executeWithRetry

      public <T> CompletableFuture<T> executeWithRetry(Supplier<CompletableFuture<T>> operation, ErrorRecoveryManager.RetryConfig config)
      Executes an operation with retry logic using exponential backoff.
      Type Parameters:
      T - the result type
      Parameters:
      operation - the operation to execute
      config - retry configuration
      Returns:
      CompletableFuture that completes with the operation result or failure
    • createCircuitBreaker

      Creates a circuit breaker for an operation.
      Parameters:
      name - unique name for the circuit breaker
      config - circuit breaker configuration
      Returns:
      a new CircuitBreaker instance
    • classifyError

      public static ErrorRecoveryManager.ErrorClassification classifyError(Throwable throwable)
      Classifies an exception to determine the appropriate recovery strategy.
      Parameters:
      throwable - the exception to classify
      Returns:
      the error classification
    • calculateBackoffDelay

      public static Duration calculateBackoffDelay(int attempt, ErrorRecoveryManager.RetryConfig config)
      Calculates the next delay with exponential backoff and jitter.
      Parameters:
      attempt - the current attempt number (0-based)
      config - retry configuration
      Returns:
      the delay duration
    • shutdown

      public void shutdown()
      Shuts down the error recovery manager and releases resources.