Skip to main content

TransactionLayer

Struct TransactionLayer 

Source
pub struct TransactionLayer { /* private fields */ }
Expand description

Holds the transactions in flight and routes messages to them.

Sans-IO like everything beneath it: the driver feeds messages and fired timers in, and performs the outputs.

Implementations§

Source§

impl TransactionLayer

Source

pub fn new(timers: Timers) -> Self

A layer with the given timer constants.

Source

pub fn len(&self) -> (usize, usize)

How many transactions are in flight, as (client, server).

Exposed because a transaction store that leaks is a slow, quiet outage, and a test that asserts on this is the cheapest way to notice.

Source

pub fn is_empty(&self) -> bool

Whether no transactions are in flight.

Source

pub fn send_request( &mut self, request: Request, reliability: Reliability, ) -> Option<(TransactionKey, Vec<Output>)>

Send a request, creating a client transaction for it.

Source

pub fn receive( &mut self, message: Message, reliability: Reliability, ) -> Dispatch

Route an incoming message.

Source

pub fn send_response( &mut self, key: &TransactionKey, response: Response, ) -> Vec<Output>

Send a response from the transaction user.

Source

pub fn abandon(&mut self, key: &TransactionKey) -> bool

Abandon a server transaction the transaction user never answered.

RFC 3261 §17.2 gives a server transaction in Trying no timer, because the model is that the transaction user always responds. A stack exposed to a network needs the case where it does not: an application that forgot a request, or one that is wedged, both look like this, and a transaction held for the life of the process is a leak that grows with traffic.

Deliberately not a timer inside the transaction: that would change what the state machine does, and the machine is right. This is the layer above admitting that its user is fallible, and it is the driver — which owns the clock — that decides when.

Returns whether there was one to abandon.

Source

pub fn on_timer(&mut self, key: &TransactionKey, timer: Timer) -> Vec<Output>

A timer fired for a transaction.

Source

pub fn on_transport_error(&mut self, key: &TransactionKey) -> Vec<Output>

The transport failed for a transaction.

Source

pub fn server_request(&self, key: &TransactionKey) -> Option<&Request>

The request that created a server transaction.

A driver needs this to build a response on the transaction’s behalf — refusing an overloaded endpoint with 503, for instance — without the application having been given the request in the first place.

Source

pub fn client_request(&self, key: &TransactionKey) -> Option<&Request>

The request that created a client transaction.

A transport driver needs this after an asynchronous connection attempt fails so it can account for the exact method whose queued bytes never reached a socket.

Source

pub fn client_state(&self, key: &TransactionKey) -> Option<ClientState>

The state of a client transaction, if it exists.

Source

pub fn server_state(&self, key: &TransactionKey) -> Option<ServerState>

The state of a server transaction, if it exists.

Trait Implementations§

Source§

impl Debug for TransactionLayer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.