feat(adminui): in-process browse session registry + TTL reaper + service
This commit is contained in:
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user