private void Incoming(CommandCloseConsumer command) { var channel = _consumerChannels[command.ConsumerId]; if (channel is null) { return; } _ = _consumerChannels.Remove(command.ConsumerId); _requestResponseHandler.Incoming(command); channel.ClosedByServer(); }
private void HandleCommand(uint commandSize, ReadOnlySequence <byte> sequence) { var command = Serializer.Deserialize <BaseCommand>(sequence.Slice(0, commandSize)); switch (command.CommandType) { case BaseCommand.Type.Message: _consumerManager.Incoming(command.Message, sequence.Slice(commandSize)); return; case BaseCommand.Type.CloseConsumer: _consumerManager.Incoming(command.CloseConsumer); return; case BaseCommand.Type.ActiveConsumerChange: _consumerManager.Incoming(command.ActiveConsumerChange); return; case BaseCommand.Type.ReachedEndOfTopic: _consumerManager.Incoming(command.ReachedEndOfTopic); return; case BaseCommand.Type.CloseProducer: _producerManager.Incoming(command.CloseProducer); return; case BaseCommand.Type.Ping: _pingPongHandler.Incoming(command.Ping); return; default: _requestResponseHandler.Incoming(command); return; } }
public async Task ProcessIncommingFrames(CancellationToken cancellationToken) { await Task.Yield(); try { await foreach (var frame in _stream.Frames()) { var commandSize = frame.ReadUInt32(0, true); var command = Serializer.Deserialize <BaseCommand>(frame.Slice(4, commandSize)); switch (command.CommandType) { case BaseCommand.Type.Message: _channelManager.Incoming(command.Message, frame.Slice(commandSize + 4)); break; case BaseCommand.Type.CloseConsumer: _channelManager.Incoming(command.CloseConsumer); break; case BaseCommand.Type.ActiveConsumerChange: _channelManager.Incoming(command.ActiveConsumerChange); break; case BaseCommand.Type.ReachedEndOfTopic: _channelManager.Incoming(command.ReachedEndOfTopic); break; case BaseCommand.Type.CloseProducer: _channelManager.Incoming(command.CloseProducer); break; case BaseCommand.Type.Ping: _pingPongHandler.Incoming(command.Ping, cancellationToken); break; default: _requestResponseHandler.Incoming(command); break; } } } catch { // ignored } }
public ChannelManager() { _requestResponseHandler = new RequestResponseHandler(); _consumerChannels = new IdLookup <IChannel>(); _producerChannels = new IdLookup <IChannel>(); _incoming = new EnumLookup <BaseCommand.Type, Action <BaseCommand> >(cmd => _requestResponseHandler.Incoming(cmd)); _incoming.Set(BaseCommand.Type.CloseConsumer, cmd => Incoming(cmd.CloseConsumer)); _incoming.Set(BaseCommand.Type.CloseProducer, cmd => Incoming(cmd.CloseProducer)); _incoming.Set(BaseCommand.Type.ActiveConsumerChange, cmd => Incoming(cmd.ActiveConsumerChange)); _incoming.Set(BaseCommand.Type.ReachedEndOfTopic, cmd => Incoming(cmd.ReachedEndOfTopic)); }