@sailboat-computer/resilience
Version:
Enhanced resilience patterns for sailboat computer v3 with marine-specific adaptations
145 lines • 4.49 kB
TypeScript
/**
* Bulkhead manager for coordinating multiple resource pools
*/
import { ResourcePool, ResourceAllocation } from './ResourcePool';
import { BulkheadConfig, ResourcePoolMetrics, ResilienceEvent, MarineEnvironmentStatus } from '../types';
import { OperationalContextType } from '../types/marine-constants';
/**
* Bulkhead execution context
*/
export interface BulkheadExecutionContext {
poolName: string;
priority: 'critical' | 'normal' | 'low';
marineSystemType: 'navigation' | 'safety' | 'comfort' | 'maintenance';
operationalContext: OperationalContextType;
timeoutMs?: number;
}
/**
* Bulkhead execution result
*/
export interface BulkheadExecutionResult<T> {
success: boolean;
data?: T;
error?: Error;
resourceAllocation: ResourceAllocation;
poolMetrics: ResourcePoolMetrics;
executionTime: number;
}
/**
* Manager for coordinating multiple bulkhead resource pools
*/
export declare class BulkheadManager {
private static instance;
private pools;
private eventListeners;
private marineEnvironment?;
/**
* Get the singleton instance of BulkheadManager
* This ensures only one instance exists across the application
*/
static getInstance(): BulkheadManager;
constructor();
/**
* Execute operation with bulkhead protection
*/
execute<T>(operation: () => Promise<T>, context: BulkheadExecutionContext): Promise<BulkheadExecutionResult<T>>;
/**
* Create or update a resource pool
*/
createPool(config: BulkheadConfig): void;
/**
* Get resource pool by name
*/
getPool(poolName: string): ResourcePool | undefined;
/**
* Get all pool metrics
*/
getAllPoolMetrics(): Record<string, ResourcePoolMetrics>;
/**
* Get system-wide bulkhead status
*/
getSystemStatus(): {
pools: Record<string, any>;
systemTotals: {
totalCapacity: number;
totalActive: number;
totalQueued: number;
totalRejected: number;
totalPowerImpact: number;
utilizationPercentage: number;
};
marineEnvironment: MarineEnvironmentStatus | undefined;
};
/**
* Update marine environment for all pools
*/
updateMarineEnvironment(environment: MarineEnvironmentStatus): void;
/**
* Emergency release all resources across all pools
*/
emergencyReleaseAll(reason?: string): void;
/**
* Add event listener
*/
onEvent(listener: (event: ResilienceEvent) => void): void;
/**
* Remove a resource pool
*/
removePool(poolName: string): boolean;
/**
* Get pool names
*/
getPoolNames(): string[];
/**
* Check if pool exists
*/
hasPool(poolName: string): boolean;
/**
* Initialize default marine resource pools
*/
private initializeDefaultPools;
/**
* Emit resilience event
*/
private emitEvent;
/**
* Get empty metrics for error cases
*/
private getEmptyMetrics;
}
/**
* Default bulkhead manager instance
* Using the getInstance method ensures we always get the same instance
*/
export declare const defaultBulkheadManager: BulkheadManager;
/**
* Convenience function to execute with bulkhead protection
* Always uses the singleton instance to ensure consistency
*/
export declare function executeWithBulkhead<T>(operation: () => Promise<T>, context: BulkheadExecutionContext): Promise<BulkheadExecutionResult<T>>;
/**
* Pre-configured bulkhead execution contexts
*/
export declare const BulkheadContexts: {
/**
* Navigation operations (GPS, compass, autopilot)
*/
navigation: (operationalContext?: OperationalContextType) => BulkheadExecutionContext;
/**
* Safety operations (anchor alarm, collision avoidance)
*/
safety: (operationalContext?: OperationalContextType) => BulkheadExecutionContext;
/**
* Comfort operations (lighting, entertainment, climate)
*/
comfort: (operationalContext?: OperationalContextType) => BulkheadExecutionContext;
/**
* Maintenance operations (diagnostics, updates)
*/
maintenance: (operationalContext?: OperationalContextType) => BulkheadExecutionContext;
/**
* Communication operations (weather, email, messaging)
*/
communication: (operationalContext?: OperationalContextType) => BulkheadExecutionContext;
};
//# sourceMappingURL=BulkheadManager.d.ts.map