pub struct HotContext { /* private fields */ }Expand description
Hot context with lock-free concurrent access
Uses DashMap with sequential IDs for lock-free recent updates storage. Older updates are automatically evicted when capacity is reached.
Implementations§
Source§impl HotContext
impl HotContext
Sourcepub fn new(max_size: usize) -> HotContext
pub fn new(max_size: usize) -> HotContext
Create new hot context with specified capacity
Sourcepub fn push(&self, update: ContextUpdate)
pub fn push(&self, update: ContextUpdate)
Push new update, evicting oldest if at capacity (lock-free)
Uses Release ordering to ensure the insert is visible before the ID increment is visible to readers using Acquire ordering.
Sourcepub fn get_recent(&self, n: usize) -> Vec<ContextUpdate>
pub fn get_recent(&self, n: usize) -> Vec<ContextUpdate>
Get N most recent updates (lock-free)
Note: In a concurrent environment, some entries may have been evicted between loading the ID and fetching. This is expected lock-free behavior. The returned Vec may contain fewer than N elements.
Sourcepub fn get_all(&self) -> Vec<ContextUpdate>
pub fn get_all(&self) -> Vec<ContextUpdate>
Get all updates as Vec in chronological order (lock-free)
Returns updates sorted by insertion order (oldest first). Only iterates over the valid range of IDs to avoid O(n) iteration.
Sourcepub fn remove_by_id(&self, entry_id: &Uuid) -> bool
pub fn remove_by_id(&self, entry_id: &Uuid) -> bool
Remove the first update whose ContextUpdate.id matches entry_id (lock-free).
Returns true if an entry was removed. Used by manage_entity delete_update so
MCP clients can clean up ghost / bad context rows by entry_id.
Sourcepub fn back(&self) -> Option<ContextUpdate>
pub fn back(&self) -> Option<ContextUpdate>
Get most recent update (lock-free)
Returns None if the context is empty or if the most recent entry was evicted by a concurrent push operation.
Sourcepub fn snapshot(&self) -> Vec<ContextUpdate>
pub fn snapshot(&self) -> Vec<ContextUpdate>
Get snapshot of all updates as Vec (lock-free) Returns owned Vec for maximum flexibility (.iter(), .rev(), .par_iter(), etc.)
Sourcepub fn iter(&self) -> Vec<ContextUpdate>
pub fn iter(&self) -> Vec<ContextUpdate>
Iterate over all updates (convenience method, returns Vec)
Sourcepub fn to_deque(&self) -> VecDeque<ContextUpdate>
pub fn to_deque(&self) -> VecDeque<ContextUpdate>
Convert to VecDeque for serialization Only iterates over the valid range of IDs (last max_size entries)
Sourcepub fn from_deque(deque: VecDeque<ContextUpdate>, max_size: usize) -> HotContext
pub fn from_deque(deque: VecDeque<ContextUpdate>, max_size: usize) -> HotContext
Create from VecDeque for deserialization (lock-free)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HotContext
impl !RefUnwindSafe for HotContext
impl Send for HotContext
impl Sync for HotContext
impl Unpin for HotContext
impl UnsafeUnpin for HotContext
impl UnwindSafe for HotContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request