TsgcWSCircuitBreaker › Methods › LoadStateFromFile
Restores circuit states and counters from a file previously written by SaveStateToFile.
procedure LoadStateFromFile(const aFileName: string);
| Name | Type | Description |
|---|---|---|
aFileName | const string | Path of a file previously produced by SaveStateToFile. The method silently returns if the file does not exist — first-start scenarios are therefore safe. |
Reconstitutes every key's state, rolling-window counters and last state-change timestamp from a snapshot written by SaveStateToFile. Call once at startup before traffic starts flowing so the breaker resumes from its last-known state instead of starting cold — preventing a just-restarted process from immediately hammering an upstream that was known to be Open. When the file is missing the method is a no-op (first-start safety). Only runtime state is restored; configuration must be set programmatically or come from the design-time property values.
// Restore circuit state at startup so a restart does not forget Open circuits
procedure TForm1.FormCreate(Sender: TObject);
begin
sgcWSCircuitBreaker1.LoadStateFromFile('circuit.dat');
sgcAI_OpenAI1.CircuitBreaker := sgcWSCircuitBreaker1;
end;