pub struct FileLockManager { /* private fields */ }Expand description
Manages file locks across multiple agents
Implementations§
Source§impl FileLockManager
impl FileLockManager
Sourcepub fn with_timeout(timeout: Duration) -> Self
pub fn with_timeout(timeout: Duration) -> Self
Create a file lock manager with a custom default timeout
Sourcepub fn without_timeout() -> Self
pub fn without_timeout() -> Self
Create a file lock manager with no default timeout
Sourcepub async fn acquire_lock(
self: &Arc<Self>,
agent_id: &str,
path: impl AsRef<Path>,
lock_type: LockType,
) -> Result<LockGuard>
pub async fn acquire_lock( self: &Arc<Self>, agent_id: &str, path: impl AsRef<Path>, lock_type: LockType, ) -> Result<LockGuard>
Acquire a lock on a file
Returns a LockGuard that automatically releases the lock when dropped.
Sourcepub async fn acquire_lock_with_timeout(
self: &Arc<Self>,
agent_id: &str,
path: impl AsRef<Path>,
lock_type: LockType,
timeout: Option<Duration>,
) -> Result<LockGuard>
pub async fn acquire_lock_with_timeout( self: &Arc<Self>, agent_id: &str, path: impl AsRef<Path>, lock_type: LockType, timeout: Option<Duration>, ) -> Result<LockGuard>
Acquire a lock with a specific timeout
Sourcepub async fn acquire_with_wait(
self: &Arc<Self>,
agent_id: &str,
path: impl AsRef<Path>,
lock_type: LockType,
wait_timeout: Duration,
) -> Result<LockGuard>
pub async fn acquire_with_wait( self: &Arc<Self>, agent_id: &str, path: impl AsRef<Path>, lock_type: LockType, wait_timeout: Duration, ) -> Result<LockGuard>
Acquire a lock with waiting and timeout
This method will wait up to wait_timeout for the lock to become available.
It includes deadlock detection to prevent circular wait scenarios.
Sourcepub async fn clear_waiting(&self, agent_id: &str)
pub async fn clear_waiting(&self, agent_id: &str)
Clear all waiting entries for an agent (e.g., when agent exits)
Sourcepub async fn get_waiting_agents(&self) -> HashMap<String, Vec<PathBuf>>
pub async fn get_waiting_agents(&self) -> HashMap<String, Vec<PathBuf>>
Get all agents currently waiting for locks
Sourcepub async fn release_lock(
&self,
agent_id: &str,
path: impl AsRef<Path>,
lock_type: LockType,
) -> Result<()>
pub async fn release_lock( &self, agent_id: &str, path: impl AsRef<Path>, lock_type: LockType, ) -> Result<()>
Release a specific lock
Sourcepub async fn release_all_locks(&self, agent_id: &str) -> usize
pub async fn release_all_locks(&self, agent_id: &str) -> usize
Release all locks held by an agent
Sourcepub async fn check_lock(&self, path: impl AsRef<Path>) -> Option<LockInfo>
pub async fn check_lock(&self, path: impl AsRef<Path>) -> Option<LockInfo>
Check if a file is locked
Sourcepub async fn is_locked_by(&self, path: impl AsRef<Path>, agent_id: &str) -> bool
pub async fn is_locked_by(&self, path: impl AsRef<Path>, agent_id: &str) -> bool
Check if a file is locked by a specific agent
Sourcepub async fn can_acquire(
&self,
path: impl AsRef<Path>,
agent_id: &str,
lock_type: LockType,
) -> bool
pub async fn can_acquire( &self, path: impl AsRef<Path>, agent_id: &str, lock_type: LockType, ) -> bool
Check if a file can be locked with a specific type by an agent
Sourcepub async fn force_release(&self, path: impl AsRef<Path>) -> Result<()>
pub async fn force_release(&self, path: impl AsRef<Path>) -> Result<()>
Force release a lock (admin operation)
Sourcepub async fn list_locks(&self) -> Vec<(PathBuf, LockInfo)>
pub async fn list_locks(&self) -> Vec<(PathBuf, LockInfo)>
Get all currently held locks
Sourcepub async fn locks_for_agent(&self, agent_id: &str) -> Vec<(PathBuf, LockInfo)>
pub async fn locks_for_agent(&self, agent_id: &str) -> Vec<(PathBuf, LockInfo)>
Get locks held by a specific agent
Sourcepub async fn cleanup_expired(&self) -> usize
pub async fn cleanup_expired(&self) -> usize
Clean up expired locks