Package com.lucimber.dbus.util
Class ErrorRecoveryManager
java.lang.Object
com.lucimber.dbus.util.ErrorRecoveryManager
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Circuit breaker implementation for preventing cascading failures.static class
Configuration for circuit breaker operations.static class
Exception thrown when circuit breaker is in OPEN state.static enum
Error classification for determining retry strategies.static class
Configuration for retry operations. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new ErrorRecoveryManager with its own scheduler.ErrorRecoveryManager
(ScheduledExecutorService scheduler) Creates a new ErrorRecoveryManager using the provided scheduler. -
Method Summary
Modifier and TypeMethodDescriptionstatic Duration
calculateBackoffDelay
(int attempt, ErrorRecoveryManager.RetryConfig config) Calculates the next delay with exponential backoff and jitter.classifyError
(Throwable throwable) Classifies an exception to determine the appropriate recovery strategy.Creates a circuit breaker for an operation.<T> CompletableFuture<T>
executeWithRetry
(Supplier<CompletableFuture<T>> operation, ErrorRecoveryManager.RetryConfig config) Executes an operation with retry logic using exponential backoff.void
shutdown()
Shuts down the error recovery manager and releases resources.
-
Constructor Details
-
ErrorRecoveryManager
public ErrorRecoveryManager()Creates a new ErrorRecoveryManager with its own scheduler. -
ErrorRecoveryManager
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 executeconfig
- retry configuration- Returns:
- CompletableFuture that completes with the operation result or failure
-
createCircuitBreaker
public ErrorRecoveryManager.CircuitBreaker createCircuitBreaker(String name, ErrorRecoveryManager.CircuitBreakerConfig config) Creates a circuit breaker for an operation.- Parameters:
name
- unique name for the circuit breakerconfig
- circuit breaker configuration- Returns:
- a new CircuitBreaker instance
-
classifyError
Classifies an exception to determine the appropriate recovery strategy.- Parameters:
throwable
- the exception to classify- Returns:
- the error classification
-
calculateBackoffDelay
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.
-