// Copyright (c) 2025 GeWuYou
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using GFramework.Core.Abstractions.Utility;
namespace GFramework.Core.Abstractions.Concurrency;
///
/// 异步键锁管理器接口,提供基于键的细粒度锁机制
///
public interface IAsyncKeyLockManager : IUtility, IDisposable
{
///
/// 异步获取指定键的锁(推荐使用)
///
/// 锁键
/// 取消令牌
/// 锁句柄,使用 await using 自动释放
ValueTask AcquireLockAsync(string key, CancellationToken cancellationToken = default);
///
/// 同步获取指定键的锁(兼容性方法)
///
/// 锁键
/// 锁句柄,使用 using 自动释放
IAsyncLockHandle AcquireLock(string key);
///
/// 获取锁管理器的统计信息
///
/// 统计信息快照
LockStatistics GetStatistics();
///
/// 获取当前活跃的锁信息(用于调试)
///
/// 键到锁信息的只读字典
IReadOnlyDictionary GetActiveLocks();
}