TsgcWSCircuitBreakerMethods › RegisterConnection

RegisterConnection 方法

跟踪新连接的服务器端钩子(保留供未来的每 IP 指标使用)。

语法

procedure RegisterConnection(const aIP: string);

参数

名称类型描述
aIPconst string新接受连接的对端 IP 地址。

备注

当前作为空操作实现的保留钩子,在启用 SGC_CIRCUITBREAKER 时生效,未来版本将使用它来追踪每个 IP 的连接数,以便断路器能够以 IP 粒度触发 OnFailureRecorded / OnCallRejected。请在服务器的 OnConnect 处理程序中于 IsConnectionAllowed 返回 True 后调用它,并在 OnDisconnect 中配对每次调用与 UnregisterConnection,以保持追踪平衡。现在调用是安全的,它保证向前兼容,不会产生可观察到的行为变化。

示例

procedure TForm1.WSServerConnect(Connection: TsgcWSConnection);
begin
  if not sgcWSCircuitBreaker1.IsConnectionAllowed(Connection.PeerIP) then
  begin
    Connection.Disconnect;
    Exit;
  end;
  sgcWSCircuitBreaker1.RegisterConnection(Connection.PeerIP);
end;

procedure TForm1.WSServerDisconnect(Connection: TsgcWSConnection);
begin
  sgcWSCircuitBreaker1.UnregisterConnection(Connection.PeerIP);
end;

返回方法