Struct LockManager

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

Manages concurrent access to workflows through fine-grained locking

The LockManager maintains a mapping of workflow references to mutex guards, allowing for per-workflow exclusive access control. This approach maximizes concurrency by only blocking access to the specific workflow being modified, rather than using a global lock that would block all workflow operations.

§Design Principles

  • Fine-grained locking: Each workflow has its own lock
  • Lazy initialization: Locks are created on first access
  • Shared ownership: Multiple references to the same lock using Arc
  • Automatic cleanup: Locks are managed by the DashMap and cleaned up automatically

§Thread Safety

This struct is completely thread-safe and can be safely accessed from multiple threads. The Default implementation is used to create the global singleton instance.

Implementations§

Source§

impl LockManager

Source

pub fn new() -> Self

Creates a new LockManager instance

Returns a new lock manager with an empty lock table. Locks will be created lazily as workflows are accessed.

§Examples
use aimx::aim::LockManager;

let lock_manager = LockManager::new();
Source

pub fn acquire_workflow_lock(&self, reference: Reference) -> Arc<Mutex<()>>

Acquires an exclusive write lock for a single workflow by reference

This method retrieves or creates a mutex for the specified workflow reference and returns a clone of the Arc<Mutex<()>>. The caller must call lock() on this mutex to actually acquire the exclusive lock.

§Important Notes
  • The lock is not acquired by this method - it only provides access to the mutex
  • Multiple calls with the same reference return the same mutex
  • The lock is released when the MutexGuard is dropped
  • For production use, ensure the reference is canonicalized to prevent lock aliasing
§Parameters
  • reference - The workflow reference to lock
§Returns

An Arc<Mutex<()>> that can be used to acquire the exclusive lock

§Examples
use aimx::aim::LockManager;
use aimx::Reference;
use std::sync::Arc;

let lock_manager = LockManager::new();
let reference = Reference::One("my_workflow".to_string());

// Get the mutex for this workflow
let mutex = lock_manager.acquire_workflow_lock(reference);

// Actually acquire the lock
let _guard = mutex.lock().unwrap();

// Perform exclusive operations...
// Lock is released when `_guard` is dropped

NOTE: I plan to probably add an fs lock mechanism to this at some point in the future.

Trait Implementations§

Source§

impl Debug for LockManager

Source§

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

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

impl Default for LockManager

Source§

fn default() -> LockManager

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,