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)); }
public RequestResponseHandler() { _requestId = new RequestId(); _requests = new Awaiter <IRequest, BaseCommand>(); _getResponseIdentifier = new EnumLookup <BaseCommand.Type, Func <BaseCommand, IRequest> >(cmd => throw new Exception($"CommandType '{cmd.CommandType}' not supported as request/response type")); _getResponseIdentifier.Set(BaseCommand.Type.Connected, cmd => new ConnectRequest()); _getResponseIdentifier.Set(BaseCommand.Type.SendError, cmd => new SendRequest(cmd.SendError.ProducerId, cmd.SendError.SequenceId)); _getResponseIdentifier.Set(BaseCommand.Type.SendReceipt, cmd => new SendRequest(cmd.SendReceipt.ProducerId, cmd.SendReceipt.SequenceId)); _getResponseIdentifier.Set(BaseCommand.Type.ProducerSuccess, cmd => StandardRequest.WithRequestId(cmd.ProducerSuccess.RequestId)); _getResponseIdentifier.Set(BaseCommand.Type.CloseConsumer, cmd => StandardRequest.WithConsumerId(cmd.CloseConsumer.RequestId, cmd.CloseConsumer.ConsumerId)); _getResponseIdentifier.Set(BaseCommand.Type.CloseProducer, cmd => StandardRequest.WithProducerId(cmd.CloseProducer.RequestId, cmd.CloseProducer.ProducerId)); _getResponseIdentifier.Set(BaseCommand.Type.LookupResponse, cmd => StandardRequest.WithRequestId(cmd.LookupTopicResponse.RequestId)); _getResponseIdentifier.Set(BaseCommand.Type.GetLastMessageIdResponse, cmd => StandardRequest.WithRequestId(cmd.GetLastMessageIdResponse.RequestId)); _getResponseIdentifier.Set(BaseCommand.Type.GetOrCreateSchemaResponse, cmd => StandardRequest.WithRequestId(cmd.GetOrCreateSchemaResponse.RequestId)); _getResponseIdentifier.Set(BaseCommand.Type.Success, cmd => StandardRequest.WithRequestId(cmd.Success.RequestId)); _getResponseIdentifier.Set(BaseCommand.Type.Error, cmd => !_requestId.IsPastInitialId() ? new ConnectRequest() : StandardRequest.WithRequestId(cmd.Error.RequestId)); }