Skip to main content

InstanceTracker

Struct InstanceTracker 

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

Thread-safe tracker — instantiated in both the DataWriter and the DataReader.

Implementations§

Source§

impl InstanceTracker

Source

pub fn new() -> Self

New tracker with its own InstanceHandleAllocator.

Source

pub fn with_allocator(allocator: Arc<InstanceHandleAllocator>) -> Self

Tracker with a shared allocator (e.g. when a writer and reader in the same participant draw their handles from the same pool).

Source

pub fn register( &self, keyhash: KeyHash, key_holder: Vec<u8>, timestamp: Option<Time>, ) -> InstanceHandle

Registers the instance if it is not yet known; otherwise just reactivates it (Spec §2.2.2.4.2.5).

Always returns the (stable) InstanceHandle.

Source

pub fn should_deliver_under_time_based_filter( &self, keyhash: &KeyHash, sample_ts: Time, min_separation_nanos: u128, ) -> bool

Spec §2.2.3.12 TIME_BASED_FILTER — decides whether a sample with sample_ts may be delivered to the user API. false if t - last_delivered_ts < min_separation (drop); true otherwise (deliver).

For an unknown instance or the first sample (no last_delivered_ts) it is always true.

Source

pub fn should_deliver_under_destination_order( &self, keyhash: &KeyHash, source_ts: Time, by_source_timestamp: bool, ) -> bool

Spec §2.2.3.18 DESTINATION_ORDER — decides whether a sample with source_ts may be delivered to the user API. BY_RECEPTION_TIMESTAMP: always true. BY_SOURCE_TIMESTAMP: only if source_ts is strictly greater than this instance’s last_delivered_ts (the tie-break on equal timestamps via the writer GUID happens in the typed path).

Source

pub fn record_delivery(&self, keyhash: &KeyHash, sample_ts: Time)

Marks that a sample with sample_ts was delivered to the user API (Spec §2.2.3.12 — for the next filter decision).

Source

pub fn lookup(&self, keyhash: &KeyHash) -> Option<InstanceHandle>

Lookup without mutation (Spec §2.2.2.4.2.14 lookup_instance).

Source

pub fn get_by_handle(&self, handle: InstanceHandle) -> Option<InstanceState>

Returns a copy of the state snapshot for a handle.

Source

pub fn get_by_keyhash(&self, keyhash: &KeyHash) -> Option<InstanceState>

Returns a copy of the state snapshot for a KeyHash.

Source

pub fn get_key_holder(&self, handle: InstanceHandle) -> Option<Vec<u8>>

Returns the key-holder byte stream for a handle (Spec §2.2.2.4.2.13 get_key_value).

Source

pub fn dispose(&self, handle: InstanceHandle, timestamp: Option<Time>) -> bool

Marks the instance as NOT_ALIVE_DISPOSED (Spec §2.2.2.4.2.10 dispose).

Returns false if the instance is not known.

Source

pub fn unregister( &self, handle: InstanceHandle, timestamp: Option<Time>, ) -> bool

Decrements the writer counter; if it drops to 0, the instance transitions to NOT_ALIVE_NO_WRITERS (Spec §2.2.2.4.2.7).

Source

pub fn should_accept_sample_under_exclusive_ownership( &self, keyhash: &KeyHash, writer_guid: [u8; 16], writer_strength: i32, ) -> bool

Spec §2.2.3.10 OWNERSHIP=EXCLUSIVE strength selection. Returns true if a sample from the writer with (writer_guid, writer_strength) should be accepted for the instance keyhash.

Algorithm (Spec §2.2.3.10):

  • No current owner → accept + set as owner.
  • Strength > current → accept + replace owner.
  • Strength == current and guid > current_guid → accept (spec tie-break via the lexicographically higher guid).
  • Strength < current → reject.
  • Strength == current and guid < current → reject.
  • Strength == current and guid == current → accept (same writer).
Source

pub fn clear_owner_for_writer(&self, writer_guid: [u8; 16]) -> usize

Spec §2.2.3.23 — on liveliness loss of a writer: clear the owner for all instances whose owner was this writer. The next sample triggers failover selection.

Source

pub fn clear_owner_for_writer_prefix(&self, prefix: [u8; 12]) -> usize

Like Self::clear_owner_for_writer, but matches on the first 12 bytes of the GUID (GuidPrefix). Allows failover when only the participant identity (e.g. via SPDP lease expiry) is known.

Source

pub fn autopurge( &self, now: Time, autopurge_disposed_delay_nanos: u128, autopurge_nowriter_delay_nanos: u128, ) -> usize

Spec §2.2.3.22 READER_DATA_LIFECYCLE — purges instances whose disposed/no-writer marker is older than the respective delay. now is the caller-side wall-clock; the delays are in nanoseconds. Returns the number of removed instances.

Lazy purge: called from the read path (or a background tick). The spec leaves the strategy open — we delete the affected instance entirely, so that subsequent read/take no longer see it.

Source

pub fn observe_sample( &self, keyhash: KeyHash, key_holder: Vec<u8>, timestamp: Option<Time>, ) -> (InstanceHandle, bool)

Reader-side hook: marks that a sample has arrived for this instance. Returns (handle, was_new), where was_new == true means this instance was previously unknown or the reader view was freshly reset (view_state = NEW).

Source

pub fn mark_view_seen(&self, handle: InstanceHandle)

Reader side: after the first read/take of an instance, its view state is set to NOT_NEW.

Source

pub fn drain_samples(&self, handle: InstanceHandle, n: u32)

Reader side: after take, samples_in_cache is reduced by n.

Source

pub fn ordered_handles(&self) -> Vec<InstanceHandle>

Lists all instance handles in stable order (BTreeMap order by KeyHash). Spec §2.2.2.5.3.28 read_next_instance.

Source

pub fn next_handle_after( &self, previous: InstanceHandle, ) -> Option<InstanceHandle>

Returns the first handle whose sort order lies strictly after previous_handle (or the very first one if previous == HANDLE_NIL). Spec §2.2.2.5.3.28.

Source

pub fn len(&self) -> usize

Number of tracked instances.

Source

pub fn is_empty(&self) -> bool

true if no instances are tracked.

Trait Implementations§

Source§

impl Clone for InstanceTracker

Source§

fn clone(&self) -> Self

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 Debug for InstanceTracker

Source§

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

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

impl Default for InstanceTracker

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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> 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> 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 = 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.