TsgcWSCircuitBreakerMethods › RegisterConnection

RegisterConnection Method

Server-side hook that tracks a new connection (reserved for future per-IP metrics).

Syntax

procedure RegisterConnection(const aIP: string);

Parameters

NameTypeDescription
aIPconst stringPeer IP address of the newly accepted connection.

Remarks

Reserved hook currently implemented as a no-op when SGC_CIRCUITBREAKER is enabled — future releases will use it to track per-IP connection counts so the breaker can raise OnFailureRecorded / OnCallRejected at the IP granularity. Call it from the server's OnConnect handler after IsConnectionAllowed returns True, and pair every call with UnregisterConnection in OnDisconnect so the tracking stays balanced. Safe to call today — it guarantees forward compatibility with no observable behavior change.

Example

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;

Back to Methods