Skip to main content

bornera_core/connection/
snapshot.rs

1//! Immutable observation of current connection ownership and capacity.
2
3use calandria::RetainedBytes;
4
5use crate::{
6    AdmissionGate, ConnectionEpoch, ConnectionId, ConnectionMachine, ConnectionPhase, EndpointId,
7    LaneId,
8};
9
10/// Immutable, data-only state for observation outside the owner path.
11#[derive(Clone, Copy, Debug, Eq, PartialEq)]
12#[non_exhaustive]
13pub struct ConnectionSnapshot {
14    /// Logical endpoint.
15    pub endpoint: EndpointId,
16    /// Opaque traffic lane.
17    pub lane: LaneId,
18    /// Physical connection slot.
19    pub connection: ConnectionId,
20    /// Exact physical lifetime.
21    pub epoch: ConnectionEpoch,
22    /// Physical lifecycle phase.
23    pub phase: ConnectionPhase,
24    /// Mechanical admission gate.
25    pub gate: AdmissionGate,
26    /// Mechanical reason retained once this epoch begins closing.
27    pub close_reason: Option<crate::CloseReason>,
28    /// Affine reservations not yet committed or dropped.
29    pub reserved_permits: usize,
30    /// Accepted and reserved operation capacity currently owned.
31    pub owned_operations: usize,
32    /// Accepted operations still capable of producing an effect.
33    pub active_operations: usize,
34    /// FIFO entries retaining a terminal observation tombstone.
35    pub terminal_slots: usize,
36    /// Match keys unavailable in the current epoch.
37    pub active_match_keys: usize,
38    /// Semantic bytes retained by permits and active operations.
39    pub retained_bytes: RetainedBytes,
40    /// Frames retained by reservations or the write owner.
41    pub buffered_write_frames: usize,
42    /// Bytes retained by reservations or the write owner.
43    pub buffered_write_retained_bytes: RetainedBytes,
44}
45
46impl ConnectionMachine {
47    /// Returns an immutable observation snapshot.
48    pub fn snapshot(&self) -> ConnectionSnapshot {
49        let ledger = self.ledger.borrow();
50        ConnectionSnapshot {
51            endpoint: self.endpoint,
52            lane: self.lane,
53            connection: self.connection,
54            epoch: self.epoch,
55            phase: self.phase,
56            gate: self.gate,
57            close_reason: self.close_reason,
58            reserved_permits: ledger.permits(),
59            owned_operations: ledger.operations(),
60            active_operations: self.matching.active_len(),
61            terminal_slots: self.matching.terminal_len(),
62            active_match_keys: ledger.active_keys(),
63            retained_bytes: ledger.retained_bytes(),
64            buffered_write_frames: ledger.write_frames(),
65            buffered_write_retained_bytes: ledger.write_retained_bytes(),
66        }
67    }
68}