@pod-protocol/sdk
Version:
TypeScript SDK for PoD Protocol - AI agent communication on Solana
146 lines • 4.05 kB
TypeScript
/**
* Advanced Connection Pooling for PoD Protocol SDK
* Provides intelligent connection management with load balancing and health monitoring
*/
import type { Rpc } from '@solana/rpc';
export interface ConnectionPoolConfig {
/** RPC endpoints to pool */
endpoints: string[];
/** Maximum connections per endpoint */
maxConnectionsPerEndpoint?: number;
/** Connection timeout in milliseconds */
connectionTimeout?: number;
/** Health check interval in milliseconds */
healthCheckInterval?: number;
/** Request timeout in milliseconds */
requestTimeout?: number;
/** Enable load balancing */
enableLoadBalancing?: boolean;
/** Load balancing strategy */
loadBalancingStrategy?: 'round-robin' | 'weighted' | 'least-connections' | 'response-time';
/** Enable automatic failover */
enableFailover?: boolean;
/** Circuit breaker configuration */
circuitBreaker?: {
failureThreshold: number;
recoveryTimeout: number;
monitoringPeriod: number;
};
}
export interface ConnectionMetrics {
endpoint: string;
status: 'healthy' | 'degraded' | 'failed';
activeConnections: number;
totalRequests: number;
successfulRequests: number;
failedRequests: number;
averageResponseTime: number;
lastSuccessfulRequest: number;
lastFailedRequest: number;
circuitBreakerState: 'closed' | 'open' | 'half-open';
}
export interface PoolStats {
totalEndpoints: number;
healthyEndpoints: number;
totalConnections: number;
activeRequests: number;
totalRequests: number;
successRate: number;
averageResponseTime: number;
uptime: number;
}
export declare class AdvancedConnectionPool {
private config;
private connections;
private endpointMetrics;
private circuitBreakers;
private healthCheckInterval?;
private roundRobinIndex;
private startTime;
constructor(config: ConnectionPoolConfig);
/**
* Initialize connection pool for all endpoints
*/
private initializePool;
/**
* Get optimal connection for request
*/
getConnection(): Promise<Rpc<any>>;
/**
* Execute RPC call with intelligent routing and retry
*/
executeRpcCall<T>(method: (rpc: Rpc<any>) => Promise<T>, maxRetries?: number): Promise<T>;
/**
* Select optimal endpoint based on strategy
*/
private selectOptimalEndpoint;
/**
* Round-robin endpoint selection
*/
private selectRoundRobin;
/**
* Select endpoint with least active connections
*/
private selectLeastConnections;
/**
* Select endpoint with fastest average response time
*/
private selectFastestResponseTime;
/**
* Weighted selection based on success rate and performance
*/
private selectWeighted;
/**
* Get healthy endpoints based on circuit breaker state
*/
private getHealthyEndpoints;
/**
* Get or create connection for specific endpoint
*/
private getConnectionForEndpoint;
/**
* Create new connection instance
*/
private createConnection;
/**
* Record successful request
*/
private recordSuccess;
/**
* Record failed request
*/
private recordFailure;
/**
* Start health monitoring
*/
private startHealthMonitoring;
/**
* Perform health checks on all endpoints
*/
private performHealthChecks;
/**
* Update circuit breaker states
*/
private updateCircuitBreakers;
/**
* Get connection pool statistics
*/
getStats(): PoolStats;
/**
* Get detailed metrics for all endpoints
*/
getDetailedMetrics(): ConnectionMetrics[];
/**
* Add new endpoint to pool
*/
addEndpoint(endpoint: string): Promise<void>;
/**
* Remove endpoint from pool
*/
removeEndpoint(endpoint: string): void;
/**
* Clean up pool resources
*/
destroy(): void;
}
//# sourceMappingURL=advanced-connection-pool.d.ts.map