using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; namespace MediaBrowser.Controller.Session; /// /// The shared record of which instance holds which session. Entries expire, so an instance that stops /// refreshing them drops out of every other instance's view instead of lingering. /// public interface ISessionDirectory { /// /// Allocates the next connection epoch for a session. The counter lives in the shared store, so the /// epochs of every instance are ordered by one clock instead of being compared across machines. /// /// The session identifier. /// The cancellation token. /// The allocated epoch, which is greater than every epoch allocated for the session before it. Task AllocateConnectionEpochAsync(string sessionId, CancellationToken cancellationToken = default); /// /// Claims a session for the publishing instance and restarts its expiry. The claim is refused when /// another instance holds the connection, so an instance that merely served a request for the session /// cannot take ownership of it. /// /// The entry. /// The epoch of the publishing instance's connection to the session, or zero when it holds none. /// The cancellation token. /// true if the entry was written. Task PublishAsync(SessionDirectoryEntry entry, long connectionEpoch, CancellationToken cancellationToken = default); /// /// Removes an entry, but only while the calling instance still owns it. /// /// The session identifier. /// The instance requesting the removal. /// The cancellation token. /// A task representing the operation. Task RemoveAsync(string sessionId, string ownerPod, CancellationToken cancellationToken = default); /// /// Gets one entry by session identifier. /// /// The session identifier. /// The cancellation token. /// The entry, or null when the session is in no instance's directory. /// The store could not be read. An unreadable store is not an absent session. Task GetAsync(string sessionId, CancellationToken cancellationToken = default); /// /// Gets every entry that has not expired. /// /// The cancellation token. /// The entries. Task> GetAllAsync(CancellationToken cancellationToken = default); }