/**
 * Port Pool Manager
 *
 * Manages a pool of ports for trace_processor_shell HTTP servers.
 * Ensures ports are properly allocated and released.
 */
import { EventEmitter } from 'events';
export interface PortAllocation {
    port: number;
    traceId: string;
    allocatedAt: Date;
}
export declare class PortPool extends EventEmitter {
    private readonly minPort;
    private readonly maxPort;
    private availablePorts;
    private blockedPorts;
    private allocations;
    private portToTraceId;
    constructor(minPort?: number, maxPort?: number);
    /**
     * Allocate a port for a trace
     * @param traceId The trace ID requesting a port
     * @returns The allocated port number
     * @throws Error if no ports are available
     */
    allocate(traceId: string): number;
    /**
     * Release a port back to the pool
     * @param traceId The trace ID releasing the port
     * @returns true if port was released, false if trace had no port
     */
    release(traceId: string): boolean;
    /**
     * Release a port by port number (useful when trace ID is unknown)
     * @param port The port number to release
     * @returns true if port was released
     */
    releaseByPort(port: number): boolean;
    /**
     * Mark a port as unusable for the remainder of this process.
     * This is used when trace_processor_shell reports "Address already in use".
     */
    blockPort(port: number): void;
    /**
     * Get the port allocated to a trace
     * @param traceId The trace ID
     * @returns The port number or null if not allocated
     */
    getPort(traceId: string): number | null;
    /**
     * Check if a port is available
     * @param port The port to check
     * @returns true if the port is available
     */
    isAvailable(port: number): boolean;
    /**
     * Get the next available port
     * @returns The next available port or null if none available
     */
    private getNextAvailablePort;
    /**
     * Get pool statistics
     */
    getStats(): {
        total: number;
        available: number;
        allocated: number;
        blocked: number;
        allocations: PortAllocation[];
    };
    /**
     * Release all ports (cleanup)
     */
    releaseAll(): void;
    /**
     * Force cleanup stale allocations (ports allocated more than maxAge ago)
     * @param maxAgeMs Maximum age in milliseconds
     * @returns Number of stale allocations cleaned
     */
    cleanupStale(maxAgeMs?: number): number;
}
export declare function getPortPool(): PortPool;
export declare function resetPortPool(): void;
//# sourceMappingURL=portPool.d.ts.map