feat(adminui): in-process browse session registry + TTL reaper + service

This commit is contained in:
Joseph Doherty
2026-05-28 15:36:19 -04:00
parent 7cd5cde315
commit bec2988309
4 changed files with 217 additions and 0 deletions
@@ -0,0 +1,30 @@
using System.Collections.Concurrent;
using ZB.MOM.WW.OtOpcUa.Commons.Browsing;
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Browsing;
/// <summary>
/// Singleton in-process directory of live <see cref="IBrowseSession"/> instances,
/// keyed by <see cref="IBrowseSession.Token"/>. Concurrency is provided by the
/// underlying <see cref="ConcurrentDictionary{TKey, TValue}"/> alone — there are no
/// additional locks; callers must dispose evicted sessions outside the dictionary.
/// </summary>
public sealed class BrowseSessionRegistry
{
private readonly ConcurrentDictionary<Guid, IBrowseSession> _sessions = new();
/// <summary>Adds (or replaces) a session in the registry keyed by its token.</summary>
public void Register(IBrowseSession session) => _sessions[session.Token] = session;
/// <summary>Looks up a session by token without removing it.</summary>
public bool TryGet(Guid token, out IBrowseSession session) =>
_sessions.TryGetValue(token, out session!);
/// <summary>Atomically removes a session from the registry, returning it for disposal.</summary>
public bool TryRemove(Guid token, out IBrowseSession session) =>
_sessions.TryRemove(token, out session!);
/// <summary>Returns a point-in-time snapshot of all currently registered sessions.</summary>
public IReadOnlyList<(Guid Token, IBrowseSession Session)> Snapshot() =>
_sessions.Select(kv => (kv.Key, kv.Value)).ToList();
}