feat: add immutable partitioned data publication hub
This commit is contained in:
@@ -246,7 +246,8 @@ public interface IOpcUaAddressSpaceSink
|
||||
/// <summary>One value write within a <see cref="IOpcUaAddressSpaceSink.WriteValues"/> batch.
|
||||
/// Same semantics per field as <see cref="IOpcUaAddressSpaceSink.WriteValue"/> (status verbatim).</summary>
|
||||
public readonly record struct ValueWrite(
|
||||
string NodeId, object? Value, uint StatusCode, DateTime SourceTimestampUtc, AddressSpaceRealm Realm);
|
||||
string NodeId, object? Value, uint StatusCode, DateTime SourceTimestampUtc, AddressSpaceRealm Realm,
|
||||
DateTime? OriginalSourceTimestampUtc = null, DateTime? OriginalServerTimestampUtc = null);
|
||||
|
||||
/// <summary>One status-only write within a <see cref="IOpcUaAddressSpaceSink.WriteStatuses"/> batch: the
|
||||
/// node's current VALUE is retained and only <paramref name="StatusCode"/> +
|
||||
|
||||
@@ -19,6 +19,28 @@ public sealed class DataValue : IDisposable
|
||||
{ Kind = kind; _payload = payload; Dimensions = dimensions; }
|
||||
public DataValueKind Kind { get; }
|
||||
public IReadOnlyList<int>? Dimensions { get; }
|
||||
/// <summary>A conservative, allocation-free estimate of retained value storage, in bytes.</summary>
|
||||
public long EstimatedRetainedBytes
|
||||
{
|
||||
get
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
checked
|
||||
{
|
||||
const long baseline = 256;
|
||||
if (_payload is byte[] bytes) return baseline + 32L + bytes.LongLength;
|
||||
if (_payload is string text) return baseline + 32L + 2L * text.Length;
|
||||
if (_payload is ArrayPayload array)
|
||||
{
|
||||
long size = baseline + 128L + 8L * (Dimensions?.Count ?? 0) + 48L * array.Elements.LongLength;
|
||||
if (array.Kind == DataValueKind.String)
|
||||
foreach (var element in array.Elements) size += 2L * ((string)element).Length;
|
||||
return size;
|
||||
}
|
||||
return baseline + 32L;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static DataValue Null() => new(DataValueKind.Null, null);
|
||||
public static DataValue FromBytes(byte[] bytes) => new(DataValueKind.Bytes, (byte[])bytes.Clone());
|
||||
public static DataValue FromScalar(DataValueKind kind, object value)
|
||||
|
||||
@@ -43,3 +43,9 @@ public interface IDataConnectionFactory
|
||||
{
|
||||
IDataConnection Create(DataAuthenticatedContext context, DataTarget target);
|
||||
}
|
||||
|
||||
/// <summary>Final-send guard for metadata and values prepared by a caller-bound connection.</summary>
|
||||
public interface IDataConnectionPublicationGate
|
||||
{
|
||||
bool CanPublish(ServingIdentity expectedServing);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
namespace ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
|
||||
|
||||
/// <summary>A retained response's live publication fence and resource ownership.</summary>
|
||||
public interface IDataPublicationLease : IDisposable
|
||||
{
|
||||
bool IsValid { get; }
|
||||
}
|
||||
|
||||
public sealed record BrowseRequest(DataView Parent, string? Filter, string? Continuation, DataBudget Budget);
|
||||
public sealed record MetadataRequest(IReadOnlyList<DataView> Views, DataBudget Budget);
|
||||
public sealed record ReadItem(string CorrelationId, DataView View, TimeSpan? MaximumAge);
|
||||
public sealed record ReadRequest(IReadOnlyList<ReadItem> Items, DataBudget Budget);
|
||||
/// <summary>Sample is owned by the recipient. Status/age/readiness are distinct from original sample quality.</summary>
|
||||
public sealed record ReadResult(string CorrelationId, DataItemStatus Status, DataReadiness Readiness,
|
||||
TimeSpan? Age, DataSample? Sample, string? Diagnostic) : IDisposable
|
||||
TimeSpan? Age, DataSample? Sample, string? Diagnostic, IDisposable? ResourceLease = null) : IDisposable
|
||||
{
|
||||
public void Dispose() => Sample?.Dispose();
|
||||
public void Dispose()
|
||||
{
|
||||
try { Sample?.Dispose(); }
|
||||
finally { ResourceLease?.Dispose(); }
|
||||
}
|
||||
}
|
||||
public sealed record WriteItem(string CorrelationId, string OperationId, DataView View, DataValue Value,
|
||||
long ExpectedCatalogRevision, string ExpectedServingIncarnation, TimeSpan RemainingBudget);
|
||||
|
||||
@@ -9,9 +9,9 @@ namespace ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
||||
/// <param name="Value">The raw value; null when <see cref="StatusCode"/> indicates Bad.</param>
|
||||
/// <param name="StatusCode">OPC UA status code (numeric value matches the OPC UA spec).</param>
|
||||
/// <param name="SourceTimestampUtc">Driver-side timestamp when the value was sampled at the source. Null if unavailable.</param>
|
||||
/// <param name="ServerTimestampUtc">Driver-side timestamp when the driver received / processed the value.</param>
|
||||
/// <param name="ServerTimestampUtc">Driver-side timestamp when the driver received / processed the value, or null if unavailable.</param>
|
||||
public sealed record DataValueSnapshot(
|
||||
object? Value,
|
||||
uint StatusCode,
|
||||
DateTime? SourceTimestampUtc,
|
||||
DateTime ServerTimestampUtc);
|
||||
DateTime? ServerTimestampUtc);
|
||||
|
||||
@@ -819,7 +819,7 @@ public sealed class OutOfProcessScriptRunner : IScriptRunner, IAsyncDisposable,
|
||||
{
|
||||
StatusCode = snapshot.StatusCode,
|
||||
SourceTsTicks = snapshot.SourceTimestampUtc is { } source ? VariantCodec.ToUtc(source).Ticks : 0,
|
||||
ServerTsTicks = VariantCodec.ToUtc(snapshot.ServerTimestampUtc).Ticks,
|
||||
ServerTsTicks = snapshot.ServerTimestampUtc is { } server ? VariantCodec.ToUtc(server).Ticks : 0,
|
||||
};
|
||||
if (entry.Slots.TryGetValue(path, out var slot)) input.Slot = slot;
|
||||
else input.Path = path;
|
||||
|
||||
@@ -20,6 +20,8 @@ public sealed record DataCallerIdentity(string Principal, string? ApiKeyId, stri
|
||||
/// <summary>Transport-independent data-plane grant and credential policy.</summary>
|
||||
public sealed class DataOperationPolicy
|
||||
{
|
||||
/// <summary>The currently installed local authority generation, rechecked at publication boundaries.</summary>
|
||||
public long AuthorityEpoch => _authority.Current.GenerationId;
|
||||
private readonly IDataPlaneAuthoritySource _authority;
|
||||
private readonly IPermissionEvaluator _evaluator;
|
||||
private readonly TimeProvider _clock;
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace ZB.MOM.WW.OtOpcUa.Core.Authorization;
|
||||
|
||||
/// <summary>Shared placement of equipment-owned values that are not raw-tag references.</summary>
|
||||
public static class DataScopeSubjects
|
||||
{
|
||||
/// <summary>Cannot match an authored name or inherit tag-only browse transit.</summary>
|
||||
public const string OwnedNodeSegment = "\u0000owned";
|
||||
public static NodeScope Owned(NodeScope owner) => owner with
|
||||
{ Segments = Array.AsReadOnly(owner.Segments.Append(OwnedNodeSegment).ToArray()) };
|
||||
}
|
||||
Reference in New Issue
Block a user