// // Copyright (c) PlaceholderCompany. All rights reserved. // namespace Jellyfin.Server.Implementations.Clustering { using System; using System.Threading; using System.Threading.Tasks; /// /// Interface for managing distributed locks across multiple instances. /// public interface IDistributedLockManager { /// /// Attempts to acquire a distributed lock. /// /// The unique name of the lock. /// The maximum time to wait for the lock. /// The cancellation token. /// A disposable lock handle, or null if lock could not be acquired. Task TryAcquireLockAsync( string lockName, TimeSpan timeout, CancellationToken cancellationToken = default); /// /// Acquires a distributed lock, waiting indefinitely if necessary. /// /// The unique name of the lock. /// The cancellation token. /// A disposable lock handle. Task AcquireLockAsync( string lockName, CancellationToken cancellationToken = default); /// /// Checks if a lock is currently held. /// /// The name of the lock to check. /// The cancellation token. /// True if the lock is held, false otherwise. Task IsLockHeldAsync( string lockName, CancellationToken cancellationToken = default); /// /// Releases all locks held by the current instance. /// /// The cancellation token. /// A task representing the asynchronous operation. Task ReleaseAllLocksAsync(CancellationToken cancellationToken = default); /// /// Cleans up expired locks from the database. /// /// The cancellation token. /// The number of locks cleaned up. Task CleanupExpiredLocksAsync(CancellationToken cancellationToken = default); } /// /// Represents a handle to a distributed lock that can be disposed to release the lock. /// public interface IDistributedLockHandle : IAsyncDisposable { /// /// Gets the name of the lock. /// string LockName { get; } /// /// Gets the instance ID holding the lock. /// Guid InstanceId { get; } /// /// Gets the time when the lock was acquired. /// DateTime AcquiredAt { get; } /// /// Gets the time when the lock will expire. /// DateTime ExpiresAt { get; } /// /// Gets a value indicating whether the lock is still valid. /// bool IsValid { get; } /// /// Renews the lock by extending its expiration time. /// /// The additional time to extend the lock. /// The cancellation token. /// A task representing the asynchronous operation. Task RenewAsync(TimeSpan additionalTime, CancellationToken cancellationToken = default); } }