Skip to main content

CemSession

Struct CemSession 

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

A Customer Energy Manager’s side of one S2 session.

The mirror of RmSession, over the same core: the same state table, the same acknowledgement ledger, the same registry. Wiring one of each together through crate::testing::Conversation is how the documented conversations are tested.

Implementations§

Source§

impl CemSession

Source

pub fn new(config: CemConfig) -> Self

A manager’s side of a session, not yet opened.

Source

pub fn set_inbound_policy(&mut self, policy: Box<dyn InboundPolicy + Send>)

Install a hook consulted before every inbound message is acknowledged.

Source

pub fn state(&self) -> &SessionState

Where the session has got to.

Source

pub fn profile(&self) -> WireProfile

The wire profile in use.

Source

pub fn negotiated_version(&self) -> Option<&ProtocolVersion>

The version string the handshake settled on, exactly as it crossed the wire — or the pre-negotiated one under S2 Connect. None until then.

profile is what the codec reads with; this is what an operator greps for, and the evidence R2’s trigger is evaluated on: which string a peer actually selects.

Source

pub fn stats(&self) -> Stats

What this session has done, for an operator’s metrics rather than for the application: how many messages crossed, how many were refused, and how long the peer takes to answer.

Source

pub fn registry(&self) -> &Registry

Everything this session has learned about the resource.

Source

pub fn details(&self) -> Option<&ResourceManagerDetails>

The resource’s details, once it has sent them.

Source

pub fn open(&mut self, now: Timestamp)

Begin.

With a handshake, this queues one — the Resource Manager also sends one, and neither order is wrong. With a version already agreed, it does nothing but wait for the resource’s details.

Source

pub fn poll_transmit(&mut self) -> Option<Outgoing>

The next message to put on the wire.

Source

pub fn poll_event(&mut self) -> Option<CemEvent>

The next thing the application needs to know.

Source

pub fn poll_timeout(&self) -> Option<Timestamp>

When handle_timeout next has something to do.

Source

pub fn handle_text(&mut self, text: &str, now: Timestamp) -> Inbound

Feed in one text frame. Never fails.

A frame that arrives after the session is over is ignored rather than answered: the transport is gone, so an acknowledgement queued for it is one nobody will ever read — and a closed session that keeps filling its outbox is a closed session that keeps growing. handle_message makes the same check; this one is for the frames that never get that far.

Source

pub fn handle_message(&mut self, message: Message, now: Timestamp) -> Inbound

Feed in one already-decoded message.

Source

pub fn handle_timeout(&mut self, now: Timestamp)

Let time pass.

Source

pub fn transport_closed(&mut self, now: Timestamp)

The transport went away.

Source

pub fn select_control_type( &mut self, control_type: ControlType, now: Timestamp, ) -> Result<MessageHandle, SendError>

Activate a control type.

The session does not become active until the resource acknowledges it, which is when CemEvent::Ready arrives.

Source

pub fn instruct( &mut self, instruction: impl Into<Message>, now: Timestamp, ) -> Result<MessageHandle, SendError>

Send an instruction.

Source

pub fn revoke( &mut self, object_type: RevokableObjects, object_id: Id, now: Timestamp, ) -> Result<MessageHandle, SendError>

Withdraw something published earlier.

Source

pub fn request_session( &mut self, request: SessionRequestType, diagnostic: Option<String>, now: Timestamp, ) -> Result<MessageHandle, SendError>

Ask the peer to end or restart the session.

Source

pub fn send( &mut self, message: impl Into<Message>, now: Timestamp, ) -> Result<MessageHandle, SendError>

Send a message.

Source

pub fn close(&mut self)

End the session locally.

Trait Implementations§

Source§

impl Debug for CemSession

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Session for CemSession

Source§

type Event = CemEvent

What this side tells its application about.
Source§

fn open(&mut self, now: Timestamp)

Begin. Has no effect on a session that is already open.
Source§

fn handle_text(&mut self, text: &str, now: Timestamp) -> Inbound

Feed in one frame as it arrived from the transport.
Source§

fn handle_message(&mut self, message: Message, now: Timestamp) -> Inbound

Feed in one already-decoded message.
Source§

fn handle_timeout(&mut self, now: Timestamp)

Tell the session the time has reached Self::poll_timeout.
Source§

fn transport_closed(&mut self, now: Timestamp)

Tell the session its transport has gone.
Source§

fn poll_transmit(&mut self) -> Option<Outgoing>

Take the next frame to send, if any.
Source§

fn poll_event(&mut self) -> Option<CemEvent>

Take the next event for the application, if any.
Source§

fn poll_timeout(&self) -> Option<Timestamp>

When the session next needs to be woken, if ever.
Source§

fn state(&self) -> &SessionState

Where the session has got to.
Source§

fn negotiated_version(&self) -> Option<&ProtocolVersion>

The version string the handshake settled on, once it has.
Source§

fn registry(&self) -> &Registry

Everything the session has learned about its peer.
Source§

fn stats(&self) -> Stats

What this session has done, for an operator’s metrics.
Source§

fn close(&mut self)

Queue a close.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more