pub struct SharedStateManager { /* private fields */ }Expand description
Shared State Manager for inter-agent state sharing
Implementations§
Sourcepub fn get_typed<T: for<'de> Deserialize<'de>>(&self, key: &str) -> Option<T>
pub fn get_typed<T: for<'de> Deserialize<'de>>(&self, key: &str) -> Option<T>
Get a typed value by key
Sourcepub fn set_typed<T: Serialize>(
&mut self,
key: impl Into<String>,
value: &T,
) -> SharedStateResult<()>
pub fn set_typed<T: Serialize>( &mut self, key: impl Into<String>, value: &T, ) -> SharedStateResult<()>
Set a typed value by key
Sourcepub fn watch<F>(&mut self, key: impl Into<String>, callback: F) -> WatchHandle
pub fn watch<F>(&mut self, key: impl Into<String>, callback: F) -> WatchHandle
Watch for changes to a key
Sourcepub fn unwatch(&mut self, handle: &WatchHandle) -> bool
pub fn unwatch(&mut self, handle: &WatchHandle) -> bool
Unwatch a key
Sourcepub fn lock(
&mut self,
key: impl Into<String>,
holder: impl Into<String>,
timeout: Option<Duration>,
) -> SharedStateResult<Lock>
pub fn lock( &mut self, key: impl Into<String>, holder: impl Into<String>, timeout: Option<Duration>, ) -> SharedStateResult<Lock>
Acquire a lock on a key
If the key is already locked, this will wait until the lock is released or the timeout expires.
Sourcepub fn try_lock(
&mut self,
key: impl Into<String>,
holder: impl Into<String>,
timeout: Option<Duration>,
) -> Option<Lock>
pub fn try_lock( &mut self, key: impl Into<String>, holder: impl Into<String>, timeout: Option<Duration>, ) -> Option<Lock>
Try to acquire a lock without waiting
Sourcepub fn prepare_lock(
&mut self,
key: impl Into<String>,
holder: impl Into<String>,
timeout: Option<Duration>,
) -> Result<(String, Receiver<Lock>), Lock>
pub fn prepare_lock( &mut self, key: impl Into<String>, holder: impl Into<String>, timeout: Option<Duration>, ) -> Result<(String, Receiver<Lock>), Lock>
Prepare an async lock request
Returns a receiver that will receive the lock when it becomes available. The caller should await on the receiver with a timeout.
Sourcepub fn unlock(&mut self, lock: &Lock) -> SharedStateResult<()>
pub fn unlock(&mut self, lock: &Lock) -> SharedStateResult<()>
Release a lock
Sourcepub fn get_all_locks(&self) -> Vec<Lock>
pub fn get_all_locks(&self) -> Vec<Lock>
Get all active locks
Sourcepub fn compare_and_swap(
&mut self,
key: &str,
expected: &Value,
new_value: Value,
) -> bool
pub fn compare_and_swap( &mut self, key: &str, expected: &Value, new_value: Value, ) -> bool
Atomic compare-and-swap operation
Sets the value only if the current value equals the expected value. Returns true if the swap was successful.
Sourcepub fn compare_and_swap_typed<T: Serialize + PartialEq + for<'de> Deserialize<'de>>(
&mut self,
key: &str,
expected: &T,
new_value: &T,
) -> SharedStateResult<bool>
pub fn compare_and_swap_typed<T: Serialize + PartialEq + for<'de> Deserialize<'de>>( &mut self, key: &str, expected: &T, new_value: &T, ) -> SharedStateResult<bool>
Atomic compare-and-swap with typed values
Sourcepub fn increment(&mut self, key: &str, delta: i64) -> i64
pub fn increment(&mut self, key: &str, delta: i64) -> i64
Atomic increment operation
Increments the value by delta. If the key doesn’t exist, initializes to delta. Returns the new value.
Sourcepub fn cleanup_expired_locks(&mut self) -> usize
pub fn cleanup_expired_locks(&mut self) -> usize
Cleanup expired locks
Returns the number of locks cleaned up.
Sourcepub fn get_stats(&self) -> SharedStateStats
pub fn get_stats(&self) -> SharedStateStats
Get statistics about the shared state
Trait Implementations§
Source§fn default() -> SharedStateManager
fn default() -> SharedStateManager
Auto Trait Implementations§
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.