/* ======================================================================== * Copyright (c) 2005-2025 The OPC Foundation, Inc. All rights reserved. * * OPC Foundation MIT License 1.00 * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * The complete license agreement can be found here: * http://opcfoundation.org/License/MIT/1.00/ * ======================================================================*/ using System.Collections.Generic; using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Options; namespace Opc.Ua.Client.Subscriptions { /// /// Subscription manager manages all subscription in a session /// public interface ISubscriptionManager { /// /// Return diagnostics mask to use when sending publish requests. /// DiagnosticsMasks ReturnDiagnostics { get; set; } /// /// Gets and sets the maximum number of publish requests to /// be used in the session. /// int MaxPublishWorkerCount { get; set; } /// /// Gets and sets the minimum number of publish requests to be /// used in the session. /// int MinPublishWorkerCount { get; set; } /// /// Get the number of current publishing workers /// int PublishWorkerCount { get; } /// /// Good publish requests /// int GoodPublishRequestCount { get; } /// /// Bad publish requests /// int BadPublishRequestCount { get; } /// /// Total number of missing notification messages detected across /// all subscriptions managed by this manager (sum of /// ). /// long MissingMessageCount { get; } /// /// Total number of republish requests issued across all /// subscriptions managed by this manager (sum of /// ). /// long RepublishMessageCount { get; } /// /// Number of subscriptions /// int Count { get; } /// /// /// When true, the V2 subscription dispatcher calls /// on notification payload /// instances (such as MonitoredItemNotification) after /// the handler returns, releasing them back to their /// activator-level pools for reuse. /// /// /// When false (default), instances are simply released /// to the GC as before. /// /// /// Setting this property takes effect on the next publish /// dispatch. Handlers that retain notification values past the /// dispatch call must not enable this option, or must copy the /// retained values before returning from the handler. /// /// bool PoolNotifications { get; set; } /// /// Subscriptions /// IEnumerable Items { get; } /// /// Create new subscriptions inside the session. /// The subscription will not be created but will /// be created asynchronously. Disposing the session /// will remove it from the session but not from /// the server. The subscription must also explicitly /// be deleted using DeleteAsync to remove it from /// the server. /// /// /// /// ISubscription Add(ISubscriptionNotificationHandler handler, IOptionsMonitor options); /// /// Snapshot all subscriptions managed by this instance and write /// them to in OPC UA binary encoding. /// The format starts with the session's namespace and server URI /// tables so the snapshot is portable across sessions whose /// tables index the same URIs in different positions. /// /// The destination stream. Must be writable. /// The message context that supplies /// the namespace + server URI tables used by the on-wire encoding. /// Pass session.MessageContext. /// Optional subset of subscriptions to /// snapshot. When null all managed subscriptions are saved. /// Cancellation token. ValueTask SaveAsync( Stream stream, IServiceMessageContext messageContext, IEnumerable? subscriptions = null, CancellationToken ct = default); /// /// Restore subscriptions from a stream previously produced by /// . Each restored subscription is added to the /// manager via the same path used by . /// /// The source stream. Must be readable. /// Message context that supplies the /// active session's namespace + server URI tables. Indexes in the /// saved snapshot are remapped onto these tables. /// Factory invoked once per restored /// subscription to construct the application's /// . The factory /// receives the per-subscription Name from the snapshot. /// When true the /// server-side subscription and monitored item ids are preserved /// so the caller can issue a TransferSubscriptions call to take /// over the existing server-side state. When false the ids /// are cleared so the V2 manager recreates the subscriptions from /// scratch on the new session — matching classic /// . /// Cancellation token. ValueTask> LoadAsync(Stream stream, IServiceMessageContext messageContext, System.Func handlerFactory, bool transferSubscriptions = false, CancellationToken ct = default); } }