Exemplo n.º 1
0
        void OnReceiveSessionFrame(Frame frame)
        {
            AmqpSession  session = null;
            Performative command = frame.Command;
            ushort       channel = frame.Channel;

            if (command.DescriptorCode == Begin.Code)
            {
                Begin begin = (Begin)command;
                if (begin.RemoteChannel.HasValue)
                {
                    // reply to begin
                    lock (this.ThisLock)
                    {
                        if (!this.sessionsByLocalHandle.TryGetObject(begin.RemoteChannel.Value, out session))
                        {
                            throw new AmqpException(AmqpError.NotFound, SRClient.AmqpChannelNotFound(begin.RemoteChannel.Value));
                        }

                        session.RemoteChannel = channel;
                        this.sessionsByRemoteHandle.Add(channel, session);
                    }
                }
                else
                {
                    // new begin request
                    AmqpSessionSettings settings = AmqpSessionSettings.Create(begin);
                    settings.RemoteChannel = channel;
                    session = this.SessionFactory.CreateSession(this, settings);
                    this.AddSession(session, channel);
                }
            }
            else
            {
                if (!this.sessionsByRemoteHandle.TryGetObject((uint)channel, out session))
                {
                    if (frame.Command.DescriptorCode == End.Code ||
                        frame.Command.DescriptorCode == Detach.Code)
                    {
                        return;
                    }

                    throw new AmqpException(AmqpError.NotFound, SRClient.AmqpChannelNotFound((uint)channel));
                }
            }

            session.ProcessFrame(frame);
        }