Class QuotaContextBase
- Namespace
- FoundationaLLM.Common.Services.Quota
- Assembly
- FoundationaLLM.Common.dll
Implements the base class for managing the in-memory state of a quota context.
public abstract class QuotaContextBase
- Inheritance
-
QuotaContextBase
- Derived
- Inherited Members
- Extension Methods
Constructors
QuotaContextBase(string, QuotaDefinition, ILogger)
Implements the base class for managing the in-memory state of a quota context.
protected QuotaContextBase(string quotaServiceIdentifier, QuotaDefinition quota, ILogger logger)
Parameters
quotaServiceIdentifier
stringThe identifier of the QuotaService instance managing this quota context.
quota
QuotaDefinitionThe QuotaDefinition providing the quota configuration.
logger
ILoggerThe logger used for logging.
Fields
_logger
The logger used for logging.
protected readonly ILogger _logger
Field Value
_metricPartitions
The dictionary of QuotaMetricPartition instances that correspond to the partition identifiers.
protected readonly Dictionary<string, QuotaMetricPartition> _metricPartitions
Field Value
Remarks
Each derived class must implement the specific methods to get the quota metric partition that corresponds to the partition identifier.
_quota
The QuotaDefinition providing the quota configuration.
protected readonly QuotaDefinition _quota
Field Value
_quotaServiceIdentifier
The identifier of the QuotaService instance managing this quota context.
protected readonly string _quotaServiceIdentifier
Field Value
_syncRoot
The object used to synchronize access to the quota context.
protected readonly object _syncRoot
Field Value
Properties
Quota
Gets or sets the context.
public QuotaDefinition Quota { get; }
Property Value
Methods
AddLocalMetricUnit(DateTimeOffset, string, string)
Adds a new local unit of the quota metric to the quota context and checks if the quota is exceeded or not.
public QuotaMetricPartitionState AddLocalMetricUnit(DateTimeOffset referenceTime, string userIdentifier, string userPrincipalName)
Parameters
referenceTime
DateTimeOffsetThe time at which the local metric unit was recorded.
userIdentifier
stringThe user identifier associated with the unit of the quota metric.
userPrincipalName
stringThe user principal name associated with the unit of the quota metric.
Returns
- QuotaMetricPartitionState
The result of the quota evaluation.
AddRemoteMetricUnits(List<DateTimeOffset>, string)
Adds remote units of the quota metric to the quota context.
public void AddRemoteMetricUnits(List<DateTimeOffset> referenceTimes, string partitionId)
Parameters
referenceTimes
List<DateTimeOffset>The times at which the remote metric units were recorded.
partitionId
stringThe quota metric partition identifier.
EnsureQuotaMetricPartition(string)
Ensures that the quota metric partition corresponding to the specified partition identifier exists.
protected QuotaMetricPartition EnsureQuotaMetricPartition(string partitionId)
Parameters
partitionId
stringThe quota metric partition identifier.
Returns
GetQuotaMetricPartition(string)
Gets the quota metric partition that corresponds to the specified partition identifier.
protected virtual QuotaMetricPartition GetQuotaMetricPartition(string partitionId)
Parameters
partitionId
stringThe quota metric partition id.
Returns
- QuotaMetricPartition
A QuotaMetricPartition instance.
GetQuotaMetricPartition(string, string)
Gets the quota metric partition that corresponds to the specified user identifier and/or user principal name.
protected abstract QuotaMetricPartition GetQuotaMetricPartition(string userIdentifier, string userPrincipalName)
Parameters
userIdentifier
stringThe user identifier used to get the quota metric partition
userPrincipalName
stringThe user principal name used to get the quota metric partition.
Returns
- QuotaMetricPartition
A QuotaMetricPartition instance.