/** * FileLockManager - Prevents race conditions in concurrent file operations * * Features: * - Resource-based locking with automatic cleanup * - Configurable timeouts to prevent deadlocks * - Atomic file operations with write-rename pattern * - Lock queueing for concurrent requests * - Comprehensive error handling and logging * - Performance metrics tracking */ export declare class FileLockManager { private locks; private metrics; private logListener?; addLogListener(fn: (level: 'debug' | 'info' | 'warn' | 'error', message: string, data?: Record) => void): () => void; private readonly DEFAULT_TIMEOUT_MS; private readonly TEMP_DIR; /** * Execute an operation with exclusive lock on a resource * @param resource - Unique identifier for the resource (e.g., 'persona:name') * @param operation - Async function to execute while holding the lock * @param options - Lock options including timeout * @returns Result of the operation */ withLock(resource: string, operation: () => Promise, options?: { timeout?: number; }): Promise; /** * Execute operation with timeout protection */ private executeWithTimeout; /** * Perform atomic file write operation * Writes to temporary file then renames to ensure atomicity */ atomicWriteFile(filePath: string, content: string, options?: { encoding?: BufferEncoding; }): Promise; /** * Perform atomic file read with lock */ atomicReadFile(filePath: string, options?: { encoding?: BufferEncoding; }): Promise; /** * Generate temporary file path for atomic operations */ private getTempFilePath; /** * Get lock metrics for monitoring */ getMetrics(): { totalRequests: number; activeLocksCount: number; timeouts: number; concurrentWaits: number; avgWaitTimeByResource: { [k: string]: number; }; activeLocks: string[]; }; /** * Clear all locks (use with caution - mainly for testing) */ clearAllLocks(): void; /** * Reset metrics */ resetMetrics(): void; } //# sourceMappingURL=fileLockManager.d.ts.map