protected virtual void OnChannelDetachedAsync( Channel <Message> channel, ref Collector <ValueTask> taskCollector) { if (!ChannelProcessors.TryGetValue(channel, out var channelProcessor)) { return; } taskCollector.Add(channelProcessor.DisposeAsync()); }
public virtual ValueTask UnsubscribeAsync( Channel <BridgeMessage> channel, IPublication publication, CancellationToken cancellationToken = default) { if (!ChannelProcessors.TryGetValue(channel, out var channelProcessor)) { return(ValueTaskEx.CompletedTask); } return(channelProcessor.UnsubscribeAsync(publication, cancellationToken)); }
protected virtual ReplicatorChannelProcessor CreateChannelProcessor(Symbol publisherId) { var channelProcessor = new ReplicatorChannelProcessor(this, publisherId); channelProcessor.Run().ContinueWith(_ => { // Since ChannelProcessor is AsyncProcessorBase desc., // its disposal will shut down RunAsync as well, // so "subscribing" to RunAsync completion is the // same as subscribing to its disposal. ChannelProcessors.TryRemove(publisherId, channelProcessor); }); return(channelProcessor); }
protected virtual ReplicatorChannelProcessor CreateChannelProcessor(Symbol publisherId) { var logger = Services.GetRequiredService <ILoggerFactory>().CreateLogger(nameof(ReplicatorChannelProcessor)); var channelProcessor = new ReplicatorChannelProcessor(this, publisherId, logger); channelProcessor.Run().ContinueWith(_ => { // Since ChannelProcessor is AsyncProcessorBase desc., // its disposal will shut down Run as well, // so "subscribing" to Run completion is the // same as subscribing to its disposal. ChannelProcessors.TryRemove(publisherId, channelProcessor); }); return(channelProcessor); }
protected virtual ValueTask <bool> SubscribeAsync( Channel <Message> channel, IPublication publication, SubscribeMessage subscribeMessage, CancellationToken cancellationToken) { ThrowIfDisposedOrDisposing(); if (!ChannelProcessors.TryGetValue(channel, out var channelProcessor)) { return(ValueTaskEx.FalseTask); } if (publication.Publisher != this || publication.State.IsDisposed) { return(ValueTaskEx.FalseTask); } return(channelProcessor.SubscribeAsync(publication, subscribeMessage, cancellationToken)); }
protected virtual void OnChannelAttached(Channel <Message> channel) { var channelProcessor = CreateChannelProcessor(channel); if (!ChannelProcessors.TryAdd(channel, channelProcessor)) { return; } channelProcessor.RunAsync().ContinueWith(_ => { // Since ChannelProcessor is AsyncProcessorBase desc., // its disposal will shut down RunAsync as well, // so "subscribing" to RunAsync completion is the // same as subscribing to its disposal. ChannelProcessors.TryRemove(channel, channelProcessor); }); }
public virtual ValueTask SubscribeAsync( Channel <BridgeMessage> channel, IPublication publication, bool isUpdateRequested, CancellationToken cancellationToken = default) { ThrowIfDisposedOrDisposing(); if (!ChannelProcessors.TryGetValue(channel, out var channelProcessor)) { throw Errors.UnknownChannel(channel); } if (publication.Publisher != this) { throw Errors.WrongPublisher(this, publication.Publisher.Id); } var message = new SubscribeMessage() { PublisherId = Id, PublicationId = publication.Id, IsUpdateRequested = isUpdateRequested, }; return(channelProcessor.OnReplicaMessageAsync(message, cancellationToken)); }
public IState <bool> GetPublisherConnectionState(Symbol publisherId) => ChannelProcessors .GetOrAddChecked(publisherId, CreateChannelProcessorHandler) .IsConnected;
protected virtual ReplicatorChannelProcessor GetChannelProcessor(Symbol publisherId) => ChannelProcessors .GetOrAddChecked(publisherId, CreateChannelProcessorHandler);