public Task <BaseCommand> Outgoing(CommandCloseConsumer command) { command.RequestId = _requestId.FetchNext(); var request = StandardRequest.WithConsumerId(command.RequestId, command.ConsumerId); return(_requests.CreateTask(request)); }
public static BaseCommand ToBaseCommand(this CommandCloseConsumer value) { return(new BaseCommand { type = BaseCommand.Type.CloseConsumer, CloseConsumer = value }); }
public static BaseCommand AsBaseCommand(this CommandCloseConsumer command) { return(new BaseCommand { CommandType = BaseCommand.Type.CloseConsumer, CloseConsumer = command }); }
public static ReadOnlySequence <byte> NewCloseConsumer(long consumerId, long requestId) { var closeConsumer = new CommandCloseConsumer { ConsumerId = (ulong)consumerId, RequestId = (ulong)requestId }; return(Serializer.Serialize(closeConsumer.ToBaseCommand())); }
public void Incoming(CommandCloseConsumer command) { var channel = _consumerChannels.Remove(command.ConsumerId); if (channel != null) { channel.ClosedByServer(); } }
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); }
private void Incoming(CommandCloseConsumer command) { var channel = _consumerChannels[command.ConsumerId]; if (channel is null) { return; } _ = _consumerChannels.Remove(command.ConsumerId); _requestResponseHandler.Incoming(command); channel.ClosedByServer(); }
public async ValueTask ClosedByClient(CancellationToken cancellationToken) { try { var closeConsumer = new CommandCloseConsumer { ConsumerId = _id }; await _connection.Send(closeConsumer, cancellationToken).ConfigureAwait(false); } catch { // Ignore } }
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)); }
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); }
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 } }
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); } } } }
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); }
public Builder() { _close = new CommandCloseConsumer(); }
public void Incoming(CommandCloseConsumer command) => _consumerChannels.Remove(command.ConsumerId)?.ClosedByServer();