コード例 #1
0
        public Task <BaseCommand> Outgoing(CommandCloseProducer command)
        {
            command.RequestId = _requestId.FetchNext();
            var request = StandardRequest.WithProducerId(command.RequestId, command.ProducerId);

            return(_requests.CreateTask(request));
        }
コード例 #2
0
 public static BaseCommand ToBaseCommand(this CommandCloseProducer value)
 {
     return(new BaseCommand
     {
         type = BaseCommand.Type.CloseProducer,
         CloseProducer = value
     });
 }
コード例 #3
0
ファイル: CommandExtensions.cs プロジェクト: eaba/dotpulsar
 public static BaseCommand AsBaseCommand(this CommandCloseProducer command)
 {
     return(new BaseCommand
     {
         CommandType = BaseCommand.Type.CloseProducer,
         CloseProducer = command
     });
 }
コード例 #4
0
        public static ReadOnlySequence <byte> NewCloseProducer(long producerId, long requestId)
        {
            var closeProducer = new CommandCloseProducer
            {
                ProducerId = (ulong)producerId, RequestId = (ulong)requestId
            };

            return(Serializer.Serialize(closeProducer.ToBaseCommand()));
        }
コード例 #5
0
ファイル: ChannelManager.cs プロジェクト: Omsaaf/dotpulsar
        public void Incoming(CommandCloseProducer command)
        {
            var inbox = _producerChannels.Remove(command.ProducerId);

            if (inbox != null)
            {
                inbox.ClosedByServer();
            }
        }
コード例 #6
0
ファイル: Connection.cs プロジェクト: eaba/dotpulsar
        public async Task <BaseCommand> Send(CommandCloseProducer command)
        {
            var response = await SendRequestResponse(command.AsBaseCommand());

            if (response.CommandType == BaseCommand.Type.Success)
            {
                _producerManager.Remove(command.ProducerId);
            }
            return(response);
        }
コード例 #7
0
        public void Outgoing(CommandCloseProducer command, Task <BaseCommand> response)
        {
            var producerId = command.ProducerId;

            _ = response.ContinueWith(result =>
            {
                if (result.Result.CommandType == BaseCommand.Type.Success)
                {
                    _producerChannels.Remove(producerId);
                }
            }, TaskContinuationOptions.OnlyOnRanToCompletion);
        }
コード例 #8
0
        public void Incoming(CommandCloseProducer command)
        {
            var requests = _requests.Keys;

            foreach (var request in requests)
            {
                if (request.SenderIsProducer(command.ProducerId))
                {
                    _requests.Cancel(request);
                }
            }
        }
コード例 #9
0
        private void Incoming(CommandCloseProducer command)
        {
            var channel = _producerChannels[command.ProducerId];

            if (channel is null)
            {
                return;
            }

            _ = _producerChannels.Remove(command.ProducerId);
            _requestResponseHandler.Incoming(command);
            channel.ClosedByServer();
        }
コード例 #10
0
 public async ValueTask ClosedByClient(CancellationToken cancellationToken)
 {
     try
     {
         var closeProducer = new CommandCloseProducer {
             ProducerId = _id
         };
         await _connection.Send(closeProducer, cancellationToken).ConfigureAwait(false);
     }
     catch
     {
         // Ignore
     }
 }
コード例 #11
0
 public async ValueTask DisposeAsync()
 {
     try
     {
         var closeProducer = new CommandCloseProducer {
             ProducerId = _id
         };
         await _connection.Send(closeProducer, CancellationToken.None).ConfigureAwait(false);
     }
     catch
     {
         // Ignore
     }
 }
コード例 #12
0
        public async Task <BaseCommand> Send(CommandCloseProducer command, CancellationToken cancellationToken)
        {
            ThrowIfDisposed();

            Task <BaseCommand>?responseTask;

            using (await _lock.Lock(cancellationToken).ConfigureAwait(false))
            {
                responseTask = _channelManager.Outgoing(command);
                var sequence = Serializer.Serialize(command.AsBaseCommand());
                await _stream.Send(sequence).ConfigureAwait(false);
            }

            return(await responseTask.ConfigureAwait(false));
        }
コード例 #13
0
        public async Task <BaseCommand> Send(CommandCloseProducer command)
        {
            Task <BaseCommand>?responseTask = null;

            using (await _lock.Lock())
            {
                var baseCommand = command.AsBaseCommand();
                responseTask = _requestResponseHandler.Outgoing(baseCommand);
                _channelManager.Outgoing(command, responseTask);
                var sequence = Serializer.Serialize(baseCommand);
                await _stream.Send(sequence);
            }

            return(await responseTask);
        }
コード例 #14
0
        public Task <BaseCommand> Outgoing(CommandCloseProducer command)
        {
            var producerId = command.ProducerId;

            Task <BaseCommand> response;

            using (TakeProducerSenderLock(producerId))
            {
                response = _requestResponseHandler.Outgoing(command);
            }

            _ = response.ContinueWith(result =>
            {
                if (result.Result.CommandType == BaseCommand.Type.Success)
                {
                    _ = _producerChannels.Remove(producerId);
                }
            }, TaskContinuationOptions.OnlyOnRanToCompletion);

            return(response);
        }
コード例 #15
0
 public void Incoming(CommandCloseProducer command)
 => _producerChannels.Remove(command.ProducerId)?.ClosedByServer();
コード例 #16
0
 public Builder()
 {
     _producer = new CommandCloseProducer();
 }