bornera_core/connection/effect.rs
1//! Data-only effects emitted by the deterministic connection machine.
2
3use calandria::Deadline;
4
5use crate::{
6 ConnectionEpoch, Delivery, EffectId, MatchKey, OperationFailure, OperationId, OperationOutcome,
7};
8
9/// Why an epoch must close.
10#[derive(Clone, Copy, Debug, Eq, PartialEq)]
11#[non_exhaustive]
12pub enum CloseReason {
13 /// Accepted work drained after admission closed.
14 Drained,
15 /// The owner explicitly requested closure.
16 Requested,
17 /// A possibly-sent operation reached its deadline.
18 DeadlineAfterPossibleSend,
19 /// The transport reported loss of the connection.
20 TransportLost,
21 /// One exact nonblocking connection attempt failed before establishment.
22 ConnectFailed,
23 /// One exact nonblocking connection attempt exceeded its absolute deadline.
24 ConnectTimedOut,
25 /// A reply arrived when no operation could own it.
26 UnexpectedReply,
27 /// The adapter rejected a complete inbound frame as malformed.
28 MalformedReply,
29 /// A complete inbound frame exceeded its configured retained-byte bound.
30 InboundRetainedCapacity,
31 /// A reply key did not equal the wire-order front.
32 MatchKeyMismatch {
33 /// Match key required by the FIFO front.
34 expected: MatchKey,
35 /// Match key carried by the received reply.
36 received: MatchKey,
37 },
38}
39
40/// A capability action or terminal publication requested by core policy.
41#[derive(Clone, Debug, Eq, PartialEq)]
42#[non_exhaustive]
43pub enum ConnectionEffect<F = ()> {
44 /// Schedule the original absolute deadline.
45 ScheduleDeadline {
46 /// Owning epoch.
47 epoch: ConnectionEpoch,
48 /// Owning operation.
49 operation: OperationId,
50 /// Absolute, never-restarted deadline.
51 deadline: Deadline,
52 },
53 /// Remove a frame that never entered transport write ownership.
54 DiscardWrite {
55 /// Original write effect.
56 effect: EffectId,
57 /// Owning epoch.
58 epoch: ConnectionEpoch,
59 /// Owning operation.
60 operation: OperationId,
61 },
62 /// Remove the deadline owned by an operation.
63 CancelDeadline {
64 /// Owning epoch.
65 epoch: ConnectionEpoch,
66 /// Owning operation.
67 operation: OperationId,
68 },
69 /// Close the physical capability for this exact epoch.
70 CloseEpoch {
71 /// Epoch that must close.
72 epoch: ConnectionEpoch,
73 /// Mechanical closure reason.
74 reason: CloseReason,
75 },
76 /// Publish one terminal operation outcome outside the owner path.
77 PublishOutcome {
78 /// Owning epoch.
79 epoch: ConnectionEpoch,
80 /// Terminal operation.
81 operation: OperationId,
82 /// Mechanical terminal outcome, including an opaque matched reply when present.
83 outcome: OperationOutcome<F>,
84 },
85}
86
87impl<F> ConnectionEffect<F> {
88 pub(crate) fn failed(
89 epoch: ConnectionEpoch,
90 operation: OperationId,
91 failure: OperationFailure,
92 delivery: Delivery,
93 ) -> Self {
94 Self::PublishOutcome {
95 epoch,
96 operation,
97 outcome: OperationOutcome::Failed { failure, delivery },
98 }
99 }
100}