Skip to main content

TableView

Struct TableView 

Source
pub struct TableView<C: ConsumerApi + Clone = Consumer> { /* private fields */ }
Expand description

Compacted-topic key/value view.

Generic over C: ConsumerApi + Clone per ADR-0026 §D1. The default (C = magnetar_runtime_tokio::Consumer) keeps existing callers — magnetar::TableView without a type argument — pointing at the tokio specialisation. Moonpool callers name TableView<magnetar_runtime_moonpool::Consumer<P>> directly. The drain task uses tokio::spawn regardless of engine, which matches ADR-0025’s note that both engines ultimately schedule on tokio (determinism comes from substituting the providers, not from replacing the executor).

Implementations§

Source§

impl<C: ConsumerApi + Clone> TableView<C>

Source

pub fn len(&self) -> usize

Number of distinct keys currently materialised.

Source

pub fn is_empty(&self) -> bool

true if no key has been observed yet.

Source

pub fn get(&self, key: &str) -> Option<Bytes>

Lookup the most recent value for the given key, if any.

Source

pub fn contains_key(&self, key: &str) -> bool

true if the key has at least one materialised value.

Source

pub fn snapshot(&self) -> HashMap<String, Bytes>

Snapshot every currently-known (key, value) pair. Allocates — use Self::for_each for hot paths.

Source

pub fn keys(&self) -> Vec<String>

Snapshot every currently-known key. Mirrors Java TableView#keySet.

Source

pub fn values(&self) -> Vec<Bytes>

Snapshot every currently-known value. Mirrors Java TableView#values.

Source

pub fn contains_value(&self, value: &[u8]) -> bool

Returns true if any key maps to a value equal to value. Mirrors Java TableView#containsValue.

Source

pub fn for_each<F: FnMut(&str, &Bytes)>(&self, f: F)

Iterate every currently-known (key, value) pair under a shared read lock. The callback must not call back into the TableView or it will deadlock.

Source

pub async fn close(self)

Tear down the background drain task. The view’s snapshot remains queryable.

Source

pub fn observed_partitions(&self) -> Option<u32>

Most recent partition count observed by the background partition watcher. None when TableViewBuilder::auto_update_partitions_interval was not set (no watcher spawned). Mirrors the read side of Java’s TableViewBuilder#autoUpdatePartitionsInterval behaviour — Java rebuilds internally; we expose the observation so callers can observe and react.

Source

pub fn partition_change_count(&self) -> Option<u64>

Monotonic count of partition-change events observed by the background watcher. Returns None when no watcher was configured. The counter starts at 0 and is bumped every time a poll detects a different partition count than the previous one. Useful for tests and “did the topology change since X?” probes.

Source

pub fn has_auto_update_partitions(&self) -> bool

Returns true if a background partition-watcher was spawned for this view (i.e. TableViewBuilder::auto_update_partitions_interval was set on the builder). Defaults to false — current Java-parity behaviour when the user did not opt in.

Source

pub fn partitions_changed_notify(&self) -> Option<Arc<Notify>>

Arc<Notify> signalled by the background partition-watcher on every timer tick (i.e. every auto_update_partitions_interval) and on every observed partition-count change driven by Self::refresh_partitions. Returns None when no watcher was configured. Callers may await notified() on the returned handle to react to ticks without polling Self::partition_change_count.

Source

pub async fn refresh_partitions( &self, client: &PulsarClient, ) -> Result<Option<u32>, PulsarError>

Query the broker for the current partition count of the topic this view was opened against, and update Self::observed_partitions / Self::partition_change_count in place if the count differs from the last observation.

This is the user-driven half of the TableViewBuilder::auto_update_partitions_interval machinery: the timer task signals Self::partitions_changed_notify; the user calls this method in response (or independently) to actually refresh the count. Returns the freshly-observed count on success, or Ok(None) if no watcher was configured (no topic recorded). Errors are surfaced via PulsarError.

§Errors

Surfaces PulsarError::Client when the broker metadata lookup fails.

Source

pub fn listen(&self, listener: TableViewListener)

Register an additional listener fired for every subsequent mutation. Mirrors Java TableView#listen. The callback runs inside the drain task — keep it fast and non-blocking. Listeners installed via this method fire after the one optionally configured at build time, in the order they were registered.

Source

pub fn listener_count(&self) -> usize

Number of listeners currently registered (includes the build-time listener, if any). Mostly useful for tests and instrumentation.

Source

pub fn stats(&self) -> ConsumerStats

Cumulative consumer counters for the underlying subscription. Mirrors Java TableView#getStats (the Java table view exposes its consumer’s stats directly).

Source

pub fn is_connected(&self) -> bool

true while the broker connection backing the table view is up. Mirrors Java TableView#isConnected.

Source

pub async fn last_message_id(&self) -> Result<MessageId, PulsarError>

Ask the broker for the underlying topic’s last-published message id. Mirrors Java TableView#getLastMessageId — useful for “is the view caught up?” checks. The table view itself does not track its own cursor; pair this with the timestamps on the messages your listener observed.

§Errors
  • PulsarError::Other on broker rejection or wire failure (stringified from the runtime’s ConsumerApi::Error).

Trait Implementations§

Source§

impl<C: Clone + ConsumerApi + Clone> Clone for TableView<C>

Source§

fn clone(&self) -> TableView<C>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C: ConsumerApi + Clone> Debug for TableView<C>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<C = Consumer> !RefUnwindSafe for TableView<C>

§

impl<C = Consumer> !UnwindSafe for TableView<C>

§

impl<C> Freeze for TableView<C>
where C: Freeze,

§

impl<C> Send for TableView<C>

§

impl<C> Sync for TableView<C>

§

impl<C> Unpin for TableView<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for TableView<C>
where C: UnsafeUnpin,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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, <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.
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