public Task <BaseCommand> Outgoing(CommandCloseProducer command) { command.RequestId = _requestId.FetchNext(); var request = StandardRequest.WithProducerId(command.RequestId, command.ProducerId); return(_requests.CreateTask(request)); }
public static BaseCommand ToBaseCommand(this CommandCloseProducer value) { return(new BaseCommand { type = BaseCommand.Type.CloseProducer, CloseProducer = value }); }
public static BaseCommand AsBaseCommand(this CommandCloseProducer command) { return(new BaseCommand { CommandType = BaseCommand.Type.CloseProducer, CloseProducer = command }); }
public static ReadOnlySequence <byte> NewCloseProducer(long producerId, long requestId) { var closeProducer = new CommandCloseProducer { ProducerId = (ulong)producerId, RequestId = (ulong)requestId }; return(Serializer.Serialize(closeProducer.ToBaseCommand())); }
public void Incoming(CommandCloseProducer command) { var inbox = _producerChannels.Remove(command.ProducerId); if (inbox != null) { inbox.ClosedByServer(); } }
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); }
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); }
public void Incoming(CommandCloseProducer command) { var requests = _requests.Keys; foreach (var request in requests) { if (request.SenderIsProducer(command.ProducerId)) { _requests.Cancel(request); } } }
private void Incoming(CommandCloseProducer command) { var channel = _producerChannels[command.ProducerId]; if (channel is null) { return; } _ = _producerChannels.Remove(command.ProducerId); _requestResponseHandler.Incoming(command); channel.ClosedByServer(); }
public async ValueTask ClosedByClient(CancellationToken cancellationToken) { try { var closeProducer = new CommandCloseProducer { ProducerId = _id }; await _connection.Send(closeProducer, cancellationToken).ConfigureAwait(false); } catch { // Ignore } }
public async ValueTask DisposeAsync() { try { var closeProducer = new CommandCloseProducer { ProducerId = _id }; await _connection.Send(closeProducer, CancellationToken.None).ConfigureAwait(false); } catch { // Ignore } }
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)); }
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); }
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); }
public void Incoming(CommandCloseProducer command) => _producerChannels.Remove(command.ProducerId)?.ClosedByServer();
public Builder() { _producer = new CommandCloseProducer(); }