0ffd4bdbea
Comment/XML-doc changes only, no code logic: - strip project-tracking references (WP*, P*-*, row-NN, #NN, Task N) from comments, keeping the explanatory rationale - add missing summaries, <param>, <returns>, <typeparam> and <inheritdoc/> - replace misused <inheritdoc/> with real docs; where <inheritdoc/> was combined with useful remarks, move the rationale into // comments - drop stale replicationActor <param> on DeploymentManagerActor ctor Remaining 5 are false positives (CWE-1236 x2, failures-1, year-0001, M365). Build 0 errors / 0 warnings.
41 lines
1.7 KiB
C#
41 lines
1.7 KiB
C#
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Kpi;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.KpiHistory;
|
|
|
|
/// <summary>
|
|
/// Root-provider-owned admission for source collections. Actor replacement must not
|
|
/// start another call while an earlier cancellation-ignoring collection still owns its scope.
|
|
/// Registration indices are stable because the root provider's service collection is immutable.
|
|
/// </summary>
|
|
internal sealed class KpiSourceAdmission
|
|
{
|
|
private readonly object _gate = new();
|
|
private readonly Dictionary<int, Task<IReadOnlyList<KpiSample>>> _tasks = new();
|
|
|
|
/// <summary>
|
|
/// Starts a collection for the given registration unless an earlier one is still running, in which case the running one is returned.
|
|
/// </summary>
|
|
/// <param name="registrationIndex">Stable index of the source registration.</param>
|
|
/// <param name="collect">Delegate that performs the collection when a new one is started.</param>
|
|
/// <param name="collection">The new collection task, or the still-running earlier one.</param>
|
|
/// <returns><see langword="true"/> if a new collection was started; <see langword="false"/> if an earlier one is still running.</returns>
|
|
internal bool TryStart(
|
|
int registrationIndex,
|
|
Func<Task<IReadOnlyList<KpiSample>>> collect,
|
|
out Task<IReadOnlyList<KpiSample>> collection)
|
|
{
|
|
lock (_gate)
|
|
{
|
|
if (_tasks.TryGetValue(registrationIndex, out var existing) && !existing.IsCompleted)
|
|
{
|
|
collection = existing;
|
|
return false;
|
|
}
|
|
|
|
collection = Task.Run(collect);
|
|
_tasks[registrationIndex] = collection;
|
|
return true;
|
|
}
|
|
}
|
|
}
|