using System.Diagnostics.CodeAnalysis; using ZB.MOM.WW.MxGateway.Contracts.Proto; namespace ZB.MOM.WW.MxGateway.Server.Sessions; public interface ISessionManager { /// Opens a new gateway session and launches a worker process. /// Request payload. /// Client identity string. /// API key identifier of the caller creating the session. /// Token to cancel the asynchronous operation. /// The newly opened session. Task OpenSessionAsync( SessionOpenRequest request, string? clientIdentity, string? ownerKeyId, CancellationToken cancellationToken); /// Attempts to retrieve a session by ID. /// Identifier of the session. /// The retrieved session, if found. /// True if the session exists; otherwise false. bool TryGetSession( string sessionId, [MaybeNullWhen(false)] out GatewaySession session); /// Invokes a command on the worker for the specified session. /// Identifier of the session. /// Command to invoke. /// Token to cancel the asynchronous operation. /// The command reply from the worker. Task InvokeAsync( string sessionId, WorkerCommand command, CancellationToken cancellationToken); /// Reads events streamed from the worker for the specified session. /// Identifier of the session. /// Token to cancel the asynchronous operation. /// Events emitted by the worker. IAsyncEnumerable ReadEventsAsync( string sessionId, CancellationToken cancellationToken); /// Closes a session and terminates its worker process. /// Identifier of the session to close. /// Token to cancel the asynchronous operation. /// The result of closing the session. Task CloseSessionAsync( string sessionId, CancellationToken cancellationToken); /// /// Forcefully terminates a session's worker without attempting graceful shutdown, /// transitions the session to Closed, and removes it from the registry. /// /// Identifier of the session whose worker to kill. /// Reason for killing the worker (recorded in logs/audit). /// Token to cancel the asynchronous operation. /// The result of closing the session. Task KillWorkerAsync( string sessionId, string reason, CancellationToken cancellationToken); /// Closes all sessions with expired leases at the specified time. /// The current time to evaluate expiration against. /// Token to cancel the asynchronous operation. /// The number of sessions closed. Task CloseExpiredLeasesAsync( DateTimeOffset now, CancellationToken cancellationToken); /// Shuts down all sessions and the session manager. /// Token to cancel the asynchronous operation. Task ShutdownAsync(CancellationToken cancellationToken); }