Brama.ConnectionManager (Brama v1.0.0)
View SourceManages connection states and implements circuit breaking logic.
This module is responsible for:
- Tracking connection states (closed, open, half-open)
- Implementing circuit breaking logic
- Managing state transitions
- Cleaning up expired connections
Summary
Functions
Checks if a connection is available (circuit is closed or half-open).
Returns a specification to start this module under a supervisor.
Manually closes the circuit for a connection.
Updates the configuration for a specific connection or globally.
Reports a failed connection attempt.
Manually opens the circuit for a connection.
Registers a new connection.
Resets the circuit for a connection (closes it and resets failure count).
Starts the connection manager.
Gets the current status of a connection.
Reports a successful connection attempt.
Unregisters a connection.
Types
@type connection_data() :: %{ identifier: connection_id(), scope: connection_scope(), state: connection_state(), failure_count: non_neg_integer(), max_attempts: pos_integer() | nil, expiry: non_neg_integer() | nil, opened_at: non_neg_integer() | nil, last_success_time: non_neg_integer() | nil, last_failure_time: non_neg_integer() | nil, metadata: map(), expiry_strategy: :fixed | :progressive, initial_expiry: non_neg_integer(), max_expiry: non_neg_integer(), backoff_factor: float() }
@type connection_id() :: String.t()
@type connection_scope() :: String.t() | nil
@type connection_state() :: :closed | :open | :half_open
Functions
Checks if a connection is available (circuit is closed or half-open).
Options
:scope
- Optional scope to match
Returns a specification to start this module under a supervisor.
See Supervisor
.
Manually closes the circuit for a connection.
Options
:scope
- Optional scope to match
Updates the configuration for a specific connection or globally.
Parameters
identifier
- Optional connection identifier. If not provided, updates global settingsopts
- Configuration options to update
Reports a failed connection attempt.
Options
:scope
- Optional scope to match:reason
- Reason for the failure:metadata
- Additional metadata about the failure
Manually opens the circuit for a connection.
Options
:scope
- Optional scope to match:reason
- Reason for opening the circuit:expiry
- Custom expiry time in milliseconds
Registers a new connection.
Options
:scope
- Optional scope for grouping connections:max_attempts
- Maximum number of failures before opening circuit:expiry
- Time in milliseconds after which an open circuit transitions to half-open:metadata
- Additional metadata to store with the connection
Resets the circuit for a connection (closes it and resets failure count).
Options
:scope
- Optional scope to match
@spec start_link(keyword()) :: GenServer.on_start()
Starts the connection manager.
Gets the current status of a connection.
Options
:scope
- Optional scope to match
Reports a successful connection attempt.
Options
:scope
- Optional scope to match:metadata
- Additional metadata about the success
Unregisters a connection.
Options
:scope
- Optional scope to match