Exemple #1
0
 protected virtual void OnChannelDetachedAsync(
     Channel <Message> channel, ref Collector <ValueTask> taskCollector)
 {
     if (!ChannelProcessors.TryGetValue(channel, out var channelProcessor))
     {
         return;
     }
     taskCollector.Add(channelProcessor.DisposeAsync());
 }
Exemple #2
0
 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));
 }
Exemple #3
0
 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));
 }
Exemple #4
0
        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));
        }