/**
 * Circuit breaker implementation for handling external module failures
 * Prevents cascading failures and provides graceful degradation
 *
 * Resource Management:
 * - Tracks all active timers for proper cleanup
 * - Provides shutdown() method to cancel in-flight operations
 * - Prevents timer leaks in retry operations
 */
export interface CircuitBreakerOptions {
    failureThreshold: number;
    recoveryTimeout: number;
    monitoringPeriod: number;
    exponentialBackoff: boolean;
    maxBackoffTime: number;
    jitterEnabled: boolean;
}
export interface CircuitBreakerState {
    state: 'closed' | 'open' | 'half-open';
    failures: number;
    lastFailureTime: number;
    nextRetryTime: number;
    consecutiveSuccesses: number;
    totalRequests: number;
    totalFailures: number;
}
export interface RetryOptions {
    maxRetries: number;
    initialDelay: number;
    maxDelay: number;
    exponential: boolean;
    jitter: boolean;
}
/**
 * Circuit breaker for external module dependencies
 */
export declare class CircuitBreaker {
    private state;
    private readonly options;
    private readonly failureTimes;
    private readonly activeTimers;
    private readonly pendingRejects;
    private isShuttingDown;
    constructor(options?: Partial<CircuitBreakerOptions>);
    /**
     * Execute an operation with circuit breaker protection
     */
    execute<T>(operation: () => Promise<T>, fallback?: () => Promise<T>): Promise<T>;
    /**
     * Check if shutting down and throw error if so
     */
    private checkShutdown;
    /**
     * Calculate retry delay with exponential backoff and jitter
     */
    private calculateRetryDelay;
    /**
     * Execute with retry logic
     */
    executeWithRetry<T>(operation: () => Promise<T>, retryOptions?: Partial<RetryOptions>, fallback?: () => Promise<T>): Promise<T>;
    private attemptOperation;
    private recordSuccess;
    private recordFailure;
    private openCircuit;
    private cleanupOldFailures;
    private isOpen;
    private isHalfOpen;
    private sleep;
    /**
     * Get current circuit breaker state
     */
    getState(): CircuitBreakerState;
    /**
     * Get failure rate over the monitoring period
     */
    getFailureRate(): number;
    /**
     * Force circuit to closed state (for testing/admin)
     */
    reset(): void;
    /**
     * Force circuit to open state (for maintenance/emergency)
     */
    forceOpen(duration?: number): void;
    /**
     * Get health status of the circuit breaker
     */
    getHealthStatus(): {
        healthy: boolean;
        state: string;
        failureRate: number;
        failures: number;
        nextRetry?: string;
    };
    /**
     * Shutdown the circuit breaker and cleanup all resources
     * - Cancels all active timers
     * - Rejects in-flight sleep operations
     * - Prevents new operations from starting
     */
    shutdown(): void;
    /**
     * Check if circuit breaker is shut down
     */
    isShutdown(): boolean;
}
/**
 * Circuit breaker manager for multiple external dependencies
 */
export declare class CircuitBreakerManager {
    private readonly breakers;
    private readonly defaultOptions;
    constructor(defaultOptions?: Partial<CircuitBreakerOptions>);
    /**
     * Get or create circuit breaker for a specific external module
     */
    getBreaker(moduleId: string, options?: Partial<CircuitBreakerOptions>): CircuitBreaker;
    /**
     * Execute operation with circuit breaker protection for specific module
     */
    execute<T>(moduleId: string, operation: () => Promise<T>, fallback?: () => Promise<T>, options?: Partial<CircuitBreakerOptions>): Promise<T>;
    /**
     * Execute with retry logic for specific module
     */
    executeWithRetry<T>(moduleId: string, operation: () => Promise<T>, retryOptions?: Partial<RetryOptions>, fallback?: () => Promise<T>, breakerOptions?: Partial<CircuitBreakerOptions>): Promise<T>;
    /**
     * Get status of all circuit breakers
     */
    getAllStatus(): Record<string, ReturnType<CircuitBreaker['getHealthStatus']>>;
    /**
     * Reset all circuit breakers
     */
    resetAll(): void;
    /**
     * Force all circuit breakers to open state
     */
    forceAllOpen(duration?: number): void;
    /**
     * Remove circuit breaker for specific module
     */
    removeBreaker(moduleId: string): void;
    /**
     * Get overall health status
     */
    getOverallHealth(): {
        healthy: boolean;
        totalBreakers: number;
        healthyBreakers: number;
        openBreakers: number;
    };
    /**
     * Shutdown all circuit breakers and cleanup resources
     * - Calls shutdown() on all managed circuit breakers
     * - Clears the breaker map
     * - Prevents resource leaks from active timers
     */
    shutdown(): void;
    /**
     * Get count of active timers across all breakers (for monitoring)
     */
    getActiveTimerCount(): number;
}
//# sourceMappingURL=circuit-breaker.d.ts.map