Table of Contents

Class CellChannel

Namespace
KernLab.Cell
Assembly
KernLab.Cell.dll

宿主侧通道(C2/C304——握手宿主半程+Invoke 关联域+回调服务分发+遥测消费)。

public sealed class CellChannel : IAsyncDisposable
Inheritance
CellChannel
Implements
Inherited Members

Properties

NotificationDroppedCount

出站通知丢弃计数(队列溢出/通道断/处置后丢弃——计数增长可见="可丢但可观测",零静默纪律)。

public long NotificationDroppedCount { get; }

Property Value

long

Methods

AcceptAsync(ICellTransportConnection, string, CellChannelOptions?, uint, CancellationToken)

宿主握手(§3.2 半程):收 Hello → 发 HelloAck → 收 Ready。返回容器自述。

public static Task<(CellChannel Channel, ReadyFrame Ready)> AcceptAsync(ICellTransportConnection connection, string expectedInstanceLabel, CellChannel.CellChannelOptions? options = null, uint requiredFeatures = 0, CancellationToken cancellationToken = default)

Parameters

connection ICellTransportConnection
expectedInstanceLabel string
options CellChannel.CellChannelOptions
requiredFeatures uint
cancellationToken CancellationToken

Returns

Task<(CellChannel Channel, ReadyFrame Ready)>

CancelAsync(ulong)

取消在途调用(Cancel 帧+本地取消收场)。

public ValueTask CancelAsync(ulong callId)

Parameters

callId ulong

Returns

ValueTask

DisposeAsync()

public ValueTask DisposeAsync()

Returns

ValueTask

InvokeAsync(string, ushort, ReadOnlyMemory<byte>, TimeSpan?, CancellationToken)

发起调用(callId 单调分配;deadline 到期关联域兜底失败 DEADLINE_EXCEEDED)。 容器回执错误码非 0=抛 CellCallException(错误码随行——CallAsync/尾单同口; 回执与 deadline 计时器赛跑双确定性:两侧任一先到,错误码语义一致)。

public Task<ResultFrame> InvokeAsync(string siteKey, ushort codecId, ReadOnlyMemory<byte> payload, TimeSpan? deadline = null, CancellationToken cancellationToken = default)

Parameters

siteKey string
codecId ushort
payload ReadOnlyMemory<byte>
deadline TimeSpan?
cancellationToken CancellationToken

Returns

Task<ResultFrame>

InvokeStreamAsync(string, ushort, PipeReader, TimeSpan?, CancellationToken)

流式调用(ChunkBegin/ChunkData/ChunkEnd——大体载荷):请求体边读边发(ChunkPayloadLength 分块,背压直通上游),响应体经 Body 流式读。deadline 跨全程(关联域同一兜底); 容器未声明 ChunkedTransfer 时结构化拒绝(握手已协商能力位,错位 fail-fast)。

通道串行语义不变:Body 消费慢=整通道背压(有界管道直通);缺省 deadline 30s——大体载荷显式传。

public Task<ChunkedInvocation> InvokeStreamAsync(string siteKey, ushort codecId, PipeReader requestBody, TimeSpan? deadline = null, CancellationToken cancellationToken = default)

Parameters

siteKey string
codecId ushort
requestBody PipeReader
deadline TimeSpan?
cancellationToken CancellationToken

Returns

Task<ChunkedInvocation>

NotifyAsync(string, ReadOnlyMemory<byte>, CancellationToken)

发通知(免应答推送 H→C):即时返回——出站队列满丢最旧+计数,永不阻塞调用方; 容器 handler 慢不挂宿主(通知在容器入站队列就丢)。 容器未声明 NotifyCapability=结构化拒绝(BusySpin/Chunked 先例第三例); key 空白或 UTF-8 超 256B、payload 超 MaxFrameLength=参数错误即抛(发送侧结构拒绝)。 通道断开/处置后调用=静默丢弃+计数(残余队列已封存——可丢语义,不伪造可达)。

public Task NotifyAsync(string key, ReadOnlyMemory<byte> payload, CancellationToken cancellationToken = default)

Parameters

key string
payload ReadOnlyMemory<byte>
cancellationToken CancellationToken

Returns

Task

RegisterCallbackService(string, Func<ReadOnlyMemory<byte>, CancellationToken, ValueTask<ReadOnlyMemory<byte>>>)

注册宿主回调服务(§6.4——容器经服务键调用的分发表;重复键=装配错误)。

public void RegisterCallbackService(string key, Func<ReadOnlyMemory<byte>, CancellationToken, ValueTask<ReadOnlyMemory<byte>>> handler)

Parameters

key string
handler Func<ReadOnlyMemory<byte>, CancellationToken, ValueTask<ReadOnlyMemory<byte>>>

SendByeAsync(int, CancellationToken)

发 drain 令(Bye——容器停接新调用、在途收尾或窗口到期后退出 ExitCode 0,§5.3)。

public ValueTask SendByeAsync(int drainWindowMilliseconds, CancellationToken cancellationToken = default)

Parameters

drainWindowMilliseconds int
cancellationToken CancellationToken

Returns

ValueTask

Events

ChannelClosed

通道断开(容器消失——fail-fast 事件,§5.2)。

public event Action? ChannelClosed

Event Type

Action

ChannelProtocolError

协议错误事件(§3.4——计数面;断连阈值策略归监督器)。

public event Action<CellProtocolErrorEventArgs>? ChannelProtocolError

Event Type

Action<CellProtocolErrorEventArgs>

ContainerNotification

容器通知到达(双向通知设计稿 §2.1——拷贝脱离池化帧,事件内联于泵循环; handler 应快速转投自有队列,慢 handler=整通道泵背压)。

public event Action<ContainerNotification>? ContainerNotification

Event Type

Action<ContainerNotification>

TelemetryBatch

遥测批次到达(§6.4——真源/聚合在宿主侧使用方)。

public event Action<TelemetryBatchFrame>? TelemetryBatch

Event Type

Action<TelemetryBatchFrame>