Example #1
0
        public Task <BaseCommand> Outgoing(CommandCloseConsumer command)
        {
            command.RequestId = _requestId.FetchNext();
            var request = StandardRequest.WithConsumerId(command.RequestId, command.ConsumerId);

            return(_requests.CreateTask(request));
        }
Example #2
0
 public static BaseCommand ToBaseCommand(this CommandCloseConsumer value)
 {
     return(new BaseCommand
     {
         type = BaseCommand.Type.CloseConsumer,
         CloseConsumer = value
     });
 }
Example #3
0
 public static BaseCommand AsBaseCommand(this CommandCloseConsumer command)
 {
     return(new BaseCommand
     {
         CommandType = BaseCommand.Type.CloseConsumer,
         CloseConsumer = command
     });
 }
Example #4
0
        public static ReadOnlySequence <byte> NewCloseConsumer(long consumerId, long requestId)
        {
            var closeConsumer = new CommandCloseConsumer
            {
                ConsumerId = (ulong)consumerId, RequestId = (ulong)requestId
            };

            return(Serializer.Serialize(closeConsumer.ToBaseCommand()));
        }
Example #5
0
        public void Incoming(CommandCloseConsumer command)
        {
            var channel = _consumerChannels.Remove(command.ConsumerId);

            if (channel != null)
            {
                channel.ClosedByServer();
            }
        }
Example #6
0
        public async Task <BaseCommand> Send(CommandCloseConsumer command)
        {
            var response = await SendRequestResponse(command.AsBaseCommand());

            if (response.CommandType == BaseCommand.Type.Success)
            {
                _consumerManager.Remove(command.ConsumerId);
            }
            return(response);
        }
        public void Outgoing(CommandCloseConsumer command, Task <BaseCommand> response)
        {
            var consumerId = command.ConsumerId;

            _ = response.ContinueWith(result =>
            {
                if (result.Result.CommandType == BaseCommand.Type.Success)
                {
                    _consumerChannels.Remove(consumerId);
                }
            }, TaskContinuationOptions.OnlyOnRanToCompletion);
        }
Example #8
0
        private void Incoming(CommandCloseConsumer command)
        {
            var channel = _consumerChannels[command.ConsumerId];

            if (channel is null)
            {
                return;
            }

            _ = _consumerChannels.Remove(command.ConsumerId);
            _requestResponseHandler.Incoming(command);
            channel.ClosedByServer();
        }
Example #9
0
 public async ValueTask ClosedByClient(CancellationToken cancellationToken)
 {
     try
     {
         var closeConsumer = new CommandCloseConsumer {
             ConsumerId = _id
         };
         await _connection.Send(closeConsumer, cancellationToken).ConfigureAwait(false);
     }
     catch
     {
         // Ignore
     }
 }
Example #10
0
        public async Task <BaseCommand> Send(CommandCloseConsumer 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));
        }
Example #11
0
        public async Task <BaseCommand> Send(CommandCloseConsumer 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);
        }
Example #12
0
        public async ValueTask DisposeAsync()
        {
            try
            {
                _queue.Dispose();
                await _lock.DisposeAsync();

                var closeConsumer = new CommandCloseConsumer {
                    ConsumerId = _id
                };
                await _connection.Send(closeConsumer, CancellationToken.None).ConfigureAwait(false);
            }
            catch
            {
                // Ignore
            }
        }
Example #13
0
        public void Incoming(CommandCloseConsumer command)
        {
            var requests = _requests.Keys;

            foreach (var request in requests)
            {
                if (request.SenderIsConsumer(command.ConsumerId))
                {
                    if (request.IsCommandType(BaseCommand.Type.Seek))
                    {
                        _requests.SetResult(request, new BaseCommand {
                            CommandType = BaseCommand.Type.Success
                        });
                    }
                    else
                    {
                        _requests.Cancel(request);
                    }
                }
            }
        }
Example #14
0
        public Task <BaseCommand> Outgoing(CommandCloseConsumer command)
        {
            var consumerId = command.ConsumerId;

            Task <BaseCommand> response;

            using (TakeConsumerSenderLock(consumerId))
            {
                response = _requestResponseHandler.Outgoing(command);
            }

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

            return(response);
        }
Example #15
0
 public Builder()
 {
     _close = new CommandCloseConsumer();
 }
 public void Incoming(CommandCloseConsumer command)
 => _consumerChannels.Remove(command.ConsumerId)?.ClosedByServer();