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>
impl<C: ConsumerApi + Clone> TableView<C>
Sourcepub fn get(&self, key: &str) -> Option<Bytes>
pub fn get(&self, key: &str) -> Option<Bytes>
Lookup the most recent value for the given key, if any.
Sourcepub fn contains_key(&self, key: &str) -> bool
pub fn contains_key(&self, key: &str) -> bool
true if the key has at least one materialised value.
Sourcepub fn snapshot(&self) -> HashMap<String, Bytes>
pub fn snapshot(&self) -> HashMap<String, Bytes>
Snapshot every currently-known (key, value) pair. Allocates — use Self::for_each
for hot paths.
Sourcepub fn keys(&self) -> Vec<String>
pub fn keys(&self) -> Vec<String>
Snapshot every currently-known key. Mirrors Java TableView#keySet.
Sourcepub fn values(&self) -> Vec<Bytes>
pub fn values(&self) -> Vec<Bytes>
Snapshot every currently-known value. Mirrors Java TableView#values.
Sourcepub fn contains_value(&self, value: &[u8]) -> bool
pub fn contains_value(&self, value: &[u8]) -> bool
Returns true if any key maps to a value equal to value. Mirrors Java
TableView#containsValue.
Sourcepub fn for_each<F: FnMut(&str, &Bytes)>(&self, f: F)
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.
Sourcepub async fn close(self)
pub async fn close(self)
Tear down the background drain task. The view’s snapshot remains queryable.
Sourcepub fn observed_partitions(&self) -> Option<u32>
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.
Sourcepub fn partition_change_count(&self) -> Option<u64>
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.
Sourcepub fn has_auto_update_partitions(&self) -> bool
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.
Sourcepub fn partitions_changed_notify(&self) -> Option<Arc<Notify>>
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.
Sourcepub async fn refresh_partitions(
&self,
client: &PulsarClient,
) -> Result<Option<u32>, PulsarError>
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.
Sourcepub fn listen(&self, listener: TableViewListener)
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.
Sourcepub fn listener_count(&self) -> usize
pub fn listener_count(&self) -> usize
Number of listeners currently registered (includes the build-time listener, if any). Mostly useful for tests and instrumentation.
Sourcepub fn stats(&self) -> ConsumerStats
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).
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
true while the broker connection backing the table view is up. Mirrors Java
TableView#isConnected.
Sourcepub async fn last_message_id(&self) -> Result<MessageId, PulsarError>
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::Otheron broker rejection or wire failure (stringified from the runtime’sConsumerApi::Error).