Skip to main content

PersistentSubscriptionBuilder

Struct PersistentSubscriptionBuilder 

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

Builder for configuring and creating a persistent subscription. This provides a fluent interface for setting up a persistent subscription with proper CString handling.

The subscription keeps the Aeron client and archive context given here open until it closes. Building also points the archive context at the subscription’s client, so build with Self::new_with_aeron, which sets one client on both, as below. Without a client, the subscription makes its own and closes it when it closes, after which the context must not be used to connect again.

§Examples

use rusteron_archive::*;

let context = AeronContext::new()?;
let aeron = Aeron::new(&context)?;
aeron.start()?;
let archive_context = AeronArchiveContext::new()?;

let subscription = PersistentSubscriptionBuilder::new_with_aeron(&archive_context, &aeron)?
    .recording_id(0)?
    .live_channel("aeron:ipc")?
    .live_stream_id(1001)?
    .replay_channel("aeron:udp?endpoint=localhost:0")?
    .replay_stream_id(1002)?
    .build()?;
while !subscription.is_live() && !subscription.has_failed() {
    subscription.poll_fn(|message, _header| println!("{} bytes", message.len()), 10)?;
}

subscription.close()?;

Implementations§

Source§

impl PersistentSubscriptionBuilder

Source

pub fn new() -> Result<Self, AeronCError>

Create a new builder with a default context.

Source

pub fn new_with_aeron( archive_context: &AeronArchiveContext, aeron: &Aeron, ) -> Result<Self, AeronCError>

A builder whose subscription and archive_context both use aeron, which it sets on the context too, so neither is left pointing at another client. The built subscription keeps both open until it closes.

§Errors

Returns the Aeron error if the context cannot be created or either setter fails.

Source

pub fn aeron(self, aeron: &Aeron) -> Result<Self, AeronCError>

Set the Aeron client to use.

§Errors

Returns the Aeron error if the context rejects the client.

Source

pub fn archive_context( self, ctx: &AeronArchiveContext, ) -> Result<Self, AeronCError>

Set the archive context to use.

§Errors

Returns the Aeron error if the context rejects the archive context.

Source

pub fn live_channel(self, channel: &str) -> Result<Self, AeronCError>

Set the live channel (accepts &str, handles CString conversion internally).

Source

pub fn live_stream_id(self, id: i32) -> Result<Self, AeronCError>

Set the live stream ID.

Source

pub fn replay_channel(self, channel: &str) -> Result<Self, AeronCError>

Set the replay channel (accepts &str, handles CString conversion internally).

Source

pub fn replay_stream_id(self, id: i32) -> Result<Self, AeronCError>

Set the replay stream ID.

Source

pub fn start_position(self, pos: i64) -> Result<Self, AeronCError>

Set the start position.

Source

pub fn start_from_beginning(self) -> Result<Self, AeronCError>

Replay from the beginning of the recording (Aeron FROM_START).

Source

pub fn start_from_live(self) -> Result<Self, AeronCError>

Skip replay and join the live stream immediately (Aeron FROM_LIVE).

Source

pub fn recording_id(self, id: i64) -> Result<Self, AeronCError>

Set the recording ID.

Source

pub fn listener<L: PersistentSubscriptionListener>( self, listener: L, ) -> Result<Self, AeronCError>

Set the listener for events.

Source

pub fn state_counter(self, counter: &AeronCounter) -> Result<Self, AeronCError>

Pre-allocate the state counter so an external observer can read the PS state-machine state. If unset the PS allocates one itself. Maps to Aeron’s Context.stateCounter. The subscription takes the counter over: it closes it, as does setting the slot again. Keep the counter’s client open until then.

Source

pub fn join_difference_counter( self, counter: &AeronCounter, ) -> Result<Self, AeronCError>

Counter holding the byte gap between replay and live when the live image is added. Maps to Aeron’s Context.joinDifferenceCounter. Taken over as in Self::state_counter.

Source

pub fn live_left_counter( self, counter: &AeronCounter, ) -> Result<Self, AeronCError>

Counter holding the number of times the PS has dropped off the live stream. Maps to Aeron’s Context.liveLeftCounter. Taken over as in Self::state_counter.

Source

pub fn live_joined_counter( self, counter: &AeronCounter, ) -> Result<Self, AeronCError>

Counter holding the number of times the PS has switched to the live stream. Maps to Aeron’s Context.liveJoinedCounter. Taken over as in Self::state_counter.

Source

pub fn build(self) -> Result<AeronArchivePersistentSubscription, AeronCError>

Build the persistent subscription, which keeps its Aeron client and archive context open until it closes.

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, 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.