macula_gateway_clients (macula v0.20.5)
View SourceClients Worker GenServer - tracks connected clients.
Responsibilities: - Track connected clients with metadata (BOUNDED POOL) - Enforce max_clients limit with backpressure - Monitor client processes for automatic cleanup - Store bidirectional streams for client communication - Provide client query APIs
Pattern: Bounded client pool with backpressure - Tracks clients with max_clients limit (default: 10,000) - Rejects new clients when pool is full (backpressure) - Allows updates to existing clients even when pool is full
Configuration: - max_clients: Maximum concurrent clients (default: 10,000)
Extracted from macula_gateway.erl (Phase 2) Renamed from macula_gateway_client_manager (Phase 2 QUIC refactoring)
Summary
Functions
Broadcast a message to all connected clients.
Register a connected client with metadata. Monitors the client process for automatic cleanup on death.
Unregister a disconnected client.
Get all connected clients.
Get all node IDs with stored client streams (for debugging).
Get information about a specific client.
Get the stored stream for a client node.
Get the stream PID for a given endpoint URL. Used for routing pub/sub messages to remote subscribers.
Handle client process death - automatic cleanup.
Check if a client is alive (process still running).
Remove a stale stream for a node when send fails with 'closed'. This is called by the gateway when quicer:send returns {error, closed} to clean up the invalid stream reference from our maps. Uses async cast to avoid blocking the gateway during send operations.
Start the client manager with options. Registers as 'macula_gateway_clients' for discovery by pubsub module.
Stop the client manager.
Store a bidirectional stream for a client node (legacy 3-arg version).
Store a bidirectional stream for a client node with endpoint tracking.
Types
Functions
Broadcast a message to all connected clients.
-spec client_connected(pid(), pid(), client_info()) -> ok.
Register a connected client with metadata. Monitors the client process for automatic cleanup on death.
Unregister a disconnected client.
-spec get_all_clients(pid()) -> {ok, [{pid(), client_info()}]}.
Get all connected clients.
Get all node IDs with stored client streams (for debugging).
-spec get_client_info(pid(), pid()) -> {ok, client_info()} | not_found.
Get information about a specific client.
Get the stored stream for a client node.
Get the stream PID for a given endpoint URL. Used for routing pub/sub messages to remote subscribers.
Handle client process death - automatic cleanup.
Check if a client is alive (process still running).
Remove a stale stream for a node when send fails with 'closed'. This is called by the gateway when quicer:send returns {error, closed} to clean up the invalid stream reference from our maps. Uses async cast to avoid blocking the gateway during send operations.
Start the client manager with options. Registers as 'macula_gateway_clients' for discovery by pubsub module.
-spec stop(pid()) -> ok.
Stop the client manager.
Store a bidirectional stream for a client node (legacy 3-arg version).
Store a bidirectional stream for a client node with endpoint tracking.