← 返回 stripe 的题目列表Connection Management for Load Balancer
类型:online_judge
Implement a simplified connection management system responsible for managing the state of multiple backend target server connections. The system should handle the following operations:
CONNECT(connId): Assign a target server to a new connection, selecting in a round-robin fashion amongst available servers.
CONNECT(connId) (duplicate): If connId already exists, do not reassign, output the original target.
DISCONNECT(connId): Close the connection, release the slot on the server, and invalidate the connId.
Set a limit on the number of connections per target, maxConnectionsPerTarget; if full, continue to the next target. If all targets are full, ignore the connection.
SHUTDOWN(targetIndex): Shut down the target server, evict all connections, and make the target unavailable.
The input consists of different types of requests, and the output should reflect the result of management operations and status changes. Provide a code implementation and matching test cases.
Example
Input
3 2
CONNECT a
CONNECT b
CONNECT a
CONNECT c
CONNECT d
DISCONNECT a
CONNECT d
SHUTDOWN 1
CONNECT e